Skip to content

Commit 043db14

Browse files
committed
wip
1 parent 11d0c00 commit 043db14

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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));

palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@Execution(ExecutionMode.CONCURRENT)
3434
public 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 {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class RSLs {
2+
{
3+
}
4+
}

0 commit comments

Comments
 (0)