aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Miller-Cushon <cushon@google.com>2021-12-22 08:01:12 -0800
committergoogle-java-format Team <google-java-format-dev+copybara@google.com>2021-12-22 08:01:44 -0800
commit7bc5daec11d91caf28ab8b1bd61d6beaf9a59c15 (patch)
tree5bc12ac0d82a4cc9736c5cbaa6991abbc880f485
parent4347a6454978a5401a3b2e1ff851bea1400bb189 (diff)
downloadgoogle-java-format-7bc5daec11d91caf28ab8b1bd61d6beaf9a59c15.tar.gz
Remove some reflection now that we require JDK 11 to run the formatter
PiperOrigin-RevId: 417821422
-rw-r--r--core/src/main/java/com/google/googlejavaformat/java/Formatter.java22
1 files changed, 1 insertions, 21 deletions
diff --git a/core/src/main/java/com/google/googlejavaformat/java/Formatter.java b/core/src/main/java/com/google/googlejavaformat/java/Formatter.java
index 3e97395..aac829d 100644
--- a/core/src/main/java/com/google/googlejavaformat/java/Formatter.java
+++ b/core/src/main/java/com/google/googlejavaformat/java/Formatter.java
@@ -14,8 +14,6 @@
package com.google.googlejavaformat.java;
-import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_VERSION;
-import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
@@ -42,7 +40,6 @@ import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Options;
import java.io.IOError;
import java.io.IOException;
-import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
@@ -154,7 +151,7 @@ public final class Formatter {
OpsBuilder builder = new OpsBuilder(javaInput, javaOutput);
// Output the compilation unit.
JavaInputAstVisitor visitor;
- if (getMajor() >= 14) {
+ if (Runtime.version().feature() >= 14) {
try {
visitor =
Class.forName("com.google.googlejavaformat.java.java14.Java14InputAstVisitor")
@@ -176,23 +173,6 @@ public final class Formatter {
javaOutput.flush();
}
- // Runtime.Version was added in JDK 9, so use reflection to access it to preserve source
- // compatibility with Java 8.
- private static int getMajor() {
- try {
- Method versionMethod = Runtime.class.getMethod("version");
- Object version = versionMethod.invoke(null);
- return (int) version.getClass().getMethod("major").invoke(version);
- } catch (Exception e) {
- // continue below
- }
- int version = (int) Double.parseDouble(JAVA_CLASS_VERSION.value());
- if (49 <= version && version <= 52) {
- return version - (49 - 5);
- }
- throw new IllegalStateException("Unknown Java version: " + JAVA_SPECIFICATION_VERSION.value());
- }
-
static boolean errorDiagnostic(Diagnostic<?> input) {
if (input.getKind() != Diagnostic.Kind.ERROR) {
return false;