blob: bc67783264fb485c6a3840d3c3d933ce8455ee74 (
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
|
import org.aspectj.testing.Tester;
public aspect AroundAdvice {
public static void main(String[] args) { test(); }
public static void test() {
Tester.checkEqual(new Foo().foo(5), 1+2+3+4+5, "sum");
Tester.checkEqual(new Foo().bar(), "overridden", "bar()");
}
pointcut fooCut(int n): target(Foo) && call(int foo(int)) && args(n);
int around(int n): fooCut(n) {
int N = n;
int sum = 0;
for(int i=0; i<N; i++) {
n = i;
int ret = proceed(n);
sum += ret;
}
return sum;
}
String around(): within(AroundAdvice) && call(String bar()) {
return "overridden";
}
}
class Foo {
public int foo(int x) {
//System.out.println("foo("+x+")");
return x+1;
}
public String bar() {
return "bar()";
}
}
|