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

12345678910111213141516171819202122232425262728293031323334353637
  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 pair) {
  7. System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000"));
  8. }
  9. before(Pair 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
  14. // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error:
  15. // NoSuchMethodError: 'I Pair.x()'
  16. default -> System.out.println("z");
  17. }
  18. switch (pair) {
  19. case Pair<I>(C c, I i) -> System.out.println("a");
  20. case Pair<I>(D d, C c) -> System.out.println("b");
  21. case Pair<I>(D d1, D d2) -> System.out.println("c");
  22. // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
  23. // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error:
  24. // NoSuchMethodError: 'I Pair.x()'
  25. default -> System.out.println("d");
  26. }
  27. }
  28. }
  29. sealed interface I permits C, D { }
  30. final class C implements I { }
  31. final class D implements I { }
  32. record Pair<T>(T x, T y) { }