From 33bf757b184cecd5be0c5377cdd3afbc7908f96f Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 1 Apr 2024 13:17:34 -0700 Subject: [PATCH] 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 https://github.com/google/google-java-format/issues/1081 PiperOrigin-RevId: 620933964 --- .../googlejavaformat/java/JavaInputAstVisitor.java | 3 --- .../googlejavaformat/java/testdata/RSLs.input | 11 +++++++++++ .../googlejavaformat/java/testdata/RSLs.output | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index 6dc82f40c..1e0675ffd 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -1667,9 +1667,6 @@ public Void visitMemberSelect(MemberSelectTree node, Void unused) { public Void visitLiteral(LiteralTree node, Void unused) { sync(node); String sourceForNode = getSourceForNode(node, getCurrentPath()); - if (sourceForNode.startsWith("\"\"\"")) { - builder.forcedBreak(); - } if (isUnaryMinusLiteral(sourceForNode)) { token("-"); sourceForNode = sourceForNode.substring(1).trim(); diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.input index f401285bc..22aa8f2b2 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.input +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.input @@ -40,4 +40,15 @@ class RSLs { lorem ipsum """; + { + f(""" + lorem + ipsum + """, 42); + + """ + hello %s + """ + .formatted("world"); + } } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.output index c6051d1fd..5ca1fb8cc 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/RSLs.output @@ -51,4 +51,18 @@ ipsum lorem ipsum """; + + { + f( + """ + lorem + ipsum + """, + 42); + + """ + hello %s + """ + .formatted("world"); + } }