From: Alexander Kriegisch Date: Tue, 28 Mar 2023 14:29:12 +0000 (+0200) Subject: Add basic tests for Java 20, deactivate Java 19 preview tests X-Git-Tag: V1_9_20~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ec5e94cc188bfb54ff96b8312548176c3c02c80a;p=aspectj.git Add basic tests for Java 20, deactivate Java 19 preview tests Signed-off-by: Alexander Kriegisch --- diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java index 87c36f2ff..216bdfdde 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java @@ -102,8 +102,10 @@ public interface Constants { short MINOR_18 = 0; short MAJOR_19 = 63; short MINOR_19 = 0; -// short MAJOR_20 = 64; -// short MINOR_20 = 0; + short MAJOR_20 = 64; + short MINOR_20 = 0; +// short MAJOR_21 = 65; +// short MINOR_21 = 0; int PREVIEW_MINOR_VERSION = 65535; diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java index dc83ed7fa..23905d45d 100644 --- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java +++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java @@ -252,15 +252,15 @@ public class AjcTask extends MatchingTask { static final String[] TARGET_INPUTS = new String[] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", "19" + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }; static final String[] SOURCE_INPUTS = new String[] { "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", - "10", "11", "12", "13", "14", "15", "16", "17", "18", "19" + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }; static final String[] COMPLIANCE_INPUTS = new String[] { "-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9", - "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19" + "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19", "-20" }; private static final ICommandEditor COMMAND_EDITOR; diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java index e0a99283d..36b642c30 100644 --- a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java @@ -20,14 +20,13 @@ public abstract class XMLBasedAjcTestCaseForJava19Only extends XMLBasedAjcTestCa @Override public void setUp() throws Exception { // Activate this block after upgrading to JDT Core Java 20 - /* throw new IllegalStateException( "These tests need a Java 19 level AspectJ compiler " + "(e.g. because they use version-specific preview features). " + "This compiler does not support preview features of a previous version anymore." ); - */ // Activate this block before upgrading to JDT Core Java 20 + /* if (!LangUtil.is19VMOrGreater() || LangUtil.is20VMOrGreater()) { throw new IllegalStateException( "These tests should be run on Java 19 only " + @@ -35,6 +34,7 @@ public abstract class XMLBasedAjcTestCaseForJava19Only extends XMLBasedAjcTestCa ); } super.setUp(); + */ } } diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20Only.java new file mode 100644 index 000000000..aeb1152fd --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20Only.java @@ -0,0 +1,40 @@ +/* ******************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +package org.aspectj.testing; + +import org.aspectj.util.LangUtil; + +/** + * Makes sure tests are running on the right level of JDK. + * + * @author Alexander Kriegisch + */ +public abstract class XMLBasedAjcTestCaseForJava20Only extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + // Activate this block after upgrading to JDT Core Java 21 + /* + throw new IllegalStateException( + "These tests need a Java 20 level AspectJ compiler " + + "(e.g. because they use version-specific preview features). " + + "This compiler does not support preview features of a previous version anymore." + ); + */ + // Activate this block before upgrading to JDT Core Java 21 + if (!LangUtil.is20VMOrGreater() || LangUtil.is21VMOrGreater()) { + throw new IllegalStateException( + "These tests should be run on Java 20 only " + + "(e.g. because they use version-specific preview features)" + ); + } + super.setUp(); + } + +} diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20OrLater.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20OrLater.java new file mode 100644 index 000000000..352136529 --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava20OrLater.java @@ -0,0 +1,27 @@ +/* ******************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +package org.aspectj.testing; + +import org.aspectj.util.LangUtil; + +/** + * Makes sure tests are running on the right level of JDK. + * + * @author Alexander Kriegisch + */ +public abstract class XMLBasedAjcTestCaseForJava20OrLater extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + if (!LangUtil.is20VMOrGreater()) + throw new IllegalStateException("These tests should be run on Java 20 or later"); + super.setUp(); + } + +} diff --git a/tests/features1919/java19/RecordPatternsPreview1Error.java b/tests/features1919/java19/RecordPatternsPreview1Error.java index 2a5038e89..c4a89b8d6 100644 --- a/tests/features1919/java19/RecordPatternsPreview1Error.java +++ b/tests/features1919/java19/RecordPatternsPreview1Error.java @@ -1,5 +1,5 @@ /** - * This was not working as expected in ECJ after the initial Java 19 merge the JDT Core main line, + * This was not working as expected in ECJ after the initial Java 19 merge from the JDT Core main line, * see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450. */ public class RecordPatternsPreview1Error { diff --git a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj index 44c7f12d0..4fad25327 100644 --- a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj +++ b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj @@ -5,17 +5,15 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect { doSomething(p2); } - public static void doSomething(Pair pair) { + public static void doSomething(Pair pair) { System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000")); } - before(Pair pair) : execution(* doSomething(Pair)) && args(pair) { + before(Pair pair) : execution(* doSomething(Pair)) && args(pair) { switch (pair) { case Pair(I i, C c) -> System.out.println("x"); case Pair(I i, D d) -> System.out.println("y"); - // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 - // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error: - // NoSuchMethodError: 'I Pair.x()' + // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed default -> System.out.println("z"); } @@ -23,9 +21,7 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect { case Pair(C c, I i) -> System.out.println("a"); case Pair(D d, C c) -> System.out.println("b"); case Pair(D d1, D d2) -> System.out.println("c"); - // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 - // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error: - // NoSuchMethodError: 'I Pair.x()' + // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed default -> System.out.println("d"); } } diff --git a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java index 4153d5021..e815c512d 100644 --- a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java +++ b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java @@ -10,12 +10,16 @@ public class RecordPatternsPreview1ExhaustivenessOK1 { switch (p2) { case Pair(I i, C c) -> System.out.println("x"); case Pair(I i, D d) -> System.out.println("y"); + // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + default -> System.out.println("z"); } switch (p2) { case Pair(C c, I i) -> System.out.println("a"); case Pair(D d, C c) -> System.out.println("b"); case Pair(D d1, D d2) -> System.out.println("c"); + // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + default -> System.out.println("d"); } } } diff --git a/tests/features1920/java20/SwitchPatternPreview4Error.java b/tests/features1920/java20/SwitchPatternPreview4Error.java new file mode 100644 index 000000000..a682c15c4 --- /dev/null +++ b/tests/features1920/java20/SwitchPatternPreview4Error.java @@ -0,0 +1,37 @@ +/** + * This used to work up to preview 3 (Java 19), but no longer in preview 4 (Java 20). + * Now, the default case seems to need to be the last one in the list. + * + * Javac says 4x: "this case label is dominated by a preceding case label" + * + * ECJ/AJC says 11x: "This case label is dominated by one of the preceding case label" (yes, "label" singular) + * See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/919. + */ +public class SwitchPatternPreview4Error { + static void defaultCanAppearBeforePattern(Integer i) { + switch (i) { + case null -> System.out.println("value unavailable: " + i); + case -1, 1 -> System.out.println("absolute value 1: " + i); + default -> System.out.println("other integer: " + i); + case Integer value when value > 0 -> System.out.println("positive integer: " + i); + } + } + + static void defaultCanAppearBeforeNull(Integer i) { + switch (i) { + case -1, 1 -> System.out.println("absolute value 1: " + i); + default -> System.out.println("other integer: " + i); + case null -> System.out.println("value unavailable: " + i); + case Integer value when value > 0 -> System.out.println("positive integer: " + i); + } + } + + static void defaultCanAppearBeforeConstantLabel(Integer i) { + switch (i) { + case null -> System.out.println("value unavailable: " + i); + default -> System.out.println("other integer: " + i); + case -1, 1 -> System.out.println("absolute value 1: " + i); + case Integer value when value > 0 -> System.out.println("positive integer: " + i); + } + } +} diff --git a/tests/features1920/java20/SwitchPatternPreview4OK.java b/tests/features1920/java20/SwitchPatternPreview4OK.java new file mode 100644 index 000000000..f5518d496 --- /dev/null +++ b/tests/features1920/java20/SwitchPatternPreview4OK.java @@ -0,0 +1,147 @@ +import java.util.List; +import java.util.Locale; + +/** + * Inspired by examples in https://openjdk.org/jeps/427 + */ +public class SwitchPatternPreview4OK { + public static void main(String[] args) { + + System.out.println(formatterPatternSwitch(null)); + System.out.println(formatterPatternSwitch(123)); + System.out.println(formatterPatternSwitch(999L)); + System.out.println(formatterPatternSwitch(12.34)); + System.out.println(formatterPatternSwitch("foo")); + System.out.println(formatterPatternSwitch(List.of(123, "foo", 999L, 12.34))); + + System.out.println(testCircle(new Rectangle())); + System.out.println(testCircle(new Circle(5))); + System.out.println(testCircle(new Circle(6))); + + System.out.println(testSealedCoverage(new A())); + System.out.println(testSealedCoverage(new B())); + System.out.println(testSealedCoverage(new C(5))); + +// constantLabelMustAppearBeforePattern(-1); +// constantLabelMustAppearBeforePattern(0); +// constantLabelMustAppearBeforePattern(42); +// constantLabelMustAppearBeforePattern(-99); +// constantLabelMustAppearBeforePattern(Integer.valueOf(123)); +// constantLabelMustAppearBeforePattern(null); + + constantLabelMustAppearBeforePatternInteger(-1); + constantLabelMustAppearBeforePatternInteger(0); + constantLabelMustAppearBeforePatternInteger(42); + constantLabelMustAppearBeforePatternInteger(-99); + constantLabelMustAppearBeforePatternInteger(Integer.valueOf(123)); + constantLabelMustAppearBeforePatternInteger(null); + +// System.out.println(testGenericSealedExhaustive(new E())); + } + + static String formatterPatternSwitch(Object o) { + return switch (o) { + case null -> "null"; + case Integer i -> String.format("int %d", i); + case Long l -> String.format("long %d", l); + case Double d -> String.format(Locale.ENGLISH, "double %f", d); + case String s -> String.format("String %s", s); + default -> o.toString(); + }; + } + + static class Shape {} + static class Rectangle extends Shape {} + static class Circle extends Shape { + private final double radius; + public Circle(double radius) { this.radius = radius; } + double calculateArea() { return Math.PI * radius * radius; } + } + + static String testCircle(Shape s) { + return switch (s) { + case Circle c when (c.calculateArea() > 100) -> "Large circle"; + case Circle c -> "Small circle"; + default -> "Non-circle"; + }; + } + + sealed interface S permits A, B, C {} + final static class A implements S {} + final static class B implements S {} + static record C(int i) implements S {} // Implicitly final + + static String testSealedCoverage(S s) { + return switch (s) { + case A a -> "Sealed sub-class A"; + case B b -> "Sealed sub-class B"; + case C c -> "Sealed sub-record C"; + }; + } + + /** + * According to an example from JEP 420, this should work, but it does not, neither with Javac nor ECJ. + * + * See: + * https://openjdk.java.net/jeps/420#1b--Dominance-of-pattern-labels + * https://bugs.openjdk.java.net/browse/JDK-8273326 + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=579355 + * + * TODO: reactivate when implemented or move to preview 5 with Java 21, Eclipse 4.28. + */ +/* + static String constantLabelMustAppearBeforePattern(Object o) { + switch (o) { + case null -> System.out.println("value unavailable: " + o); + case -1, 1 -> System.out.println("special case:" + o); + case Integer value when value > 0 -> System.out.println("positive integer: " + o); + case Integer i -> System.out.println("other integer: " + o); + default -> System.out.println("non-integer: " + o); + } + return o == null ? "null" : o.toString(); + } +*/ + + static String constantLabelMustAppearBeforePatternInteger(Integer i) { + switch (i) { + case null -> System.out.println("value unavailable: " + i); + case -1, 1 -> System.out.println("absolute value 1: " + i); + case Integer value when value > 0 -> System.out.println("positive integer: " + i); + default -> System.out.println("other integer: " + i); + } + return i == null ? "null" : i.toString(); + } + + static void nullCanAppearAfterConstantLabel(Integer i) { + switch (i) { + case -1, 1 -> System.out.println("absolute value 1: " + i); + case null -> System.out.println("value unavailable: " + i); + case Integer value when value > 0 -> System.out.println("positive integer: " + i); + default -> System.out.println("other integer: " + i); + } + } + + /** + * According to an example from JEP 420, this should work with preview 2 (Java 18), and it does with Javac, + * but not with ECJ for Java 18, 19 and 20. + * + * See: + * https://openjdk.java.net/jeps/420#2--Exhaustiveness-of-switch-expressions-and-statements + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=579360 + * https://github.com/eclipse-jdt/eclipse.jdt.core/issues/587 + * + * TODO: reactivate when implemented or move to preview 5 with Java 21. + */ +/* + sealed interface I permits D, E {} + final static class D implements I {} + final static class E implements I {} + + static int testGenericSealedExhaustive(I i) { + return switch (i) { + // Exhaustive as no D case possible! + case E bi -> 42; + }; + } +*/ +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1919/AllTestsAspectJ1919.java b/tests/src/test/java/org/aspectj/systemtest/ajc1919/AllTestsAspectJ1919.java index da1a81f97..e7b67db7b 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1919/AllTestsAspectJ1919.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1919/AllTestsAspectJ1919.java @@ -24,10 +24,11 @@ public class AllTestsAspectJ1919 { suite.addTest(Ajc1919TestsJava.suite()); } // Do not run tests using a previous compiler's preview features anymore. They would all fail. - // TODO: Comment out the following block when upgrading JDT Core to Java 20 + /* if (LangUtil.is19VMOrGreater() && !LangUtil.is20VMOrGreater()) { suite.addTest(Java19PreviewFeaturesTests.suite()); } + */ return suite; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Ajc1920TestsJava.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Ajc1920TestsJava.java new file mode 100644 index 000000000..cc2770412 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Ajc1920TestsJava.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc1920; + +import junit.framework.Test; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava20OrLater; + +/** + * @author Alexander Kriegisch + */ +public class Ajc1920TestsJava extends XMLBasedAjcTestCaseForJava20OrLater { + + public void testDummyJava20() { + //runTest("dummy Java 20"); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc1920TestsJava.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc1920.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java new file mode 100644 index 000000000..c7962c2db --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc1920; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.aspectj.util.LangUtil; + +/** + * @author Alexander Kriegisch + */ +public class AllTestsAspectJ1920 { + + public static Test suite() { + TestSuite suite = new TestSuite("AspectJ 1.9.20 tests"); + suite.addTest(Bugs1920Tests.suite()); + if (LangUtil.is20VMOrGreater()) { + suite.addTest(SanityTestsJava20.suite()); + suite.addTest(Ajc1920TestsJava.suite()); + } + // Do not run tests using a previous compiler's preview features anymore. They would all fail. + // TODO: Comment out the following block when upgrading JDT Core to Java 20 + if (LangUtil.is20VMOrGreater() && !LangUtil.is21VMOrGreater()) { + suite.addTest(Java20PreviewFeaturesTests.suite()); + } + return suite; + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java new file mode 100644 index 000000000..fca9fee20 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc1920; + +import junit.framework.Test; +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * @author Alexander Kriegisch + */ +public class Bugs1920Tests extends XMLBasedAjcTestCase { + + public void testDummyJava20() { + //runTest("dummy Java 20"); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Bugs1920Tests.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc1920.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java new file mode 100644 index 000000000..e597b32ec --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc1920; + +import junit.framework.Test; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava20Only; + +/** + * @author Alexander Kriegisch + */ +public class Java20PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava20Only { + + public void testSwitchPatternMatchingPreview4Java() { + runTest("switch pattern matching preview 4 java"); + checkVersion("SwitchPatternPreview4OK", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION); + } + + public void testSwitchPatternMatchingPreview4Error() { + runTest("switch pattern matching preview 4 error"); + } + + 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); + } + + public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() { + runTest("switch pattern matching error"); + } + + public void testSwitchPatternMatchingPreview3Error1() { + runTest("switch pattern matching preview 3 error 1"); + } + + public void testSwitchPatternMatchingPreview3Error2() { + runTest("switch pattern matching preview 3 error 2"); + } + + public void testRecordPatternsPreview1OK() { + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 + runTest("record patterns"); + } + + public void testRecordPatternsPreview1Error() { + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2033-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); + } + + public void testRecordPatternsPreview1ExhaustivenessOK1() { + // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice, + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 + // TODO: Remove redundant default clauses when fixed upstream + System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed"); + runTest("record patterns exhaustiveness 1"); + } + + public void testRecordPatternsPreview1Aspect() { + runTest("record patterns aspect"); + } + + public void testRecordPatternsPreview1ExhaustivenessAspect() { + // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice, + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 + // TODO: Remove redundant default clauses when fixed upstream + System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed"); + runTest("record patterns exhaustiveness aspect"); + } + + public void testRecordPatternsPreview1ExhaustivenessError() { + // See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 + runTest("record patterns exhaustiveness error"); + } + + public void testRecordPatternsPreview1ExhaustivenessOK2() { + // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected', + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 + // TODO: activate when fixed + System.out.println("TODO: activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 has been fixed"); + //runTest("record patterns exhaustiveness 2"); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Java20PreviewFeaturesTests.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc1920.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/SanityTestsJava20.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/SanityTestsJava20.java new file mode 100644 index 000000000..09f52c1b7 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/SanityTestsJava20.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc1920; + +import junit.framework.Test; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava20OrLater; + +/* + * Some very trivial tests that help verify things are OK. + * These are a copy of the earlier Sanity Tests created for 1.6 but these supply the -20 option + * to check code generation and modification with that version specified. + * + * @author Alexander Kriegisch + */ +public class SanityTestsJava20 extends XMLBasedAjcTestCaseForJava20OrLater { + + public static final int bytecode_version_for_JDK_level = 64; + + // Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug) + public void testSimpleJava_A() { + runTest("simple - a"); + } + + public void testSimpleJava_B() { + runTest("simple - b"); + } + + public void testSimpleCode_C() { + runTest("simple - c"); + } + + public void testSimpleCode_D() { + runTest("simple - d"); + } + + public void testSimpleCode_E() { + runTest("simple - e"); + } + + public void testSimpleCode_F() { + runTest("simple - f"); + } + + public void testSimpleCode_G() { + runTest("simple - g"); + } + + public void testSimpleCode_H() { + runTest("simple - h", true); + } + + public void testSimpleCode_I() { + runTest("simple - i"); + } + + public void testVersionCorrect1() { + runTest("simple - j"); + checkVersion("A", bytecode_version_for_JDK_level, 0); + } + + public void testVersionCorrect2() { + runTest("simple - k"); + checkVersion("A", bytecode_version_for_JDK_level, 0); + } + + public void testVersionCorrect4() { + runTest("simple - m"); + // Must be 49.0 when -1.5 is specified + checkVersion("A", 49, 0); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SanityTestsJava20.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("sanity-tests-20.xml"); + } + +} diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml new file mode 100644 index 000000000..4d2df9f39 --- /dev/null +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1920/sanity-tests-20.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/sanity-tests-20.xml new file mode 100644 index 000000000..1c6d8d870 --- /dev/null +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/sanity-tests-20.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java index 7151c092b..97676ea84 100644 --- a/util/src/main/java/org/aspectj/util/LangUtil.java +++ b/util/src/main/java/org/aspectj/util/LangUtil.java @@ -187,6 +187,10 @@ public class LangUtil { return 20 <= vmVersion; } + public static boolean is21VMOrGreater() { + return 21 <= vmVersion; + } + /** * Shorthand for "if null, throw IllegalArgumentException" *