private boolean isSelectionCommented ( ISelection selection ) { if ( ! ( selection instanceof ITextSelection ) ) return false ; ITextSelection textSelection = ( ITextSelection ) selection ; if ( textSelection . getStartLine ( ) < 0 || textSelection . getEndLine ( ) < 0 ) return false ; IDocument document = getTextEditor ( ) . getDocumentProvider ( ) . getDocument ( getTextEditor ( ) . getEditorInput ( ) ) ; try { IRegion block = getTextBlockFromSelection ( textSelection , document ) ; ITypedRegion [ ] regions = TextUtilities . computePartitioning ( document , fDocumentPartitioning , block . getOffset ( ) , block . getLength ( ) , false ) ; int [ ] lines = new int [ regions . length * 2 ] ; // [startline, endline, startline, endline, ...] for ( int i = 0 , j = 0 ; i < regions . length ; i ++ , j += 2 ) { // start line of region lines [ j ] = getFirstCompleteLineOfRegion ( regions [ i ] , document ) ; // end line of region int length = regions [ i ] . getLength ( ) ; int offset = regions [ i ] . getOffset ( ) + length ; if ( length > 0 ) offset -- ; lines [ j + 1 ] = ( lines [ j ] == - 1 ? - 1 : document . getLineOfOffset ( offset ) ) ; } // Perform the check for ( int i = 0 , j = 0 ; i < regions . length ; i ++ , j += 2 ) { String [ ] prefixes = ( String [ ] ) fPrefixesMap . get ( regions [ i ] . getType ( ) ) ; if ( prefixes != null && prefixes . length > 0 && lines [ j ] >= 0 && lines [ j + 1 ] >= 0 ) if ( ! isBlockCommented ( lines [ j ] , lines [ j + 1 ] , prefixes , document ) ) return false ; } return true ; } catch ( BadLocationException x ) { // should not happen VdmUIPlugin . log ( x ) ; } return false ; }
Is the given selection single - line commented?