blob: 6c5e26ce9821ba6e2e8eb78ee8dd877a4cf4a232 (
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
62
63
64
|
import org.aspectj.testing.Tester;
/** @testcase replacing this or target in around advice */
public class TargetObjectReplacement {
public static void main(String[] args) {
Foo f = new Foo("orig");
// replacing target or this in advice does not affect caller reference
f.m();
f.n();
f.o();
f.p();
Tester.checkEqual(f.idhat, "orig"); // no affect presumed
Tester.checkAllEvents();
}
static {
Tester.expectEvent("m: m-delegate");
Tester.expectEvent("n: n-delegate");
Tester.expectEvent("o: o-delegate");
Tester.expectEvent("p: orig"); // no affect presumed
}
}
class Foo {
String id;
String idhat;
Foo(String id) {
this.id = id;
this.idhat = id;
}
void m() {
Tester.event("m: " + id);
}
void n() {
Tester.event("n: " + id);
}
void o() {
Tester.event("o: " + id);
}
void p() {
Tester.event("p: " + id); // before around advice on idhat get
Tester.checkEqual(idhat, "p-delegate"); // callees affected
}
}
aspect A {
void around(Foo foo): target(foo) && call(void m()) {
proceed(new Foo("m-delegate"));
}
void around(Foo foo): target(foo) && execution(void n()) {
proceed(new Foo("n-delegate"));
}
void around(Foo foo): this(foo) && execution(void o()) {
proceed(new Foo("o-delegate"));
}
String around(Foo foo): target(foo) && get(String Foo.idhat) && within(Foo) {
return proceed(new Foo("p-delegate"));
}
}
|