Skip to content

Commit

Permalink
Fix another text block special case
Browse files Browse the repository at this point in the history
Handle removing trailing whitespace when the closing delimiter is on the same
line as the final line of the text block.

Fixes #1205

PiperOrigin-RevId: 705218533
  • Loading branch information
cushon authored and google-java-format Team committed Dec 11, 2024
1 parent ad29696 commit 3d2f63e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ private void indentTextBlocks(
}
if (i == lines.size() - 1) {
String withoutDelimiter =
trimmed.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length());
trimmed
.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length())
.stripTrailing();
if (!withoutDelimiter.stripLeading().isEmpty()) {
output.append(withoutDelimiter).append('\\').append(separator).append(prefix);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public interface Foo {

private static String foo =
"""
foo\
bar """;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public interface Foo {

private static String foo =
"""
foo\
bar\
""";
}

0 comments on commit 3d2f63e

Please sign in to comment.