diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 37779bd85..735cccaf7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -93,7 +93,7 @@ jobs:
- name: "Set up GraalVM ${{ matrix.java }}"
uses: graalvm/setup-graalvm@v1
with:
- java-version: "21"
+ java-version: "25"
distribution: "graalvm-community"
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: "true"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 1639d1e94..43dd0ed29 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -102,7 +102,7 @@ jobs:
- name: "Set up GraalVM"
uses: graalvm/setup-graalvm@v1
with:
- java-version: "21"
+ java-version: "25"
distribution: "graalvm-community"
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: "true"
diff --git a/core/pom.xml b/core/pom.xml
index 3b106cf71..f6cd62eb2 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -22,7 +22,7 @@
com.google.googlejavaformat
google-java-format-parent
- HEAD-SNAPSHOT
+ 1.33.0
google-java-format
diff --git a/core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java b/core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java
index 4035ce319..a1c722b7e 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java
@@ -17,6 +17,7 @@
package com.google.googlejavaformat.java;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.googlejavaformat.java.Trees.getEndPosition;
import static java.lang.Math.max;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -284,7 +285,7 @@ private static RangeMap buildReplacements(
continue;
}
// delete the import
- int endPosition = importTree.getEndPosition(unit.endPositions);
+ int endPosition = getEndPosition(importTree, unit);
endPosition = max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition);
String sep = Newlines.guessLineSeparator(contents);
if (endPosition + sep.length() < contents.length()
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 f1014e52f..9d917cc4a 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java
@@ -16,6 +16,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getLast;
+import static com.google.googlejavaformat.java.Trees.getEndPosition;
+import static com.google.googlejavaformat.java.Trees.getStartPosition;
import static java.lang.Math.min;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.joining;
@@ -171,7 +173,7 @@ public Void visitLiteral(LiteralTree literalTree, Void aVoid) {
&& ((MemberSelectTree) parent).getExpression().equals(literalTree)) {
return null;
}
- int endPosition = getEndPosition(unit, literalTree);
+ int endPosition = getEndPosition(literalTree, unit);
int lineEnd = endPosition;
while (Newlines.hasNewlineAt(input, lineEnd) == -1) {
lineEnd++;
@@ -188,7 +190,7 @@ private void indentTextBlocks(
TreeRangeMap replacements, List textBlocks) {
for (Tree tree : textBlocks) {
int startPosition = lineMap.getStartPosition(lineMap.getLineNumber(getStartPosition(tree)));
- int endPosition = getEndPosition(unit, tree);
+ int endPosition = getEndPosition(tree, unit);
String text = input.substring(startPosition, endPosition);
int leadingWhitespace = CharMatcher.whitespace().negate().indexIn(text);
@@ -254,7 +256,7 @@ private void wrapLongStrings(
// Handling leaving trailing non-string tokens at the end of the literal,
// e.g. the trailing `);` in `foo("...");`.
- int end = getEndPosition(unit, getLast(flat));
+ int end = getEndPosition(getLast(flat), unit);
int lineEnd = end;
while (Newlines.hasNewlineAt(input, lineEnd) == -1) {
lineEnd++;
@@ -264,7 +266,7 @@ private void wrapLongStrings(
// Get the original source text of the string literals, excluding `"` and `+`.
ImmutableList components = stringComponents(input, unit, flat);
replacements.put(
- Range.closedOpen(getStartPosition(flat.get(0)), getEndPosition(unit, getLast(flat))),
+ Range.closedOpen(getStartPosition(flat.get(0)), getEndPosition(getLast(flat), unit)),
reflow(separator, columnLimit, startColumn, trailing, components, first.get()));
}
}
@@ -280,7 +282,7 @@ private static ImmutableList stringComponents(
StringBuilder piece = new StringBuilder();
for (Tree tree : flat) {
// adjust for leading and trailing double quotes
- String text = input.substring(getStartPosition(tree) + 1, getEndPosition(unit, tree) - 1);
+ String text = input.substring(getStartPosition(tree) + 1, getEndPosition(tree, unit) - 1);
int start = 0;
for (int idx = 0; idx < text.length(); idx++) {
if (CharMatcher.whitespace().matches(text.charAt(idx))) {
@@ -453,20 +455,12 @@ && noComments(input, unit, flat.get(endIdx - 1), flat.get(endIdx))) {
private static boolean noComments(
String input, JCTree.JCCompilationUnit unit, Tree one, Tree two) {
return STRING_CONCAT_DELIMITER.matchesAllOf(
- input.subSequence(getEndPosition(unit, one), getStartPosition(two)));
+ input.subSequence(getEndPosition(one, unit), getStartPosition(two)));
}
public static final CharMatcher STRING_CONCAT_DELIMITER =
CharMatcher.whitespace().or(CharMatcher.anyOf("\"+"));
- private static int getEndPosition(JCTree.JCCompilationUnit unit, Tree tree) {
- return ((JCTree) tree).getEndPosition(unit.endPositions);
- }
-
- private static int getStartPosition(Tree tree) {
- return ((JCTree) tree).getStartPosition();
- }
-
/**
* Returns true if any lines in the given Java source exceed the column limit, or contain a {@code
* """} that could indicate a text block.
diff --git a/core/src/main/java/com/google/googlejavaformat/java/Trees.java b/core/src/main/java/com/google/googlejavaformat/java/Trees.java
index ded219644..a16ce17c0 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/Trees.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/Trees.java
@@ -15,6 +15,7 @@
package com.google.googlejavaformat.java;
import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.CompoundAssignmentTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
@@ -24,6 +25,7 @@
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.Pretty;
import com.sun.tools.javac.tree.TreeInfo;
import java.io.IOError;
@@ -44,8 +46,12 @@ static int getStartPosition(Tree expression) {
/** Returns the source end position of the node. */
static int getEndPosition(Tree expression, TreePath path) {
- return ((JCTree) expression)
- .getEndPosition(((JCTree.JCCompilationUnit) path.getCompilationUnit()).endPositions);
+ return getEndPosition(expression, path.getCompilationUnit());
+ }
+
+ /** Returns the source end position of the node. */
+ public static int getEndPosition(Tree tree, CompilationUnitTree unit) {
+ return ((JCTree) tree).getEndPosition(((JCCompilationUnit) unit).endPositions);
}
/** Returns the source text for the node. */
diff --git a/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java b/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java
index 2f2e33cbe..f5cc7fd09 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
@@ -38,8 +39,25 @@ public final class FormattingFiler implements Filer {
private final Messager messager;
/**
+ * Create a new {@link FormattingFiler}.
+ *
+ * @param processingEnv the processing environment
+ */
+ public static Filer create(ProcessingEnvironment processingEnv) {
+ Filer delegate = processingEnv.getFiler();
+ if (processingEnv.getOptions().containsKey("experimental_turbine_hjar")) {
+ return delegate;
+ }
+ return new FormattingFiler(delegate, processingEnv.getMessager());
+ }
+
+ /**
+ * Create a new {@link FormattingFiler}.
+ *
* @param delegate filer to decorate
+ * @deprecated prefer {@link #create(ProcessingEnvironment)}
*/
+ @Deprecated
public FormattingFiler(Filer delegate) {
this(delegate, null);
}
@@ -50,7 +68,9 @@ public FormattingFiler(Filer delegate) {
*
* @param delegate filer to decorate
* @param messager to log warnings to
+ * @deprecated prefer {@link #create(ProcessingEnvironment)}
*/
+ @Deprecated
public FormattingFiler(Filer delegate, @Nullable Messager messager) {
this.delegate = checkNotNull(delegate);
this.messager = messager;
diff --git a/eclipse_plugin/META-INF/MANIFEST.MF b/eclipse_plugin/META-INF/MANIFEST.MF
index 4170ad643..b8e1d4687 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.31.0
+Bundle-Version: 1.33.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 a5d8c23ae..0e5215010 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.31.0
+ 1.33.0
Google Java Format Plugin for Eclipse 4.5+
diff --git a/pom.xml b/pom.xml
index f3668d649..0aedfbdab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
com.google.googlejavaformat
google-java-format-parent
pom
- HEAD-SNAPSHOT
+ 1.33.0
core
@@ -89,7 +89,7 @@
32.1.3-jre
1.4.0
1.0.0
- 2.42.0
+ 2.45.0
1.9
1.0.1
3.6.3