You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RecordPatternsPreview1ExhaustivenessAspect.aj 1.4KB

1234567891011121314151617181920212223242526272829303132333435
  1. public aspect RecordPatternsPreview1ExhaustivenessAspect {
  2. static Pair<I> p2 = new Pair<>(new C(), new D());
  3. public static void main(String[] args) {
  4. doSomething(p2);
  5. }
  6. public static void doSomething(Pair<I> pair) {
  7. System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000"));
  8. }
  9. before(Pair<I> pair) : execution(* doSomething(Pair)) && args(pair) {
  10. switch (pair) {
  11. case Pair<I>(I i, C c) -> System.out.println("x");
  12. case Pair<I>(I i, D d) -> System.out.println("y");
  13. // Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
  14. // Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
  15. // default -> System.out.println("z");
  16. }
  17. switch (pair) {
  18. case Pair<I>(C c, I i) -> System.out.println("a");
  19. case Pair<I>(D d, C c) -> System.out.println("b");
  20. case Pair<I>(D d1, D d2) -> System.out.println("c");
  21. // Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455.
  22. // Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj.
  23. // default -> System.out.println("d");
  24. }
  25. }
  26. }
  27. sealed interface I permits C, D { }
  28. final class C implements I { }
  29. final class D implements I { }
  30. record Pair<T>(T x, T y) { }