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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
import org.aspectj.testing.Tester;
import java.util.*;
public class CallTypes {
public static void main(String[] args) {
C1 c1 = new C1();
preTest("c1.foo()");
c1.foo();
test("static c, static c1, instanceof c, instanceof c1, ");
C c = c1;
preTest("(C c = c1).foo()");
c.foo();
test("static c, instanceof c, instanceof c1, ");
c = new C();
preTest("new C().foo()");
c.foo();
test("static c, instanceof c, ");
C2 c2 = new C2();
preTest("new C2().foo()");
c2.foo();
test("static c, static c2, instanceof c, instanceof c2, ");
preTest("c1.foo1()");
c1.foo1();
test("", "static c1, instanceof c, instanceof c1, ");
}
public static void preTest(String str) {
A.noteAdvice = A.noteAdviceStar = "";
msg = str;
}
static String msg;
public static void test(String t1) {
test(t1, t1);
}
public static void test(String baseString, String starString) {
Tester.checkEqual(sort(A.noteAdvice), sort(baseString), "base: "+msg);
Tester.checkEqual(sort(A.noteAdviceStar), sort(starString), "star: "+msg);
}
private final static Collection sort(String str) {
SortedSet sort = new TreeSet();
for (StringTokenizer t = new StringTokenizer(str, ",", false);
t.hasMoreTokens();) {
String s = t.nextToken().trim();
if (s.length() > 0) sort.add(s);
}
return sort;
}
}
class C {
public void foo() { }
}
class C1 extends C {
public void foo1() { }
}
class C2 extends C {
public void foo() { }
}
aspect A {
static String noteAdvice = "";
static String noteAdviceStar = "";
before(C c): target(c) && call(void C.foo()) {
noteAdvice += "static c, ";
}
before(C1 c1): target(c1) && call(void C1.foo()) {
noteAdvice += "static c1, ";
}
before(C2 c2): target(c2) && call(void C2.foo()) {
noteAdvice += "static c2, ";
}
before(C c): target(c) && call(void foo()) {
noteAdvice += "instanceof c, ";
}
before(C1 c1): target(c1) && call(void foo()) {
noteAdvice += "instanceof c1, ";
}
before(C2 c2): target(c2) && call(void foo()) {
noteAdvice += "instanceof c2, ";
}
before(C c): target(c) && call(void C.foo*()) {
noteAdviceStar += "static c, ";
}
before(C1 c1): target(c1) && call(void C1.foo*()) {
noteAdviceStar += "static c1, ";
}
before(C2 c2): target(c2) && call(void C2.foo*()) {
noteAdviceStar += "static c2, ";
}
before(C c): target(c) && call(void foo*()) {
noteAdviceStar += "instanceof c, ";
}
before(C1 c1): target(c1) && call(void foo*()) {
noteAdviceStar += "instanceof c1, ";
}
before(C2 c2): target(c2) && call(void foo*()) {
noteAdviceStar += "instanceof c2, ";
}
}
|