public RuleMatch adjustRuleMatchPos ( RuleMatch match , int charCount , int columnCount , int lineCount , String sentence , AnnotatedText annotatedText ) { int fromPos = match . getFromPos ( ) + charCount ; int toPos = match . getToPos ( ) + charCount ; if ( annotatedText != null ) { fromPos = annotatedText . getOriginalTextPositionFor ( fromPos ) ; toPos = annotatedText . getOriginalTextPositionFor ( toPos - 1 ) + 1 ; } RuleMatch thisMatch = new RuleMatch ( match ) ; thisMatch . setOffsetPosition ( fromPos , toPos ) ; List < SuggestedReplacement > replacements = match . getSuggestedReplacementObjects ( ) ; thisMatch . setSuggestedReplacementObjects ( extendSuggestions ( replacements ) ) ; String sentencePartToError = sentence . substring ( 0 , match . getFromPos ( ) ) ; String sentencePartToEndOfError = sentence . substring ( 0 , match . getToPos ( ) ) ; int lastLineBreakPos = sentencePartToError . lastIndexOf ( ' ' ) ; int column ; int endColumn ; if ( lastLineBreakPos == - 1 ) { column = sentencePartToError . length ( ) + columnCount ; } else { column = sentencePartToError . length ( ) - lastLineBreakPos ; } int lastLineBreakPosInError = sentencePartToEndOfError . lastIndexOf ( ' ' ) ; if ( lastLineBreakPosInError == - 1 ) { endColumn = sentencePartToEndOfError . length ( ) + columnCount ; } else { endColumn = sentencePartToEndOfError . length ( ) - lastLineBreakPosInError ; } int lineBreaksToError = countLineBreaks ( sentencePartToError ) ; int lineBreaksToEndOfError = countLineBreaks ( sentencePartToEndOfError ) ; thisMatch . setLine ( lineCount + lineBreaksToError ) ; thisMatch . setEndLine ( lineCount + lineBreaksToEndOfError ) ; thisMatch . setColumn ( column ) ; thisMatch . setEndColumn ( endColumn ) ; return thisMatch ; }
Change RuleMatch positions so they are relative to the complete text not just to the sentence .