aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2022-03-24 15:16:29 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2022-03-24 15:16:29 +0700
commit50190a1918e66769e0037542054645add1ff8204 (patch)
treec58ab2b90dc44f8aa90b0ad78eb86de141471bd0
parent6403cc20326190dbc9646b0f9b1819f1bb47fc39 (diff)
downloadaspectj-50190a1918e66769e0037542054645add1ff8204.tar.gz
aspectj-50190a1918e66769e0037542054645add1ff8204.zip
Upgrade to latest JDT Core Java 18 changes, activate J18 preview tests
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
-rw-r--r--org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties2
-rw-r--r--tests/features199/java18/SwitchPatternPreview2Aspect.aj30
-rw-r--r--tests/features199/java18/SwitchPatternPreview2Error.java31
-rw-r--r--tests/features199/java18/SwitchPatternPreview2Error1.java13
-rw-r--r--tests/features199/java18/SwitchPatternPreview2Error2.java21
-rw-r--r--tests/features199/java18/SwitchPatternPreview2OK.java95
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java20
-rw-r--r--tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml33
8 files changed, 171 insertions, 74 deletions
diff --git a/org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties b/org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties
index 153469df0..23bd98c02 100644
--- a/org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties
+++ b/org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties
@@ -1,5 +1,5 @@
compiler.name = AspectJ Compiler
-compiler.version = Eclipse Compiler a721c849b3f9d5 (18Mar2022) - Java18
+compiler.version = Eclipse Compiler d3a80f1f9b2f8a (21Mar2022) - Java18
compiler.copyright =
misc.version = {0} {1} - {2} {3}
diff --git a/tests/features199/java18/SwitchPatternPreview2Aspect.aj b/tests/features199/java18/SwitchPatternPreview2Aspect.aj
index ee5dbbd68..4170b4d15 100644
--- a/tests/features199/java18/SwitchPatternPreview2Aspect.aj
+++ b/tests/features199/java18/SwitchPatternPreview2Aspect.aj
@@ -1,28 +1,26 @@
-import java.util.Locale;
-
aspect SwitchPatternPreview2Aspect {
- Object around(Object o): execution(* doSomethingWithObject(*)) && args(o) {
+ Object around(Integer i): execution(* doSomethingWithInteger(*)) && args(i) {
System.out.println(
- switch (o) {
- case -1, 1 -> "special case:" + o;
- case Integer i && i > 0 -> "positive integer: " + o;
- case Integer i -> "other integer: " + o;
- default -> "non-integer: " + o;
+ switch (i) {
+ case null -> "value unavailable: " + i;
+ case -1, 1 -> "absolute value 1: " + i;
+ case Integer value && value > 0 -> "positive integer: " + i;
+ default -> "other integer: " + i;
}
);
- return proceed(o);
+ return proceed(i);
}
}
class Application {
public static void main(String[] args) {
- doSomethingWithObject(-1);
- doSomethingWithObject(0);
- doSomethingWithObject(42);
- doSomethingWithObject(-99);
- doSomethingWithObject("test");
- doSomethingWithObject(null);
+ doSomethingWithInteger(-1);
+ doSomethingWithInteger(0);
+ doSomethingWithInteger(42);
+ doSomethingWithInteger(-99);
+ doSomethingWithInteger(Integer.valueOf(123));
+ doSomethingWithInteger(null);
}
- public static Object doSomethingWithObject(Object o) { return o; }
+ public static Object doSomethingWithInteger(Integer o) { return o; }
}
diff --git a/tests/features199/java18/SwitchPatternPreview2Error.java b/tests/features199/java18/SwitchPatternPreview2Error.java
deleted file mode 100644
index b1652aad3..000000000
--- a/tests/features199/java18/SwitchPatternPreview2Error.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Inspired by examples in https://openjdk.java.net/jeps/420
- */
-public class SwitchPatternPreview2Error {
- static void constantLabelMustAppearBeforePattern1(Object o) {
- switch (o) {
- case Integer i && i > 0 -> System.out.println("positive integer: " + o);
- case -1, 1 -> System.out.println("special case:" + o);
- case Integer i -> System.out.println("other integer: " + o);
- default -> System.out.println("non-integer: " + o);
- }
- }
-
- static void constantLabelMustAppearBeforePattern2(Object o) {
- switch (o) {
- case -1, 1 -> System.out.println("special case:" + o);
- case Integer i -> System.out.println("other integer: " + o);
- case Integer i && i > 0 -> System.out.println("positive integer: " + o);
- default -> System.out.println("non-integer: " + o);
- }
- }
-
- static void constantLabelMustAppearBeforePattern3(Object o) {
- switch (o) {
- case Integer i && i > 0 -> System.out.println("positive integer: " + o);
- case Integer i -> System.out.println("other integer: " + o);
- case -1, 1 -> System.out.println("special case:" + o);
- default -> System.out.println("non-integer: " + o);
- }
- }
-}
diff --git a/tests/features199/java18/SwitchPatternPreview2Error1.java b/tests/features199/java18/SwitchPatternPreview2Error1.java
new file mode 100644
index 000000000..342b848aa
--- /dev/null
+++ b/tests/features199/java18/SwitchPatternPreview2Error1.java
@@ -0,0 +1,13 @@
+/**
+ * Inspired by examples in https://openjdk.java.net/jeps/420
+ */
+public class SwitchPatternPreview2Error1 {
+ static void constantLabelsMustAppearBeforePatterns1(Integer i) {
+ switch (i) {
+ case null -> System.out.println("value unavailable: " + i);
+ case Integer value && value > 0 -> System.out.println("positive integer: " + i);
+ case -1, 1 -> System.out.println("absolute value 1: " + i);
+ default -> System.out.println("other integer: " + i);
+ }
+ }
+}
diff --git a/tests/features199/java18/SwitchPatternPreview2Error2.java b/tests/features199/java18/SwitchPatternPreview2Error2.java
new file mode 100644
index 000000000..3cee435e0
--- /dev/null
+++ b/tests/features199/java18/SwitchPatternPreview2Error2.java
@@ -0,0 +1,21 @@
+/**
+ * Inspired by examples in https://openjdk.java.net/jeps/420
+ */
+public class SwitchPatternPreview2Error2 {
+ static void constantLabelsMustAppearBeforePatterns2(Object o) {
+ switch (o) {
+ case null -> System.out.println("value unavailable: " + o);
+ // This seems to be a bug in JEP 420 implementation. Those constants should be compatible with 'Object'.
+ // case -1, 1 -> System.out.println("absolute value 1: " + o);
+ // case "hello" -> System.out.println("string value: " + o);
+
+ // 'Integer value' dominates the next two, more specific ones -> error
+ case Integer value -> System.out.println("other integer: " + o);
+ case Integer value && (value == 1 || value == -1) -> System.out.println("absolute value 1: " + o);
+ case Integer value && value > 0 -> System.out.println("positive integer: " + o);
+
+ case String value && value.startsWith("hello") -> System.out.println("greeting: " + o);
+ default -> System.out.println("other type: " + o);
+ }
+ }
+}
diff --git a/tests/features199/java18/SwitchPatternPreview2OK.java b/tests/features199/java18/SwitchPatternPreview2OK.java
index 859583b6d..b36b26bf2 100644
--- a/tests/features199/java18/SwitchPatternPreview2OK.java
+++ b/tests/features199/java18/SwitchPatternPreview2OK.java
@@ -1,30 +1,104 @@
-import java.util.List;
-
/**
* Inspired by examples in https://openjdk.java.net/jeps/420
*/
public class SwitchPatternPreview2OK {
public static void main(String[] args) {
- constantLabelMustAppearBeforePattern(-1);
- constantLabelMustAppearBeforePattern(0);
- constantLabelMustAppearBeforePattern(42);
- constantLabelMustAppearBeforePattern(-99);
- constantLabelMustAppearBeforePattern(Integer.valueOf(123));
- constantLabelMustAppearBeforePattern(null);
+// 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 B<Integer>()));
+// System.out.println(testGenericSealedExhaustive(new B<Integer>()));
}
+ /**
+ * 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 3 with Java 19, Eclipse 4.24.
+ */
+ /*
static String constantLabelMustAppearBeforePattern(Object o) {
switch (o) {
+ case null -> System.out.println("value unavailable: " + i);
case -1, 1 -> System.out.println("special case:" + o);
case Integer i && i > 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.toString();
+ return i == null ? "null" : i.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 && 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 && value > 0 -> System.out.println("positive integer: " + i);
+ default -> System.out.println("other integer: " + i);
+ }
+ }
+
+ 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 && 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 && 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 && value > 0 -> System.out.println("positive integer: " + i);
+ }
}
+ /**
+ * According to an example from JEP 420, this should work, and it does with Javac, but not with ECJ.
+ *
+ * See:
+ * https://openjdk.java.net/jeps/420#2--Exhaustiveness-of-switch-expressions-and-statements
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=579360
+ *
+ * TODO: reactivate when implemented or move to preview 3 with Java 19, Eclipse 4.24.
+ */
+ /*
sealed interface I<T> permits A, B {}
final static class A<X> implements I<String> {}
final static class B<Y> implements I<Y> {}
@@ -35,4 +109,5 @@ public class SwitchPatternPreview2OK {
case B<Integer> bi -> 42;
};
}
+ */
}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java
index 8d586b440..dbe6f733a 100644
--- a/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java
@@ -34,28 +34,24 @@ public class Java18PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava18Only
checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}
- // TODO:
- // JDT Core does not seem to have implemented JEP 420 yet,
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=576746.
- // Therefore, deactivate the special tests for now.
-/*
- public void testSwitchPatternMatchingPreview2Error() {
- runTest("switch pattern matching preview 2 error");
+ public void testSwitchPatternMatchingPreview2Error1() {
+ runTest("switch pattern matching preview 2 error 1");
+ }
+
+ public void testSwitchPatternMatchingPreview2Error2() {
+ runTest("switch pattern matching preview 2 error 2");
}
public void testSwitchPatternMatchingPreview2Java() {
runTest("switch pattern matching preview 2 java");
- checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview2OK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}
public void testSwitchPatternMatchingPreview2Aspect() {
runTest("switch pattern matching preview 2 aspect");
- checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("SwitchPatternPreview2Aspect", 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);
}
-*/
public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Java18PreviewFeaturesTests.class);
diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml
index f0510e79a..7baeea086 100644
--- a/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml
+++ b/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml
@@ -58,18 +58,34 @@
</ajc-test>
<!-- Java ?? final, Java 17, 18 preview -->
- <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 error">
- <compile files="SwitchPatternPreview2Error.java" options="--enable-preview -18">
+ <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 error 1">
+ <compile files="SwitchPatternPreview2Error1.java" options="--enable-preview -18">
<!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
- <message kind="error" file="SwitchPatternError.java" text="This case label is dominated by one of the preceding case label"/>
+ <message kind="error" file="SwitchPatternPreview2Error1.java" text="This case label is dominated by one of the preceding case label"/>
+ </compile>
+ </ajc-test>
+
+ <!-- Java ?? final, Java 17, 18 preview -->
+ <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 error 2">
+ <compile files="SwitchPatternPreview2Error2.java" options="--enable-preview -18">
+ <!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
+ <message kind="error" file="SwitchPatternPreview2Error2.java" text="This case label is dominated by one of the preceding case label"/>
</compile>
</ajc-test>
<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 java">
<compile files="SwitchPatternPreview2OK.java" options="--enable-preview -18" />
- <run class="SwitchPatternOK" vmargs="--enable-preview">
+ <run class="SwitchPatternPreview2OK" vmargs="--enable-preview">
+ <message></message>
<stdout>
+ <line text="absolute value 1: -1" />
+ <line text="other integer: 0" />
+ <line text="positive integer: 42" />
+ <line text="other integer: -99" />
+ <line text="positive integer: 123" />
+ <line text="value unavailable: null" />
+<!--
<line text="null" />
<line text="int 123" />
<line text="long 999" />
@@ -82,6 +98,7 @@
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
+-->
</stdout>
</run>
</ajc-test>
@@ -91,6 +108,13 @@
<compile files="SwitchPatternPreview2Aspect.aj" options="--enable-preview -18" />
<run class="Application" vmargs="--enable-preview">
<stdout>
+ <line text="absolute value 1: -1" />
+ <line text="other integer: 0" />
+ <line text="positive integer: 42" />
+ <line text="other integer: -99" />
+ <line text="positive integer: 123" />
+ <line text="value unavailable: null" />
+<!--
<line text="null" />
<line text="int 123" />
<line text="long 999" />
@@ -103,6 +127,7 @@
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
+-->
</stdout>
</run>
</ajc-test>