aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features199
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 /tests/features199
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>
Diffstat (limited to 'tests/features199')
-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
5 files changed, 133 insertions, 57 deletions
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;
};
}
+ */
}