import org.aspectj.apache.bcel.generic.Type;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
* @author Andy Clement
*/
public interface Constants {
- // Major and minor version of the code
- short MAJOR_1_1 = 45;
- short MINOR_1_1 = 3;
- short MAJOR_1_2 = 46;
- short MINOR_1_2 = 0;
- short MAJOR_1_3 = 47;
- short MINOR_1_3 = 0;
- short MAJOR_1_4 = 48;
- short MINOR_1_4 = 0;
- short MAJOR_1_5 = 49;
- short MINOR_1_5 = 0;
- short MAJOR_1_6 = 50;
- short MINOR_1_6 = 0;
- short MAJOR_1_7 = 51;
- short MINOR_1_7 = 0;
- short MAJOR_1_8 = 52;
- short MINOR_1_8 = 0;
- short MAJOR_1_9 = 53;
- short MINOR_1_9 = 0;
- short MAJOR_10 = 54;
- short MINOR_10 = 0;
- short MAJOR_11 = 55;
- short MINOR_11 = 0;
- short MAJOR_12 = 56;
- short MINOR_12 = 0;
- short MAJOR_13 = 57;
- short MINOR_13 = 0;
- short MAJOR_14 = 58;
- short MINOR_14 = 0;
- short MAJOR_15 = 59;
- short MINOR_15 = 0;
- short MAJOR_16 = 60;
- short MINOR_16 = 0;
- short MAJOR_17 = 61;
- short MINOR_17 = 0;
- short MAJOR_18 = 62;
- short MINOR_18 = 0;
- short MAJOR_19 = 63;
- short MINOR_19 = 0;
- short MAJOR_20 = 64;
- short MINOR_20 = 0;
- short MAJOR_21 = 65;
- short MINOR_21 = 0;
- // AspectJ_JDK_Update
-// short MAJOR_22 = 66;
-// short MINOR_22 = 0;
-
- int PREVIEW_MINOR_VERSION = 65535;
-
- // Defaults
- short MAJOR = MAJOR_1_1;
- short MINOR = MINOR_1_1;
+ // Selected major/minor class file versions, defined as constants because they are used in production code. Maybe,
+ // there is a slight performance advantage, therefore retain them. When tests need class file version infos, they
+ // should use ClassFileVersion.of(javaMajor) instead, avoiding new constants for every major Java release. In the
+ // past, we had too many of them.
+ int MAJOR_1_1 = 45;
+ int MINOR_1_1 = 3;
+ int MAJOR_1_5 = 49;
+ int MAJOR_1_6 = 50;
+ int MAJOR_1_8 = 52;
+
+ /**
+ * Carries information about major, minor and preview-minor version byte values found in Java class files for a
+ * specific Java version. You can obtain instances via {@link #of(int)} and {@link #of(int, int)}, respectively.
+ */
+ class ClassFileVersion {
+ private static final Map<Integer, ClassFileVersion> cache = new ConcurrentHashMap<>();
+
+ public final int MAJOR;
+ public final int MINOR;
+ public final int PREVIEW_MINOR = 65535;
+
+ private ClassFileVersion(int major, int minor) {
+ MAJOR = major;
+ MINOR = minor;
+ }
+
+ /**
+ * Obtain a class file version info instance for a specific Java version
+ *
+ * @param javaMajor Java major version; must be >= 2; values 2 to 9 are interpreted as Java versions 1.2 to 1.9
+ *
+ * @return either a cached or a new instance; result is identical to calling {@code of(javaMajor, 0)}
+ */
+ public static ClassFileVersion of(int javaMajor) {
+ return of(javaMajor, 0);
+ }
+
+ /**
+ * Obtain a class file version info instance for a specific Java version
+ *
+ * @param javaMajor Java major version; must be >= 1; values 2 to 9 are interpreted as Java versions 1.2 to 1.9
+ * @param javaMinor Java minor version; is only relevant for Java major 1 and must be in range [1..9]
+ *
+ * @return either a cached or a new instance
+ */
+ public static ClassFileVersion of(int javaMajor, int javaMinor) {
+ if (javaMajor < 1)
+ throw new IllegalArgumentException("Java major version must be >= 1");
+ if (javaMajor == 1) {
+ if (javaMinor < 1 || javaMinor > 9)
+ throw new IllegalArgumentException("Java 1.x versions must be 1.1 to 1.9");
+ // 1.1 -> 1, ..., 1.5 -> 5, ..., 1.9 -> 9
+ javaMajor = javaMinor;
+ }
+ ClassFileVersion classFileVersion = cache.get(javaMajor);
+ if (classFileVersion == null) {
+ classFileVersion = new ClassFileVersion(javaMajor + 44, javaMajor == 1 ? 3 : 0);
+ cache.put(javaMajor, classFileVersion);
+ }
+ return classFileVersion;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ClassFileVersion)) return false;
+ ClassFileVersion that = (ClassFileVersion) o;
+ // Include PREVIEW_MINOR, if it ever changes to be non-constant
+ return MAJOR == that.MAJOR && MINOR == that.MINOR /*&& PREVIEW_MINOR == that.PREVIEW_MINOR*/;
+ }
+
+ @Override
+ public int hashCode() {
+ // Include PREVIEW_MINOR, if it ever changes to be non-constant
+ return Objects.hash(MAJOR, MINOR/*, PREVIEW_MINOR*/);
+ }
+ }
/** Maximum value for an unsigned short */
int MAX_SHORT = 65535; // 2^16 - 1
ClassParser classParser = new ClassParser(moduleFilename);
JavaClass javaClass = classParser.parse();
assertNotNull(javaClass);
- assertEquals(Constants.MAJOR_1_9,javaClass.getMajor());
- assertEquals(Constants.MINOR_1_9,javaClass.getMinor());
+ assertEquals(Constants.ClassFileVersion.of(9).MAJOR, javaClass.getMajor());
+ assertEquals(Constants.ClassFileVersion.of(9).MINOR, javaClass.getMinor());
assertEquals(Constants.ACC_MODULE,javaClass.getModifiers());
assertEquals(0,javaClass.getSuperclassNameIndex());
assertEquals(0,javaClass.getInterfaceIndices().length);
* rather than executing them.
*/
public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_1_6;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(6).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() throws ClassNotFoundException {// check it is 49.0 when -1.5 is specified
runTest("simple - m");
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
// Check the stackmap stuff appears for methods in a Java6 file
* to check code generation and modification with that version specified.
*/
public class SanityTests19 extends org.aspectj.testing.XMLBasedAjcTestCase {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_1_9;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(9).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() throws ClassNotFoundException { // check it is 49.0 when -1.5 is specified
runTest("simple - m");
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
// Check the stackmap stuff appears for methods in a Java6 file
* @author Andy Clement
*/
public class SanityTestsJava10 extends org.aspectj.testing.XMLBasedAjcTestCase {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_10;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(10).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() throws ClassNotFoundException { // check it is 49.0 when -1.5 is specified
runTest("simple - m");
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
// ///////////////////////////////////////
* @author Alexander Kriegisch
*/
public class Java19PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava19Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(19);
public void testSwitchPatternMatchingPreview3Java() {
runTest("switch pattern matching preview 3 java");
- checkVersion("SwitchPatternPreview3OK", Constants.MAJOR_19, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview3OK", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingPreview3Aspect() {
runTest("switch pattern matching preview 3 aspect");
- checkVersion("SwitchPatternPreview3Aspect", Constants.MAJOR_19, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Application", Constants.MAJOR_19, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Shape", Constants.MAJOR_19, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("S", Constants.MAJOR_19, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview3Aspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Application", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Shape", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("S", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
*/
public class SanityTestsJava19 extends XMLBasedAjcTestCaseForJava19OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_19;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(19).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
* @author Andy Clement
*/
public class SanityTestsJava11 extends XMLBasedAjcTestCaseForJava11OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_11;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(11).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() throws ClassNotFoundException { // check it is 49.0 when -1.5 is specified
runTest("simple - m");
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
* @author Alexander Kriegisch
*/
public class Java20PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava20Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(20);
public void testSwitchPatternMatchingPreview4Java() {
runTest("switch pattern matching preview 4 java");
- checkVersion("SwitchPatternPreview4OK", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview4OK", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingPreview4Error() {
public void testSwitchPatternMatchingPreview3Aspect() {
runTest("switch pattern matching preview 3 aspect");
- checkVersion("SwitchPatternPreview3Aspect", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Application", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Shape", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("S", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview3Aspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Application", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Shape", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("S", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
public void testRecordPatternsPreview1Error() {
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2023-03, 4.27)
runTest("record patterns error");
- checkVersion("RecordPatternsPreview1Error", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Box", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("RecordPatternsPreview1Error", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Box", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testRecordPatternsPreview1ExhaustivenessOK1() {
*/
public class SanityTestsJava20 extends XMLBasedAjcTestCaseForJava20OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_20;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(20).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
public void testSwitchPatternMatchingPreview4Java() {
runTest("switch pattern matching preview 4 java");
- checkVersion("SwitchPatternPreview4OK", Constants.MAJOR_21, Constants.MINOR_21);
+ checkVersion("SwitchPatternPreview4OK", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
}
public void testSwitchPatternMatchingPreview4Error() {
public void testSwitchPatternMatchingPreview3Aspect() {
runTest("switch pattern matching preview 3 aspect");
- checkVersion("SwitchPatternPreview3Aspect", Constants.MAJOR_21, Constants.MINOR_21);
- checkVersion("Application", Constants.MAJOR_21, Constants.MINOR_21);
- checkVersion("Shape", Constants.MAJOR_21, Constants.MINOR_21);
- checkVersion("S", Constants.MAJOR_21, Constants.MINOR_21);
+ checkVersion("SwitchPatternPreview3Aspect", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
+ checkVersion("Application", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
+ checkVersion("Shape", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
+ checkVersion("S", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
}
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
public void testRecordPatternsPreview1Error() {
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2023-03, 4.27)
runTest("record patterns error");
- checkVersion("RecordPatternsPreview1Error", Constants.MAJOR_21, Constants.MINOR_21);
- checkVersion("Box", Constants.MAJOR_21, Constants.MINOR_21);
+ checkVersion("RecordPatternsPreview1Error", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
+ checkVersion("Box", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR);
}
public void testRecordPatternsPreview1ExhaustivenessOK1() {
*/
public class SanityTestsJava21 extends XMLBasedAjcTestCaseForJava21OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_21;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(21).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
*/
public class SanityTestsJava13 extends XMLBasedAjcTestCaseForJava13OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_13;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(13).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() throws ClassNotFoundException { // check it is 49.0 when -1.5 is specified
runTest("simple - m");
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public void testSwitch1() {
runTest("switch 1");
- checkVersion("Switch1", Constants.MAJOR_14, 0);
+ checkVersion("Switch1", Constants.ClassFileVersion.of(14).MAJOR, 0);
}
public void testSwitch2() {
runTest("switch 2");
- checkVersion("Switch2", Constants.MAJOR_14, 0);
+ checkVersion("Switch2", Constants.ClassFileVersion.of(14).MAJOR, 0);
}
public void testSwitch3() {
runTest("switch 3");
- checkVersion("Switch3", Constants.MAJOR_14, 0);
+ checkVersion("Switch3", Constants.ClassFileVersion.of(14).MAJOR, 0);
}
public static Test suite() {
* @author Alexander Kriegisch
*/
public class Java14PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava14Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(14);
public void testRecords() {
runTest("simple record");
- checkVersion("Person", Constants.MAJOR_14, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Person", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testRecords2() {
*/
public class SanityTestsJava14 extends XMLBasedAjcTestCaseForJava14OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_14;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(14).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
public void testHiddenClass() {
runTest("hidden class");
- checkVersion("HiddenClassDemo", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("HiddenClassDemo", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testTextBlock1() {
runTest("textblock 1");
- checkVersion("Code", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("Code", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testTextBlock2() {
runTest("textblock 2");
- checkVersion("Code2", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("Code2", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testRecords() {
runTest("simple record");
- checkVersion("Person", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("Person", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testRecords2() {
runTest("using a record");
- checkVersion("UsingPersonRecord", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("UsingPersonRecord", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testAdvisingRecords() {
runTest("advising records");
- checkVersion("TraceRecordComponents", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("TraceRecordComponents", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public void testInstanceofPatterns() {
runTest("instanceof patterns");
- checkVersion("Jep305", Constants.MAJOR_16, Constants.MINOR_16);
+ checkVersion("Jep305", Constants.ClassFileVersion.of(16).MAJOR, Constants.ClassFileVersion.of(16).MINOR);
}
public static Test suite() {
* @author Alexander Kriegisch
*/
public class Java16PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava16Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(16);
public void testSealedClassWithLegalSubclasses() {
runTest("sealed class with legal subclasses");
- checkVersion("Employee", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Manager", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Employee", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Manager", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSealedClassWithIllegalSubclass() {
runTest("sealed class with illegal subclass");
- checkVersion("Person", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Person", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testWeaveSealedClass() {
runTest("weave sealed class");
- checkVersion("PersonAspect", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("PersonAspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public static Test suite() {
*/
public class SanityTestsJava15 extends XMLBasedAjcTestCaseForJava15OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_15;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(15).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
*/
public class SanityTestsJava16 extends XMLBasedAjcTestCaseForJava16OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_16;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(16).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
public void testSealedClassWithLegalSubclasses() {
runTest("sealed class with legal subclasses");
- checkVersion("Employee", Constants.MAJOR_17, Constants.MINOR_17);
- checkVersion("Manager", Constants.MAJOR_17, Constants.MINOR_17);
+ checkVersion("Employee", Constants.ClassFileVersion.of(17).MAJOR, Constants.ClassFileVersion.of(17).MINOR);
+ checkVersion("Manager", Constants.ClassFileVersion.of(17).MAJOR, Constants.ClassFileVersion.of(17).MINOR);
}
public void testSealedClassWithIllegalSubclass() {
runTest("sealed class with illegal subclass");
- checkVersion("Person", Constants.MAJOR_17, Constants.MINOR_17);
+ checkVersion("Person", Constants.ClassFileVersion.of(17).MAJOR, Constants.ClassFileVersion.of(17).MINOR);
}
public void testWeaveSealedClass() {
runTest("weave sealed class");
- checkVersion("PersonAspect", Constants.MAJOR_17, Constants.MINOR_17);
+ checkVersion("PersonAspect", Constants.ClassFileVersion.of(17).MAJOR, Constants.ClassFileVersion.of(17).MINOR);
}
public static Test suite() {
// Check compiled byte code version
String className = "Buffers";
- checkVersion(className, Constants.MAJOR_1_8, Constants.MINOR_1_8);
+ checkVersion(className, Constants.ClassFileVersion.of(8).MAJOR, Constants.ClassFileVersion.of(8).MINOR);
// Disassemble method and check if Java 8 API is used as expected
JavaClass javaClass;
* @author Alexander Kriegisch
*/
public class Java17PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava17Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(17);
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
runTest("switch pattern matching error");
public void testSwitchPatternMatchingJava() {
runTest("switch pattern matching java");
- checkVersion("SwitchPatternOK", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternOK", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingAspect() {
runTest("switch pattern matching aspect");
- checkVersion("SwitchPatternAspect", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Application", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Shape", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("S", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternAspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Application", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Shape", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("S", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public static Test suite() {
*/
public class SanityTestsJava17 extends XMLBasedAjcTestCaseForJava17OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_17;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(17).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {
* @author Alexander Kriegisch
*/
public class Java18PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava18Only {
+ private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(18);
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
runTest("switch pattern matching error");
public void testSwitchPatternMatchingJava() {
runTest("switch pattern matching java");
- checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternOK", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingAspect() {
runTest("switch pattern matching aspect");
- checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Shape", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternAspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Application", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Shape", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("S", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingPreview2Error1() {
public void testSwitchPatternMatchingPreview2Java() {
runTest("switch pattern matching preview 2 java");
- checkVersion("SwitchPatternPreview2OK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview2OK", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public void testSwitchPatternMatchingPreview2Aspect() {
runTest("switch pattern matching preview 2 aspect");
- checkVersion("SwitchPatternPreview2Aspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
- checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview2Aspect", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
+ checkVersion("Application", classFileVersion.MAJOR, classFileVersion.PREVIEW_MINOR);
}
public static Test suite() {
*/
public class SanityTestsJava18 extends XMLBasedAjcTestCaseForJava18OrLater {
- public static final int bytecode_version_for_JDK_level = Constants.MAJOR_18;
+ public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(18).MAJOR;
// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
- checkVersion("A", Constants.MAJOR_1_5, 0);
+ checkVersion("A", Constants.ClassFileVersion.of(5).MAJOR, 0);
}
public static Test suite() {