File tree Expand file tree Collapse file tree
main/java/com/palantir/javaformat/java
java/com/palantir/javaformat/java
resources/com/palantir/javaformat/java/testdata2 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2655,6 +2655,7 @@ void visitDot(ExpressionTree node0) {
26552655 List <ExpressionTree > items = new ArrayList <>(stack );
26562656
26572657 boolean needDot = false ;
2658+ boolean isTextBlock = false ;
26582659
26592660 // The dot chain started with a primary expression: output it normally, and indent
26602661 // the rest of the chain +4.
@@ -2666,17 +2667,26 @@ void visitDot(ExpressionTree node0) {
26662667 scan (getArrayBase (node ), null );
26672668 token ("." );
26682669 } else {
2670+ // Special case for text blocks: if the node is a string literal that ends with """,
2671+ // don't add a break after it
2672+ if (node instanceof LiteralTree && node .getKind () == Tree .Kind .STRING_LITERAL ) {
2673+ String sourceForNode = getSourceForNode (node , getCurrentPath ());
2674+ isTextBlock = sourceForNode .trim ().endsWith ("\" \" \" " );
2675+ }
2676+
26692677 builder .open (OpenOp .builder ()
26702678 .debugName ("visitDot" )
26712679 .plusIndent (plusFour )
26722680 .breakBehaviour (BreakBehaviours .preferBreakingLastInnerLevel (true ))
26732681 .breakabilityIfLastLevel (
26742682 LastLevelBreakability .ACCEPT_INLINE_CHAIN_IF_SIMPLE_OTHERWISE_CHECK_INNER )
2675- .columnLimitBeforeLastBreak (METHOD_CHAIN_COLUMN_LIMIT )
2683+ .columnLimitBeforeLastBreak (isTextBlock ? Integer . MAX_VALUE : METHOD_CHAIN_COLUMN_LIMIT )
26762684 .isSimple (false )
26772685 .build ());
26782686 scan (getArrayBase (node ), null );
2679- builder .breakOp ();
2687+ if (!isTextBlock ) {
2688+ builder .breakOp ();
2689+ }
26802690 needDot = true ;
26812691 }
26822692 formatArrayIndices (getArrayIndices (node ));
Original file line number Diff line number Diff line change 3333@ Execution (ExecutionMode .CONCURRENT )
3434public class FormatterIntegrationTest {
3535
36- private static FileBasedTests tests = new FileBasedTests (FormatterIntegrationTest .class , "testdata " );
36+ private static FileBasedTests tests = new FileBasedTests (FormatterIntegrationTest .class , "testdata2 " );
3737
3838 @ ParameterizedClass .Parameters (name = "{0}" )
3939 public static List <Object []> data () throws IOException {
Original file line number Diff line number Diff line change 1+ class RSLs {
2+ {
3+ """
4+ No tools or answer found in the message. Please try again, following the instructions:\s
5+
6+ %s
7+ """
8+ .someOtherValue(e -> e.getValue().print()).myValue(System.err::println).formatted(toolFormatter.usage()).myOtherValue().someOtherValue().somethingElse();
9+
10+ myValue.someOtherValue(e -> e.getValue().print()).myValue(System.err::println).formatted(toolFormatter.usage()).myOtherValue().someOtherValue().somethingElse();
11+
12+ """
13+ No tools or answer found in the message. Please try again, following the i
14+ """.codePoints();
15+ """
16+ No tools or answer found in the message. Please try again, following the instructions:
17+ """
18+ .codePoints().forEach(System.err::println);
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ class RSLs {
2+ {
3+ }
4+ }
You can’t perform that action at this time.
0 commit comments