You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java
+11-5Lines changed: 11 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -153,11 +153,17 @@ final class Builder extends ImmutableFormatterCliArgs.Builder {
Copy file name to clipboardExpand all lines: palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java
+45-3Lines changed: 45 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -370,22 +370,60 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
370
370
List<Tok> toks = newArrayList<>();
371
371
intcharI = 0;
372
372
intcolumnI = 0;
373
+
intstringFragmentEndPos = -1;
374
+
373
375
for (RawTokt : rawToks) {
374
376
if (stopTokens.contains(t.kind())) {
375
377
break;
376
378
}
377
379
intcharI0 = t.pos();
380
+
381
+
/**
382
+
* String Templates : https://openjdk.org/jeps/430
383
+
* "String Template" tokenize like that : {STRINGFRAGMENT}{literal}{STRINGFRAGMENT} and after list of parameters
384
+
* for exemple:
385
+
* `String s = STR."\{fruit[0]} is nice";`
386
+
* will give this token (STRINGFRAGMENT)""" , (literal)fruit[0] ,(STRINGFRAGMENT)" is nice" and after "fruit[0]" again with a potion of fruit[0] on file
387
+
*
388
+
* for this reason we comme back after the position of the last STRINGFRAGMENT
389
+
*/
390
+
if (t.pos() < stringFragmentEndPos && stringFragmentEndPos < t.endPos()) {
391
+
// case System.out.println(STR." \{o} ---" );
392
+
// on this case tokTex == " ---\" " but we already add the token " ---\""
393
+
// it is why we recreate a new token with only " " (after \" )
394
+
395
+
charI0 = stringFragmentEndPos;
396
+
t = newRawTok("", t.kind(), stringFragmentEndPos, t.endPos());
397
+
}
398
+
399
+
if (t.pos() == stringFragmentEndPos) {
400
+
// reset when it come back exactly to the same position: System.out.println(STR." \{o}");
401
+
stringFragmentEndPos = -1;
402
+
}
403
+
404
+
// drop token when after STRINGFRAGMENT when it comme back
0 commit comments