Skip to content

Commit 33bf757

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Update text block formatting after nickreid's improvements in unknown commit
Previously the formatting was adding a forced break at the beginning of text blocks, which caused issues like #1081. With the changes in the baseline CL it correctly handles the 'width' of text blocks containing newlines as infinity, instead of counting the number of characters and treating the newline as having width 1. Fixes #1081 PiperOrigin-RevId: 620933964
1 parent 9bdae02 commit 33bf757

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

-3
Original file line numberDiff line numberDiff line change
@@ -1667,9 +1667,6 @@ public Void visitMemberSelect(MemberSelectTree node, Void unused) {
16671667
public Void visitLiteral(LiteralTree node, Void unused) {
16681668
sync(node);
16691669
String sourceForNode = getSourceForNode(node, getCurrentPath());
1670-
if (sourceForNode.startsWith("\"\"\"")) {
1671-
builder.forcedBreak();
1672-
}
16731670
if (isUnaryMinusLiteral(sourceForNode)) {
16741671
token("-");
16751672
sourceForNode = sourceForNode.substring(1).trim();

core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.input

+11
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,15 @@ class RSLs {
4040
lorem
4141
ipsum
4242
""";
43+
{
44+
f("""
45+
lorem
46+
ipsum
47+
""", 42);
48+
49+
"""
50+
hello %s
51+
"""
52+
.formatted("world");
53+
}
4354
}

core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.output

+14
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,18 @@ ipsum
5151
lorem
5252
ipsum
5353
""";
54+
55+
{
56+
f(
57+
"""
58+
lorem
59+
ipsum
60+
""",
61+
42);
62+
63+
"""
64+
hello %s
65+
"""
66+
.formatted("world");
67+
}
5468
}

0 commit comments

Comments
 (0)