Skip to content

Commit 3d2f63e

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Fix another text block special case
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
1 parent ad29696 commit 3d2f63e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ private void indentTextBlocks(
225225
}
226226
if (i == lines.size() - 1) {
227227
String withoutDelimiter =
228-
trimmed.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length());
228+
trimmed
229+
.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length())
230+
.stripTrailing();
229231
if (!withoutDelimiter.stripLeading().isEmpty()) {
230232
output.append(withoutDelimiter).append('\\').append(separator).append(prefix);
231233
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public interface Foo {
2+
3+
private static String foo =
4+
"""
5+
foo\
6+
bar """;
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public interface Foo {
2+
3+
private static String foo =
4+
"""
5+
foo\
6+
bar\
7+
""";
8+
}

0 commit comments

Comments
 (0)