diff --git a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java index d801c9b86..f241ae47f 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java +++ b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java @@ -15,6 +15,7 @@ package com.google.googlejavaformat.java; import static com.google.common.collect.Iterables.getLast; +import static java.lang.Math.min; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; @@ -122,6 +123,10 @@ public Void visitLiteral(LiteralTree literalTree, Void aVoid) { if (literalTree.getKind() != Kind.STRING_LITERAL) { return null; } + int pos = getStartPosition(literalTree); + if (input.substring(pos, min(input.length(), pos + 3)).equals("\"\"\"")) { + return null; + } Tree parent = getCurrentPath().getParentPath().getLeaf(); if (parent instanceof MemberSelectTree && ((MemberSelectTree) parent).getExpression().equals(literalTree)) { diff --git a/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java b/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java index 99e1b2fc5..0430f6534 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java @@ -52,6 +52,25 @@ public void testAwkwardLineEndWrapping() throws Exception { assertThat(StringWrapper.wrap(100, input, new Formatter())).isEqualTo(output); } + @Test + public void textBlock() throws Exception { + String input = + lines( + "package com.mypackage;", + "public class ReproBug {", + " private String myString;", + " private ReproBug() {", + " String str =", + " \"\"\"", + " " + + " {\"sourceEndpoint\":\"ri.something.1-1.object-internal.1\",\"targetEndpoint\":\"ri.some" + + "thing.1-1.object-internal.2\",\"typeId\":\"typeId\"}\"\"\";", + " myString = str;", + " }", + "}"); + assertThat(StringWrapper.wrap(100, input, new Formatter())).isEqualTo(input); + } + private static String lines(String... line) { return Joiner.on('\n').join(line) + '\n'; }