public Region getRegion ( int lineNumber ) { String js = "" ; try { js = getCode ( ) ; } catch ( IOException e ) { return null ; } int pos = 0 ; int startLine = Math . max ( 1 , lineNumber - ( SOURCE_EXCERPT_REGION_LENGTH + 1 ) / 2 + 1 ) ; for ( int n = 1 ; n < startLine ; n ++ ) { int nextpos = js . indexOf ( ' ' , pos ) ; if ( nextpos == - 1 ) { break ; } pos = nextpos + 1 ; } int end = pos ; int endLine = startLine ; for ( int n = 0 ; n < SOURCE_EXCERPT_REGION_LENGTH ; n ++ , endLine ++ ) { end = js . indexOf ( ' ' , end ) ; if ( end == - 1 ) { break ; } end ++ ; } if ( lineNumber >= endLine ) { return null ; } if ( end == - 1 ) { int last = js . length ( ) - 1 ; if ( js . charAt ( last ) == ' ' ) { return new SimpleRegion ( startLine , endLine , js . substring ( pos , last ) ) ; } else { return new SimpleRegion ( startLine , endLine , js . substring ( pos ) ) ; } } else { return new SimpleRegion ( startLine , endLine , js . substring ( pos , end ) ) ; } }
Get a region around the indicated line number . The exact definition of a region is implementation specific but it must contain the line indicated by the line number . A region must not start or end by a carriage return .