aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features1921/java21/UnderscoreInPointcutAspect.aj
blob: 41ed65d15264e25ab1ad606267638199d132ebc8 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public aspect UnderscoreInPointcutAspect {
  public static void main(String[] args) {
    UnderTest u = new UnderTest();
    System.out.println(u._add(12, 4));
    System.out.println(u._subtract(12, 4));
    System.out.println(u.multiply_(12, 4));
    System.out.println(u.divide_(12, 4));
    System.out.println(u.power_of(3, 3));
    System.out.println(u.squareRoot(49));
  }

  before(int a, int b) : execution(* _*(..)) && args(a, b) {
    System.out.println("[starts with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  }

  before(int a, int b) : execution(* *_(..)) && args(a, b) {
    System.out.println("[ends with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  }

  before(int a, int b) : execution(* *_*(..)) && args(a, b) {
    System.out.println("[contains underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  }

  before(int a) : execution(* *(..)) && !execution(* *_*(..)) && args(a) {
    System.out.println("[no underscore] " + thisJoinPoint + " -> " + a);
  }
}

class UnderTest {
  int _add(int a, int b) {
    return a + b;
  }

  int _subtract(int a, int b) {
    return a - b;
  }

  int multiply_(int a, int b) {
    return a * b;
  }

  int divide_(int a, int b) {
    return a / b;
  }

  int power_of(int base, int exponent) {
    return (int) Math.pow(base, exponent);
  }

  int squareRoot(int a) {
    return (int) Math.sqrt(a);
  }
}