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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
import java.util.*;
import org.aspectj.testing.Tester;
public class AroundAll {
public static void main(String[] args) {
new C();
new C("9");
//A.printLog();
A.checkLog();
}
}
class C extends SuperC {
static final int i;
final int x;
int y = 42;
static {
i = 23;
}
C(String s) {
this(Integer.valueOf(s).intValue());
A.log("C(" + s + ")");
A.log("y = " + y);
}
C(int i) {
super(i);
x = i;
i = i+1;
//System.out.println(i + 1);
A.log("x = " + x);
}
C() {
this("2");
A.log("C()");
}
}
class SuperC {
SuperC(int x) {
A.log("SuperC(" + x + ")");
}
}
aspect A {
static String[] expectedSteps = new String[] {
"enter staticinitialization(AroundAll.<clinit>)",
"exit staticinitialization(AroundAll.<clinit>)",
"enter execution(void AroundAll.main(String[]))",
"enter call(C())",
"enter staticinitialization(SuperC.<clinit>)",
"exit staticinitialization(SuperC.<clinit>)",
"enter staticinitialization(C.<clinit>)",
"exit staticinitialization(C.<clinit>)",
"enter call(Integer java.lang.Integer.valueOf(String))",
"exit call(Integer java.lang.Integer.valueOf(String))",
"enter call(int java.lang.Integer.intValue())",
"exit call(int java.lang.Integer.intValue())",
"enter execution(SuperC(int))",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"SuperC(2)",
"exit execution(SuperC(int))",
"enter execution(C(int))",
"enter set(int C.y)",
"exit set(int C.y)",
"enter set(int C.x)",
"exit set(int C.x)",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter get(int C.x)",
"exit get(int C.x)",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"x = 2",
"exit execution(C(int))",
"enter execution(C(String))",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"C(2)",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter get(int C.y)",
"exit get(int C.y)",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"y = 42",
"exit execution(C(String))",
"enter execution(C())",
"C()",
"exit execution(C())",
"exit call(C())",
"enter call(C(String))",
"enter call(Integer java.lang.Integer.valueOf(String))",
"exit call(Integer java.lang.Integer.valueOf(String))",
"enter call(int java.lang.Integer.intValue())",
"exit call(int java.lang.Integer.intValue())",
"enter execution(SuperC(int))",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"SuperC(9)",
"exit execution(SuperC(int))",
"enter execution(C(int))",
"enter set(int C.y)",
"exit set(int C.y)",
"enter set(int C.x)",
"exit set(int C.x)",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter get(int C.x)",
"exit get(int C.x)",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"x = 9",
"exit execution(C(int))",
"enter execution(C(String))",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(StringBuffer java.lang.StringBuffer.append(String))",
"exit call(StringBuffer java.lang.StringBuffer.append(String))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"C(9)",
"enter call(java.lang.StringBuffer(String))",
"exit call(java.lang.StringBuffer(String))",
"enter get(int C.y)",
"exit get(int C.y)",
"enter call(StringBuffer java.lang.StringBuffer.append(int))",
"exit call(StringBuffer java.lang.StringBuffer.append(int))",
"enter call(String java.lang.StringBuffer.toString())",
"exit call(String java.lang.StringBuffer.toString())",
"y = 42",
"exit execution(C(String))",
"exit call(C(String))",
};
static List logList = new ArrayList();
static void printLog() {
for (Iterator i = logList.iterator(); i.hasNext(); ) {
System.out.println(" \"" + i.next() + "\", ");
}
}
static void checkLog() {
Tester.checkEqual(expectedSteps, A.logList.toArray(), "steps");
Tester.checkEqual(A.logList, expectedSteps, "steps");
}
static void log(String s) {
logList.add(s);
}
static boolean test() { return true; }
// one minimal version
// before(): this(Runnable) && call(* intValue()) {
//
// }
// void around(String s): initialization(C.new(String)) && args(s) && if(s.equals("9")) {
// log("C.new(9)");
// proceed(s+"1");
// }
Object around(): //initialization(C.new(String)) {
if(test()) && !within(A) && !call(* A.*(..)) && !initialization(new(..)) && !preinitialization(new(..)) {
A.log("enter " + thisJoinPoint);
Object ret = proceed();
A.log("exit " + thisJoinPoint);
//proceed();
//System.err.println("run twice");
return ret;
}
}
|