Skip to content

Commit

Permalink
Always break between leading comments and opening delimiters of text …
Browse files Browse the repository at this point in the history
…blocks

PiperOrigin-RevId: 694541639
  • Loading branch information
cushon authored and google-java-format Team committed Nov 8, 2024
1 parent 98c6bbd commit 0a60c5f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/com/google/googlejavaformat/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public interface Tok {

/** Is the {@code Tok} a comment? */
boolean isComment();

/** Is the {@code Tok} a text block? */
default boolean isTextBlock() {
return false;
}
}

/** A {@code Token} is a language-level token. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public final ImmutableList<Op> build() {
space = tokBefore.isSlashStarComment();
newlines = 0;
lastWasComment = true;
if (tokBefore.isJavadocComment()) {
if (tokBefore.isJavadocComment() || token.getTok().isTextBlock()) {
tokOps.put(j, Doc.Break.makeForced());
}
allowBlankAfterLastComment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public boolean isComment() {
return isSlashSlashComment() || isSlashStarComment();
}

@Override
public boolean isTextBlock() {
return originalText.startsWith("\"\"\"");
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class T {
{
f(
/* foo */ """
/* foo */
"""
hello
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ ipsum
"""
.formatted("world");
f(
/* foo= */ """
/* foo= */
"""
foo
""",
/* bar= */ """
/* bar= */
"""
bar
""");
}
Expand Down

0 comments on commit 0a60c5f

Please sign in to comment.