diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2022-03-24 15:16:29 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2022-03-24 15:16:29 +0700 |
commit | 50190a1918e66769e0037542054645add1ff8204 (patch) | |
tree | c58ab2b90dc44f8aa90b0ad78eb86de141471bd0 /tests/features199/java18/SwitchPatternPreview2OK.java | |
parent | 6403cc20326190dbc9646b0f9b1819f1bb47fc39 (diff) | |
download | aspectj-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/java18/SwitchPatternPreview2OK.java')
-rw-r--r-- | tests/features199/java18/SwitchPatternPreview2OK.java | 95 |
1 files changed, 85 insertions, 10 deletions
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; }; } + */ } |