blob: 0f7efd4a3fc105126194e6146e29dbaceea7619e (
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
|
import org.aspectj.testing.*;
public class BindingThisInsteadOfFormal {
public static void main(String[] args) {
Caller c = new Caller();
c.goo();
Tester.checkAllEvents();
}
static {
Tester.expectEvent("before-string");
Tester.expectEvent("before-go");
Tester.expectEvent("before-static");
Tester.expectEvent("before-c");
}
}
class Caller {
void goo() {
go();
staticGo();
}
void go() {
String string = new String("string");
C c = new C();
}
static void staticGo() {
}
}
class C {
}
aspect Aspect perthis(this(Caller)) {
pointcut stringCtors(): call(String.new(String));
before(): stringCtors() {
Tester.event("before-string");
}
pointcut cCtors(): call(C.new());
before(): cCtors() {
Tester.event("before-c");
}
pointcut goCalls(Caller caller): call(void go()) && target(caller);
before(Caller caller): goCalls(caller) {
Tester.event("before-go");
Tester.check(caller != null, "instance method");
}
pointcut goStaticCalls(): call(void Caller.staticGo());
before(): goStaticCalls() {
Tester.event("before-static");
}
}
|