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.2KB

123456789101112131415161718192021222324252627282930313233
  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. // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
  14. default -> System.out.println("z");
  15. }
  16. switch (pair) {
  17. case Pair<I>(C c, I i) -> System.out.println("a");
  18. case Pair<I>(D d, C c) -> System.out.println("b");
  19. case Pair<I>(D d1, D d2) -> System.out.println("c");
  20. // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
  21. default -> System.out.println("d");
  22. }
  23. }
  24. }
  25. sealed interface I permits C, D { }
  26. final class C implements I { }
  27. final class D implements I { }
  28. record Pair<T>(T x, T y) { }