From 36deed0ccc64ad18ea7e313579ac94344dabe5ba Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Dec 2024 14:17:02 -0800 Subject: [PATCH 01/11] Remove conditional logic in tests for unsupported JDK versions JDK 17 is now the minimum supported version. PiperOrigin-RevId: 705237702 --- .../java/FormatterIntegrationTest.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java index b83be477..6a73da18 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/FormatterIntegrationTest.java @@ -48,20 +48,6 @@ public class FormatterIntegrationTest { private static final ImmutableMultimap VERSIONED_TESTS = ImmutableMultimap.builder() - .putAll( - 14, - "I477", - "Records", - "RSLs", - "Var", - "ExpressionSwitch", - "I574", - "I594", - "SwitchComment", - "B380299722") - .putAll(15, "I603") - .putAll(16, "I588", "Sealed") - .putAll(17, "I683", "I684", "I696") .putAll( 21, "SwitchGuardClause", From 88614098a58fea1bfe214c464fde019bd725c891 Mon Sep 17 00:00:00 2001 From: Michael Plump Date: Wed, 11 Dec 2024 19:08:23 -0800 Subject: [PATCH 02/11] Update the IntelliJ plugin to 1.25.2. PiperOrigin-RevId: 705324566 --- idea_plugin/build.gradle.kts | 2 +- idea_plugin/src/main/resources/META-INF/plugin.xml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/idea_plugin/build.gradle.kts b/idea_plugin/build.gradle.kts index b2405603..d9945133 100644 --- a/idea_plugin/build.gradle.kts +++ b/idea_plugin/build.gradle.kts @@ -30,7 +30,7 @@ repositories { } // https://github.com/google/google-java-format/releases -val googleJavaFormatVersion = "1.25.1" +val googleJavaFormatVersion = "1.25.2" java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/idea_plugin/src/main/resources/META-INF/plugin.xml b/idea_plugin/src/main/resources/META-INF/plugin.xml index edede315..f7188f92 100644 --- a/idea_plugin/src/main/resources/META-INF/plugin.xml +++ b/idea_plugin/src/main/resources/META-INF/plugin.xml @@ -35,6 +35,8 @@ ]]> +
1.25.2.0
+
Updated to use google-java-format 1.25.2.
1.25.1.0
Updated to use google-java-format 1.25.1.
1.25.0.0
From eb0b7682f15ec6a2bd03d12b53bdf951dd924266 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 19 Dec 2024 17:38:22 -0800 Subject: [PATCH 03/11] Increase JAXP limits to fix Tycho plugin See https://github.com/google/google-java-format/issues/1210 PiperOrigin-RevId: 708100474 --- .mvn/jvm.config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.mvn/jvm.config b/.mvn/jvm.config index 504456f9..2e8f1d41 100644 --- a/.mvn/jvm.config +++ b/.mvn/jvm.config @@ -8,3 +8,6 @@ --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED + +-Djdk.xml.maxGeneralEntitySizeLimit=0 +-Djdk.xml.totalEntitySizeLimit=0 \ No newline at end of file From ccb56c79b0bf4cec457e06f1156a0a0234ca576d Mon Sep 17 00:00:00 2001 From: Halil Sener Date: Thu, 13 Feb 2025 14:18:00 +0100 Subject: [PATCH 04/11] Publish Linux arm64 GraalVM native-image binary --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2ce2bea..dc0b4a46 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,10 +89,10 @@ jobs: # Use "oldest" available ubuntu-* instead of -latest, # see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories; # due to https://github.com/google/google-java-format/issues/1072. - os: [ubuntu-20.04, macos-latest, windows-latest] + os: [ubuntu-20.04, ubuntu-22.04-arm, macos-latest, windows-latest] env: # NB: Must keep the keys in this inline JSON below in line with the os: above! - SUFFIX: ${{fromJson('{"ubuntu-20.04":"linux-x86-64", "macos-latest":"darwin-arm64", "windows-latest":"windows-x86-64"}')[matrix.os]}} + SUFFIX: ${{fromJson('{"ubuntu-20.04":"linux-x86-64", "ubuntu-22.04-arm":"linux-arm64", "macos-latest":"darwin-arm64", "windows-latest":"windows-x86-64"}')[matrix.os]}} EXTENSION: ${{ matrix.os == 'windows-latest' && '.exe' || '' }} steps: - name: "Check out repository" From dae09ec63ca58c04dd72555e5a82304fb32a25a1 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 20 Mar 2025 11:17:34 -0700 Subject: [PATCH 05/11] Update Error Prone version PiperOrigin-RevId: 738874322 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6efb7b7..46ccad47 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ 32.1.3-jre 1.4.0 1.0.0 - 2.36.0 + 2.37.0 1.9 1.0.1 3.6.3 From 4e0eb5ae736b42c12ae667ec2a05b668704f9b89 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 24 Mar 2025 09:25:53 -0700 Subject: [PATCH 06/11] Text block formatting refinements * Don't automatically deindent long text blocks to start at column 0. For text blocks that are already deindented the existing choice will be preserved, but it won't happen automatically. * For deindented text blocks, put the opening `"""` at column 0 instead of indenting it PiperOrigin-RevId: 739966701 --- .../java/JavaInputAstVisitor.java | 19 +++++++++++++++++ .../googlejavaformat/java/StringWrapper.java | 21 ++++++------------- .../java/StringWrapperTest.java | 2 +- .../java/testdata/B361077825.output | 4 ++-- .../googlejavaformat/java/testdata/RSLs.input | 5 +++++ .../java/testdata/RSLs.output | 21 ++++++++++++------- 6 files changed, 47 insertions(+), 25 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 dcaa930e..f21f86a5 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -42,6 +42,7 @@ import static com.sun.source.tree.Tree.Kind.STRING_LITERAL; import static com.sun.source.tree.Tree.Kind.UNION_TYPE; import static com.sun.source.tree.Tree.Kind.VARIABLE; +import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import com.google.auto.value.AutoOneOf; @@ -71,6 +72,7 @@ import com.google.googlejavaformat.FormattingError; import com.google.googlejavaformat.Indent; import com.google.googlejavaformat.Input; +import com.google.googlejavaformat.Newlines; import com.google.googlejavaformat.Op; import com.google.googlejavaformat.OpenOp; import com.google.googlejavaformat.OpsBuilder; @@ -1753,6 +1755,23 @@ public Void visitMemberSelect(MemberSelectTree node, Void unused) { public Void visitLiteral(LiteralTree node, Void unused) { sync(node); String sourceForNode = getSourceForNode(node, getCurrentPath()); + if (sourceForNode.startsWith("\"\"\"")) { + String separator = Newlines.guessLineSeparator(sourceForNode); + ImmutableList initialLines = sourceForNode.lines().collect(toImmutableList()); + String stripped = initialLines.stream().skip(1).collect(joining(separator)).stripIndent(); + // Use the last line of the text block to determine if it is deindented to column 0, by + // comparing the length of the line in the input source with the length after processing + // the text block contents with stripIndent(). + boolean deindent = + getLast(initialLines).stripTrailing().length() + == Streams.findLast(stripped.lines()).orElseThrow().stripTrailing().length(); + if (deindent) { + Indent indent = Indent.Const.make(Integer.MIN_VALUE / indentMultiplier, indentMultiplier); + builder.breakOp(indent); + } + token(sourceForNode); + return null; + } if (isUnaryMinusLiteral(sourceForNode)) { token("-"); sourceForNode = sourceForNode.substring(1).trim(); 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 5d10da38..27450d82 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java +++ b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java @@ -188,15 +188,10 @@ public Void visitLiteral(LiteralTree literalTree, Void aVoid) { private void indentTextBlocks( TreeRangeMap replacements, List textBlocks) { for (Tree tree : textBlocks) { - int startPosition = getStartPosition(tree); + int startPosition = lineMap.getStartPosition(lineMap.getLineNumber(getStartPosition(tree))); int endPosition = getEndPosition(unit, tree); String text = input.substring(startPosition, endPosition); - int lineStartPosition = lineMap.getStartPosition(lineMap.getLineNumber(startPosition)); - int startColumn = - CharMatcher.whitespace() - .negate() - .indexIn(input.substring(lineStartPosition, endPosition)) - + 1; + int leadingWhitespace = CharMatcher.whitespace().negate().indexIn(text); // Find the source code of the text block with incidental whitespace removed. // The first line of the text block is always """, and it does not affect incidental @@ -204,17 +199,13 @@ private void indentTextBlocks( ImmutableList initialLines = text.lines().collect(toImmutableList()); String stripped = initialLines.stream().skip(1).collect(joining(separator)).stripIndent(); ImmutableList lines = stripped.lines().collect(toImmutableList()); - int deindent = + boolean deindent = getLast(initialLines).stripTrailing().length() - - getLast(lines).stripTrailing().length(); + == getLast(lines).stripTrailing().length(); - String prefix = - (deindent == 0 - || lines.stream().anyMatch(x -> x.length() + startColumn - 1 > columnLimit)) - ? "" - : " ".repeat(startColumn - 1); + String prefix = deindent ? "" : " ".repeat(leadingWhitespace); - StringBuilder output = new StringBuilder(initialLines.get(0).stripLeading()); + StringBuilder output = new StringBuilder(prefix).append(initialLines.get(0).stripLeading()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String trimmed = line.stripTrailing(); 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 339ed134..a9ceeacb 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java @@ -63,7 +63,7 @@ public void textBlock() throws Exception { " private String myString;", " private ReproBug() {", " String str =", - " \"\"\"", + "\"\"\"", "{\"sourceEndpoint\":\"ri.something.1-1.object-internal.1\",\"targetEndpoint" + "\":\"ri.something.1-1.object-internal.2\",\"typeId\":\"typeId\"}\\", "\"\"\";", diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B361077825.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B361077825.output index 62344bd5..c93942a5 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B361077825.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B361077825.output @@ -10,6 +10,6 @@ class T { """; String c = """ - # No implicit input file, because they can only be created outside a symbolic macro, -"""; + # No implicit input file, because they can only be created outside a symbolic macro, + """; } 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 6eaa2855..002b3653 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,6 +40,11 @@ class RSLs { lorem ipsum """; + String l = + """ + foo +bar + baz"""; { f(""" lorem 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 6e9a3ae5..af4a8a6f 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 @@ -43,14 +43,20 @@ class RSLs { """; String j = """ -lorem -one long incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt -ipsum -"""; + lorem + one long incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt + ipsum + """; String k = - """ +""" lorem ipsum +"""; + String l = +""" + foo +bar + baz\ """; { @@ -85,10 +91,11 @@ ipsum bar """; String t = - """ +""" foo """ - + """ + + +""" bar """; String u = From 14ae0a786ed7ff88e34b7b7f26c55123df997589 Mon Sep 17 00:00:00 2001 From: "Michael Vorburger.ch" Date: Thu, 27 Mar 2025 02:37:24 -0700 Subject: [PATCH 07/11] Clarify impact of java version used on /google_java_format README. Manually created Google internal equivalent of public https://github.com/google/google-java-format/pull/1228, just in case it's easier to review here instead of there; quote with rationale for this, from public PR description: It at first confused the hell out of me why clearly the exact SAME version of google-java-format worked great locally but failed with errors (due to my use of record matching pattern syntax) on a GitHub Action - until I've noticed that it still ran under Java 17 - and that this matters to google-java-format (my naive initial assumption was that only the google-java-format version itself was relevant). PiperOrigin-RevId: 741076633 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 83a524bb..d3836efb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ and run it with: java -jar /path/to/google-java-format-${GJF_VERSION?}-all-deps.jar [files...] ``` +Note that it uses the `jdk.compiler` module to parse the Java source code. The +`java` binary version used must therefore be from a JDK (not JRE) with a version +equal to or newer than the Java language version of the files being formatted. +An alternative is to use the available GraalVM based native binaries instead. + The formatter can act on whole files, on limited lines (`--lines`), on specific offsets (`--offset`), passing through to standard-out (default) or altered in-place (`--replace`). From 9d16612acaf98bfdd46ca4733ee0b935e4d1f54d Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 27 Mar 2025 10:09:56 -0700 Subject: [PATCH 08/11] Update release.yml More permissions --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc0b4a46..5b2610d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: build-maven-jars: runs-on: ubuntu-latest permissions: - contents: write + contents: write-all steps: - name: Checkout uses: actions/checkout@v4 From 1bdb10b85170fb6812ada6dbf9e151023ef3fff2 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 27 Mar 2025 10:14:03 -0700 Subject: [PATCH 09/11] Update release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b2610d9..dc0b4a46 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: build-maven-jars: runs-on: ubuntu-latest permissions: - contents: write-all + contents: write steps: - name: Checkout uses: actions/checkout@v4 From e77d28a00bcb3d7fc7bce3a9b4e0bfe29bce3d66 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 27 Mar 2025 10:14:45 -0700 Subject: [PATCH 10/11] Update release.yml --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc0b4a46..1db537e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,6 +83,8 @@ jobs: build-native-image: name: "Build GraalVM native-image on ${{ matrix.os }}" runs-on: ${{ matrix.os }} + permissions: + contents: write needs: build-maven-jars strategy: matrix: From bbbf472acae81e9aa7669b4d57546db1d81844e7 Mon Sep 17 00:00:00 2001 From: cushon Date: Thu, 27 Mar 2025 17:19:59 +0000 Subject: [PATCH 11/11] Release google-java-format 1.26.0 --- core/pom.xml | 2 +- eclipse_plugin/META-INF/MANIFEST.MF | 2 +- eclipse_plugin/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 5b6bbb4d..ad18413a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -22,7 +22,7 @@ com.google.googlejavaformat google-java-format-parent - HEAD-SNAPSHOT + 1.26.0 google-java-format diff --git a/eclipse_plugin/META-INF/MANIFEST.MF b/eclipse_plugin/META-INF/MANIFEST.MF index 91324539..62d8b013 100644 --- a/eclipse_plugin/META-INF/MANIFEST.MF +++ b/eclipse_plugin/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: google-java-format Bundle-SymbolicName: google-java-format-eclipse-plugin;singleton:=true Bundle-Vendor: Google -Bundle-Version: 1.13.0 +Bundle-Version: 1.26.0 Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.jdt.core;bundle-version="3.10.0", org.eclipse.jface, diff --git a/eclipse_plugin/pom.xml b/eclipse_plugin/pom.xml index b2c6e368..33b23d6b 100644 --- a/eclipse_plugin/pom.xml +++ b/eclipse_plugin/pom.xml @@ -22,7 +22,7 @@ com.google.googlejavaformat google-java-format-eclipse-plugin eclipse-plugin - 1.13.0 + 1.26.0 Google Java Format Plugin for Eclipse 4.5+ diff --git a/pom.xml b/pom.xml index 46ccad47..dc86c4b6 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ com.google.googlejavaformat google-java-format-parent pom - HEAD-SNAPSHOT + 1.26.0 core