diff --git a/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/Formatter.java b/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/Formatter.java index 7831b414dc..3d64796bb5 100644 --- a/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/Formatter.java +++ b/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/Formatter.java @@ -151,7 +151,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept OpsBuilder builder = new OpsBuilder(javaInput, javaOutput); // Output the compilation unit. JavaInputAstVisitor visitor; - if (Runtime.version().feature() >= 17) { + if (options.useJava17AstVisitor()) { try { visitor = Class.forName("com.google.googlejavaformat.java.java17.Java17InputAstVisitor") diff --git a/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java b/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java index 67c13d0b37..b51a8551ce 100644 --- a/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java +++ b/subprojects/google-java-format/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java @@ -58,6 +58,8 @@ public int indentationMultiplier() { public abstract boolean reorderModifiers(); + public abstract boolean useJava17AstVisitor(); + /** Returns the code style. */ public abstract Style style(); @@ -71,7 +73,8 @@ public static Builder builder() { return new AutoValue_JavaFormatterOptions.Builder() .style(Style.GOOGLE) .formatJavadoc(true) - .reorderModifiers(true); + .reorderModifiers(true) + .useJava17AstVisitor(true); } /** A builder for {@link JavaFormatterOptions}. */ @@ -84,6 +87,8 @@ public abstract static class Builder { public abstract Builder reorderModifiers(boolean reorderModifiers); + public abstract Builder useJava17AstVisitor(boolean reorderModifiers); + public abstract JavaFormatterOptions build(); } -} +} \ No newline at end of file