aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2022-12-21 12:57:44 +0100
committerAlexander Kriegisch <Alexander@Kriegisch.name>2022-12-21 12:57:44 +0100
commit5239ae0480d4f623aa9c9491b6bf75e3e568cc89 (patch)
treef6bd5d5e80275c25770282eb5b8de4f22db8c6cd /tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj
parent9be61fe259dfd3340050f0c4d80ee9e9555583e1 (diff)
downloadaspectj-5239ae0480d4f623aa9c9491b6bf75e3e568cc89.tar.gz
aspectj-5239ae0480d4f623aa9c9491b6bf75e3e568cc89.zip
Add tests for Java 19 record patterns
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj')
-rw-r--r--tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj
new file mode 100644
index 000000000..44c7f12d0
--- /dev/null
+++ b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj
@@ -0,0 +1,37 @@
+public aspect RecordPatternsPreview1ExhaustivenessAspect {
+ static Pair<I> p2 = new Pair<>(new C(), new D());
+
+ public static void main(String[] args) {
+ doSomething(p2);
+ }
+
+ public static void doSomething(Pair pair) {
+ System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000"));
+ }
+
+ before(Pair pair) : execution(* doSomething(Pair)) && args(pair) {
+ switch (pair) {
+ case Pair<I>(I i, C c) -> System.out.println("x");
+ case Pair<I>(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()'
+ default -> System.out.println("z");
+ }
+
+ switch (pair) {
+ case Pair<I>(C c, I i) -> System.out.println("a");
+ case Pair<I>(D d, C c) -> System.out.println("b");
+ case Pair<I>(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()'
+ default -> System.out.println("d");
+ }
+ }
+}
+
+sealed interface I permits C, D { }
+final class C implements I { }
+final class D implements I { }
+record Pair<T>(T x, T y) { }