blob: a07815baf6e629710087b6d1492f83a6e0e120b8 (
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
54
55
56
57
58
59
60
|
import org.aspectj.testing.Tester;
public class OverridingPointcuts {
public static void main(String[] args) {
C c1 = new C();
C c2 = new C();
c1.m1();
c2.m2();
Tester.checkEqual(c1.m1(), "A1-m1");
Tester.checkEqual(c2.m2(), "m2");
Tester.checkEqual(c1.m3(), "A1-m3");
Tester.checkEqual(c2.m3(), "m3");
Tester.check(!A2.hasAspect(c1), "c1 hasa A2");
Tester.check(A1.hasAspect(c1), "c1 hasa A1");
Tester.check(A2.hasAspect(c2), "c2 hasa A2");
Tester.check(!A1.hasAspect(c2), "!c2 hasa A1");
}
}
class C {
public String m1() { return "m1"; }
public String m2() { return "m2"; }
public String m3() { return "m3"; }
}
abstract aspect A pertarget(target(C) && call(String m2())) {
int cached;
abstract pointcut testpoint();
String modifyResult(String r) { return "A-" + r; }
String around (): testpoint() {
return modifyResult(proceed());
}
}
aspect A1 extends A pertarget(target(C) && call(String m1())) {
pointcut testpoint() : call(String C.*(..));
String modifyResult(String s) { return "A1-" + s; }
}
aspect A2 extends A {
pointcut testpoint();
}
/*
public aspect A2 extends A of eachobject(instanceof(C) && receptions(String m2())) {
pointcut testpoint() returns String: receptions(String *(..));
String modifyResult(String s) { return "A2-" + s; }
}
*/
|