diff --git a/org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc b/org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc index 3956369b262..dd3c36bb6dd 100644 --- a/org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc +++ b/org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc @@ -1,4 +1,4 @@ - + @@ -11,20 +11,20 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar index 73d4ff1e0e9..db620aae8cc 100644 Binary files a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar and b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar differ diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/RecordElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/RecordElementProcessor.java index a0371205330..75bb80c2286 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/RecordElementProcessor.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/RecordElementProcessor.java @@ -132,7 +132,8 @@ public void testPreviewFlagTrue() throws IOException { assertTrue("Preview flag not seen as enabled", preview); } SourceVersion sourceVersion = this.processingEnv.getSourceVersion(); - assertEquals("Should support the latest compliance", sourceVersion, SourceVersion.RELEASE_6); + SourceVersion expected = SourceVersion.valueOf("RELEASE_" + Runtime.version().feature()); + assertEquals("Should support the latest compliance", expected, sourceVersion); } /* * Basic test for record element and kind diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java index c0653570861..07f63a57eb9 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseProcessingEnvImpl.java @@ -33,6 +33,7 @@ import org.eclipse.jdt.internal.compiler.apt.model.TypesImpl; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -42,6 +43,12 @@ */ public abstract class BaseProcessingEnvImpl implements ProcessingEnvironment { + /** + * The minimal required Java runtime version (we need to run compiler on) + */ + public static final SourceVersion MINIMAL_REQUIRED_RUNTIME_VERSION = SourceVersion.RELEASE_17; + private static final long VERSION_FOR_MINIMAL_RUNTIME = ClassFileConstants.JDK17; + // Initialized in subclasses: protected Filer _filer; protected Messager _messager; @@ -123,61 +130,49 @@ public LookupEnvironment getLookupEnvironment() { @Override public SourceVersion getSourceVersion() { - if (this._compiler.options.sourceLevel <= ClassFileConstants.JDK1_5) { + final long sourceLevel = this._compiler.options.sourceLevel; + if (sourceLevel <= ClassFileConstants.JDK1_5) { return SourceVersion.RELEASE_5; } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_6) { + if (sourceLevel == ClassFileConstants.JDK1_6) { return SourceVersion.RELEASE_6; + } else if (sourceLevel == ClassFileConstants.JDK1_7) { + return SourceVersion.RELEASE_7; + } else if (sourceLevel == ClassFileConstants.JDK1_8) { + return SourceVersion.RELEASE_8; + } else if (sourceLevel == ClassFileConstants.JDK9) { + return SourceVersion.RELEASE_9; + } else if (sourceLevel == ClassFileConstants.JDK10) { + return SourceVersion.RELEASE_10; + } else if (sourceLevel == ClassFileConstants.JDK11) { + return SourceVersion.RELEASE_11; + } else if (sourceLevel == ClassFileConstants.JDK12) { + return SourceVersion.RELEASE_12; + } else if (sourceLevel == ClassFileConstants.JDK13) { + return SourceVersion.RELEASE_13; + } else if (sourceLevel == ClassFileConstants.JDK14) { + return SourceVersion.RELEASE_14; + } else if (sourceLevel == ClassFileConstants.JDK15) { + return SourceVersion.RELEASE_15; + } else if (sourceLevel == ClassFileConstants.JDK16) { + return SourceVersion.RELEASE_16; + } else if (sourceLevel == ClassFileConstants.JDK17) { + return SourceVersion.RELEASE_17; } - try { - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_7) { - return SourceVersion.valueOf("RELEASE_7"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_8) { - return SourceVersion.valueOf("RELEASE_8"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK9) { - return SourceVersion.valueOf("RELEASE_9"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK10) { - return SourceVersion.valueOf("RELEASE_10"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK11) { - return SourceVersion.valueOf("RELEASE_11"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK12) { - return SourceVersion.valueOf("RELEASE_12"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK13) { - return SourceVersion.valueOf("RELEASE_13"); //$NON-NLS-1$ + // From here on we can't use constants that may not be yet defined in + // minimal required runtime Java version we have to avoid + // errors like java.lang.NoSuchFieldError: RELEASE_20 + if (sourceLevel > VERSION_FOR_MINIMAL_RUNTIME) { + try { + return SourceVersion.valueOf("RELEASE_" + CompilerOptions.versionFromJdkLevel(sourceLevel)); //$NON-NLS-1$ + } catch (IllegalArgumentException e) { + // handle call on a minimal release we can run on + return MINIMAL_REQUIRED_RUNTIME_VERSION; } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK14) { - return SourceVersion.valueOf("RELEASE_14"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK15) { - return SourceVersion.valueOf("RELEASE_15"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK16) { - return SourceVersion.valueOf("RELEASE_16"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK17) { - return SourceVersion.valueOf("RELEASE_17"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK18) { - return SourceVersion.valueOf("RELEASE_18"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK19) { - return SourceVersion.valueOf("RELEASE_19"); //$NON-NLS-1$ - } - if (this._compiler.options.sourceLevel == ClassFileConstants.JDK20) { - return SourceVersion.valueOf("RELEASE_20"); //$NON-NLS-1$ - } - } catch(IllegalArgumentException e) { - // handle call on a JDK 6 - return SourceVersion.RELEASE_6; + } else { + // to make compiler happy, should never happen + throw new IllegalStateException("Invalid JDK source level: " + sourceLevel); //$NON-NLS-1$ } - // handle call on a JDK 6 by default - return SourceVersion.RELEASE_6; } /** diff --git a/org.eclipse.jdt.core.tests.builder/pom.xml b/org.eclipse.jdt.core.tests.builder/pom.xml index 0e01fb5558a..726f97ed144 100644 --- a/org.eclipse.jdt.core.tests.builder/pom.xml +++ b/org.eclipse.jdt.core.tests.builder/pom.xml @@ -44,7 +44,7 @@ - test-on-javase-9 + test-on-javase-17 @@ -53,7 +53,7 @@ - JavaSE-9 + JavaSE-17 @@ -61,11 +61,11 @@ - --add-modules ALL-SYSTEM + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17 - test-on-javase-10 + test-on-javase-20 @@ -74,7 +74,7 @@ - JavaSE-10 + JavaSE-20 @@ -82,30 +82,7 @@ - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,10 - - - - test-on-javase-11 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-11 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11 + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,20 diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml index 9fba2b29564..0c2790c9d91 100644 --- a/org.eclipse.jdt.core.tests.compiler/pom.xml +++ b/org.eclipse.jdt.core.tests.compiler/pom.xml @@ -44,177 +44,6 @@ - - test-on-javase-9 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-9 - - - - - - - - --add-modules ALL-SYSTEM - - - - test-on-javase-10 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-10 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,10 - - - - test-on-javase-11 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-11 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11 - - - - test-on-javase-12 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-12 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12 - - - - test-on-javase-13 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-13 - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13 - - - - test-on-javase-14 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-14 - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,14 - - - - test-on-javase-15 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-15 - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,14,15 - - - - test-on-javase-16 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-16 - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,15,16 - - test-on-javase-17 diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml index 1107c742801..3130530793e 100644 --- a/org.eclipse.jdt.core.tests.model/pom.xml +++ b/org.eclipse.jdt.core.tests.model/pom.xml @@ -53,160 +53,7 @@ - test-on-javase-9 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-9 - - - - - - - - --add-modules ALL-SYSTEM - - - - test-on-javase-10 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-10 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,10 - - - - test-on-javase-11 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-11 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11 - - - - test-on-javase-12 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-12 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,12 - - - - test-on-javase-13 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-13 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13 - - - - test-on-javase-14 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-14 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,14 - - - - test-on-javase-15 - - - - org.apache.maven.plugins - maven-toolchains-plugin - - - - JavaSE-15 - - - - - - - - - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,14,15 - - - - test-on-javase-16 + test-on-javase-17 @@ -215,7 +62,7 @@ - JavaSE-16 + JavaSE-17 @@ -223,11 +70,11 @@ - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,13,15,16 + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,14,17 - test-on-javase-17 + test-on-javase-18 @@ -236,7 +83,7 @@ - JavaSE-17 + JavaSE-18 @@ -244,11 +91,11 @@ - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,14,17 + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,15,18 - test-on-javase-18 + test-on-javase-19 @@ -257,7 +104,7 @@ - JavaSE-18 + JavaSE-19 @@ -265,11 +112,11 @@ - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,15,18 + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17,19 - test-on-javase-19 + test-on-javase-20 @@ -278,7 +125,7 @@ - JavaSE-19 + JavaSE-20 @@ -286,7 +133,7 @@ - --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17,19 + --add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17,20