public boolean removeToPreviousKeyword ( Issue issue , IXtextDocument document , String keyword1 , String ... otherKeywords ) throws BadLocationException { // Skip spaces before the element int index = issue . getOffset ( ) - 1 ; char c = document . getChar ( index ) ; while ( Character . isWhitespace ( c ) ) { index -- ; c = document . getChar ( index ) ; } // Skip non-spaces before the identifier final StringBuffer kw = new StringBuffer ( ) ; while ( ! Character . isWhitespace ( c ) ) { kw . insert ( 0 , c ) ; index -- ; c = document . getChar ( index ) ; } if ( kw . toString ( ) . equals ( keyword1 ) || Arrays . contains ( otherKeywords , kw . toString ( ) ) ) { // Skip spaces before the previous keyword while ( Character . isWhitespace ( c ) ) { index -- ; c = document . getChar ( index ) ; } final int delta = issue . getOffset ( ) - index - 1 ; document . replace ( index + 1 , issue . getLength ( ) + delta , "" ) ; //$NON-NLS-1$ return true ; } return false ; }
Remove the element related to the issue and the whitespaces before the element until one of the given keywords is encountered .