aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features199/java18/SwitchPatternPreview2Aspect.aj
blob: 4170b4d15ea81c0dc9436151703bd9ef6336b0da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
aspect SwitchPatternPreview2Aspect {
  Object around(Integer i): execution(* doSomethingWithInteger(*)) && args(i) {
    System.out.println(
      switch (i) {
        case null -> "value unavailable: " + i;
        case -1, 1 -> "absolute value 1: " + i;
        case Integer value && value > 0 -> "positive integer: " + i;
        default -> "other integer: " + i;
      }
    );
    return proceed(i);
  }
}

class Application {
  public static void main(String[] args) {
    doSomethingWithInteger(-1);
    doSomethingWithInteger(0);
    doSomethingWithInteger(42);
    doSomethingWithInteger(-99);
    doSomethingWithInteger(Integer.valueOf(123));
    doSomethingWithInteger(null);
  }

  public static Object doSomethingWithInteger(Integer o) { return o; }
}