Skip to content

Commit 81e9e1c

Browse files
cushongoogle-java-format Team
authored andcommitted
Always break between leading comments and opening delimiters of text blocks
PiperOrigin-RevId: 694550141
1 parent 98c6bbd commit 81e9e1c

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public interface Tok {
7171

7272
/** Is the {@code Tok} a comment? */
7373
boolean isComment();
74+
75+
/** Is the {@code Tok} a text block? */
76+
default boolean isTextBlock() {
77+
return false;
78+
}
7479
}
7580

7681
/** A {@code Token} is a language-level token. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public final ImmutableList<Op> build() {
534534
space = tokBefore.isSlashStarComment();
535535
newlines = 0;
536536
lastWasComment = true;
537-
if (tokBefore.isJavadocComment()) {
537+
if (tokBefore.isJavadocComment() || token.getTok().isTextBlock()) {
538538
tokOps.put(j, Doc.Break.makeForced());
539539
}
540540
allowBlankAfterLastComment =

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public boolean isComment() {
166166
return isSlashSlashComment() || isSlashStarComment();
167167
}
168168

169+
@Override
170+
public boolean isTextBlock() {
171+
return originalText.startsWith("\"\"\"");
172+
}
173+
169174
@Override
170175
public String toString() {
171176
return MoreObjects.toStringHelper(this)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class T {
22
{
33
f(
4-
/* foo */ """
4+
/* foo */
5+
"""
56
hello
67
""");
78
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ ipsum
6666
"""
6767
.formatted("world");
6868
f(
69-
/* foo= */ """
69+
/* foo= */
70+
"""
7071
foo
7172
""",
72-
/* bar= */ """
73+
/* bar= */
74+
"""
7375
bar
7476
""");
7577
}

0 commit comments

Comments
 (0)