blob: bf96cdd9bb89d66807b3b8d41abd452cc8d72a2c (
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
61
|
import org.aspectj.testing.Tester;
public class AroundChangeThis {
public static void main(String[] args) {
C c1 = new C("c1");
C c2 = new C("c2");
SubC sc = new SubC("sc");
c1.m(c2);
Tester.checkAndClearEvents(new String[] { "c1.m(c2)", "c2.m(c1)" });
c1.m(sc);
Tester.checkAndClearEvents(new String[] { "c1.m(sc)", "sc.m(c1)" });
sc.m(c1);
Tester.checkAndClearEvents(new String[] { "sc.m(c1)", "c1.m(sc)" });
try {
sc.m1(c1);
} catch (ClassCastException e) {
Tester.event("ClassCastException");
}
Tester.checkAndClearEvents(new String[] { "ClassCastException" });
Tester.printEvents();
}
}
class C {
private String name;
public C(String name) { this.name = name; }
public String toString() { return name; }
public void m(Object other) {
Tester.event(this + ".m(" + other + ")");
}
}
class SubC extends C {
public SubC(String name) { super(name); }
public void m1(Object other) {
Tester.event(this + ".m1(" + other + ")");
}
}
aspect A {
/* Swaps this with arg for calls of C.m(C) */
void around(C thisC, C argC): execution(void m*(*)) && this(thisC) && args(argC) {
proceed(argC, thisC);
proceed(thisC, argC);
}
void around(C thisC, C argC): call(void m*(*)) && target(thisC) && args(argC) {
proceed(argC, thisC);
}
}
|