@@ -54,7 +54,7 @@ public CxxHighlighterVisitor(SensorContext context) {
5454 public void visitFile (@ Nullable AstNode astNode ) {
5555 newHighlighting = context .newHighlighting ();
5656 InputFile inputFile = context .fileSystem ().inputFile (context .fileSystem ().predicates ()
57- .is (getContext ().getFile ().getAbsoluteFile ()));
57+ .is (getContext ().getFile ().getAbsoluteFile ()));
5858 if (inputFile != null ) {
5959 newHighlighting .onFile (inputFile );
6060 }
@@ -83,10 +83,10 @@ public void visitToken(Token token) {
8383 } else if (token .getType ().equals (CxxTokenType .STRING )) {
8484 Optional <Trivia > triviaWithConcatenatedLiterals = getTriviaWithConcatenatedLiterals (token );
8585 if (!triviaWithConcatenatedLiterals .isPresent ()) {
86- last = highlight (last , new TokenLocation (token ), TypeOfText .STRING );
86+ last = highlight (last , new StringLocation (token ), TypeOfText .STRING );
8787 } else {
8888 for (Token concatenatedLiterals : triviaWithConcatenatedLiterals .get ().getTokens ()) {
89- last = highlight (last , new TokenLocation (concatenatedLiterals ), TypeOfText .STRING );
89+ last = highlight (last , new StringLocation (concatenatedLiterals ), TypeOfText .STRING );
9090 }
9191 }
9292 }
@@ -95,7 +95,7 @@ public void visitToken(Token token) {
9595 if (trivia .isComment ()) {
9696 highlight (last , new CommentLocation (trivia .getToken ()), TypeOfText .COMMENT );
9797 } else if (trivia .isSkippedText ()
98- && trivia .getToken ().getType ().equals (CxxTokenType .PREPROCESSOR )) {
98+ && trivia .getToken ().getType ().equals (CxxTokenType .PREPROCESSOR )) {
9999 highlight (last , new PreprocessorDirectiveLocation (trivia .getToken ()), TypeOfText .PREPROCESS_DIRECTIVE );
100100 }
101101 }
@@ -104,20 +104,24 @@ public void visitToken(Token token) {
104104
105105 private Optional <Trivia > getTriviaWithConcatenatedLiterals (Token stringToken ) {
106106 return stringToken .getTrivia ().stream ()
107- .filter (t -> t .isSkippedText () && CxxTokenType .STRING .equals (t .getToken ().getType ())).findFirst ();
107+ .filter (t -> t .isSkippedText () && CxxTokenType .STRING .equals (t .getToken ().getType ())).findFirst ();
108108 }
109109
110110 private TokenLocation highlight (TokenLocation last , TokenLocation current , TypeOfText typeOfText ) {
111111 try {
112112 if (!current .overlaps (last )) {
113113 newHighlighting .highlight (current .startLine (), current .startLineOffset (),
114- current .endLine (), current .endLineOffset (), typeOfText );
114+ current .endLine (), current .endLineOffset (), typeOfText );
115115 }
116116 } catch (IllegalArgumentException ex ) {
117117 // ignore highlight errors: parsing errors could lead to wrong location data
118- LOG .warn ("Highlighting error in file '{}' at line:{}, column:{}" , getContext ().getFile ().getAbsoluteFile (),
119- current .startLine (), current .startLineOffset ());
120- LOG .debug ("highlighting exception {}" , ex );
118+ LOG .debug ("Highlighting error in file '{}' at start:{}:{} end:{}:{}" ,
119+ getContext ().getFile ().getAbsoluteFile (),
120+ current .startLine (),
121+ current .startLineOffset (),
122+ current .endLine (),
123+ current .endLineOffset ()
124+ );
121125 }
122126 return current ;
123127 }
@@ -155,15 +159,31 @@ public int endLineOffset() {
155159 public boolean overlaps (@ Nullable TokenLocation other ) {
156160 if (other != null ) {
157161 return !(startLineOffset () > other .endLineOffset ()
158- || other .startLineOffset () > endLineOffset ()
159- || startLine () > other .endLine ()
160- || other .startLine () > endLine ());
162+ || other .startLineOffset () > endLineOffset ()
163+ || startLine () > other .endLine ()
164+ || other .startLine () > endLine ());
161165 }
162166 return false ;
163167 }
164168
165169 }
166170
171+ private static class StringLocation extends TokenLocation {
172+
173+ public StringLocation (Token token ) {
174+ super (token );
175+ String value = token .getValue ();
176+ if (value .startsWith ("R" )) { // Raw String?
177+ String [] lines = CxxUtils .EOL_PATTERN .split (value , -1 );
178+
179+ if (lines .length > 1 ) {
180+ endLine = token .getLine () + lines .length - 1 ;
181+ endLineOffset = lines [lines .length - 1 ].length ();
182+ }
183+ }
184+ }
185+ }
186+
167187 private static class CommentLocation extends TokenLocation {
168188
169189 public CommentLocation (Token token ) {
0 commit comments