1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package test.expression;
9
10 import junit.framework.TestCase;
11 import org.codehaus.aspectwerkz.expression.ExpressionContext;
12 import org.codehaus.aspectwerkz.expression.ExpressionInfo;
13 import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
14 import org.codehaus.aspectwerkz.expression.ExpressionVisitor;
15 import org.codehaus.aspectwerkz.expression.PointcutType;
16 import org.codehaus.aspectwerkz.reflect.ClassInfo;
17 import org.codehaus.aspectwerkz.reflect.ConstructorInfo;
18 import org.codehaus.aspectwerkz.reflect.FieldInfo;
19 import org.codehaus.aspectwerkz.reflect.MethodInfo;
20 import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo;
21 import org.codehaus.aspectwerkz.reflect.impl.java.JavaFieldInfo;
22 import org.codehaus.aspectwerkz.reflect.impl.java.JavaMethodInfo;
23
24 /***
25 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
26 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
27 */
28 public class ExpressionTest extends TestCase {
29 private static final String NAMESPACE = "TESTING";
30
31 private static ExpressionNamespace s_namespace = ExpressionNamespace.getNamespace(NAMESPACE);
32
33 private static ClassInfo s_declaringType = JavaClassInfo.getClassInfo(Target.class);
34
35 private static MethodInfo modifiers1;
36
37 private static MethodInfo modifiers2;
38
39 private static MethodInfo modifiers3;
40
41 private static MethodInfo modifiers4;
42
43 private static MethodInfo parameters1;
44
45 private static MethodInfo parameters2;
46
47 private static MethodInfo parameters2bis;
48
49 private static MethodInfo parameters3;
50
51 private static MethodInfo parameters4;
52
53 private static MethodInfo parameters5;
54
55 private static MethodInfo returnType1;
56
57 private static MethodInfo returnType2;
58
59 private static MethodInfo returnType3;
60
61 private static MethodInfo returnType4;
62
63 private static MethodInfo returnType5;
64
65 private static MethodInfo _method$Name1;
66
67 private static MethodInfo attributes1;
68
69 private static ConstructorInfo constructorNoArgPublic;
70
71 private static ConstructorInfo constructorIntArgPrivate;
72
73 private static FieldInfo modifier1;
74
75 private static FieldInfo modifier2;
76
77 private static FieldInfo modifier3;
78
79 private static FieldInfo type1;
80
81 private static FieldInfo type2;
82
83 private static FieldInfo type3;
84
85 private static FieldInfo type4;
86
87 private static FieldInfo _field$Name1;
88
89 private static FieldInfo attribute1;
90
91
92 static {
93 ConstructorInfo[] constructors = s_declaringType.getConstructors();
94 for (int i = 0; i < constructors.length; i++) {
95 ConstructorInfo constructor = constructors[i];
96 if (constructor.getParameterTypes().length == 0) {
97 constructorNoArgPublic = constructor;
98 } else {
99 constructorIntArgPrivate = constructor;
100 }
101 }
102
103 MethodInfo[] methods = s_declaringType.getMethods();
104 for (int i = 0; i < methods.length; i++) {
105 MethodInfo method = methods[i];
106 if (method.getName().equals("modifiers1")) {
107 modifiers1 = method;
108 }
109 if (method.getName().equals("modifiers2")) {
110 modifiers2 = method;
111 }
112 if (method.getName().equals("modifiers3")) {
113 modifiers3 = method;
114 }
115 if (method.getName().equals("modifiers4")) {
116 modifiers4 = method;
117 }
118 if (method.getName().equals("parameters1")) {
119 parameters1 = method;
120 }
121 if (method.getName().equals("parameters2")) {
122 parameters2 = method;
123 }
124 if (method.getName().equals("parameters2bis")) {
125 parameters2bis = method;
126 }
127 if (method.getName().equals("parameters3")) {
128 parameters3 = method;
129 }
130 if (method.getName().equals("parameters4")) {
131 parameters4 = method;
132 }
133 if (method.getName().equals("parameters5")) {
134 parameters5 = method;
135 }
136 if (method.getName().equals("returnType1")) {
137 returnType1 = method;
138 }
139 if (method.getName().equals("returnType1")) {
140 returnType1 = method;
141 }
142 if (method.getName().equals("returnType2")) {
143 returnType2 = method;
144 }
145 if (method.getName().equals("returnType3")) {
146 returnType3 = method;
147 }
148 if (method.getName().equals("returnType4")) {
149 returnType4 = method;
150 }
151 if (method.getName().equals("returnType5")) {
152 returnType5 = method;
153 }
154 if (method.getName().equals("__method$Name1")) {
155 _method$Name1 = method;
156 }
157 if (method.getName().equals("attributes1")) {
158 attributes1 = method;
159 }
160 }
161 FieldInfo[] fields = s_declaringType.getFields();
162 for (int f = 0; f < fields.length; f++) {
163 FieldInfo field = fields[f];
164 if (field.getName().equals("modifier1")) {
165 modifier1 = field;
166 }
167 if (field.getName().equals("modifier2")) {
168 modifier2 = field;
169 }
170 if (field.getName().equals("modifier3")) {
171 modifier3 = field;
172 }
173 if (field.getName().equals("type1")) {
174 type1 = field;
175 }
176 if (field.getName().equals("type2")) {
177 type2 = field;
178 }
179 if (field.getName().equals("type3")) {
180 type3 = field;
181 }
182 if (field.getName().equals("type4")) {
183 type4 = field;
184 }
185 if (field.getName().equals("__field$Name1")) {
186 _field$Name1 = field;
187 }
188 if (field.getName().equals("attribute1")) {
189 attribute1 = field;
190 }
191 }
192 }
193
194 public ExpressionTest(String name) {
195 super(name);
196 }
197
198
199 public void testConstructor() throws Exception {
200 assertTrue(new ExpressionInfo("call(test.expression.Target.new())", NAMESPACE).getExpression().match(
201 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
202 assertFalse(new ExpressionInfo("call(test.expression.Target.new(String))", NAMESPACE).getExpression().match(
203 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
204
205 assertTrue(new ExpressionInfo("within(test.expression.Target) && execution(new())", NAMESPACE).getExpression().match(
206 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, null)));
207 assertTrue(new ExpressionInfo("within(test..*) && execution(*.expression.Target.new())", NAMESPACE).getExpression().match(
208 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, constructorNoArgPublic.getDeclaringType())));
209 assertTrue(new ExpressionInfo("within(test..*.*) && execution(*.expression.Target.new())", NAMESPACE).getExpression().match(
210 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, constructorNoArgPublic.getDeclaringType())));
211 }
212
213
214 public void testConstructorModifiers1() throws Exception {
215 assertTrue(new ExpressionInfo("call(public test.expression.Target.new())", NAMESPACE).getExpression().match(
216 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
217 assertFalse(new ExpressionInfo("call(private test.expression.Target.new())", NAMESPACE).getExpression().match(
218 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
219 }
220
221
222 public void testConstructorAnnotations1() throws Exception {
223 assertTrue(new ExpressionInfo("call(@Requires test.expression.Target.new())", NAMESPACE).getExpression().match(
224 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
225 assertFalse(new ExpressionInfo("call(@RequiresNew test.expression.Target.new())", NAMESPACE).getExpression()
226 .match(new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
227 assertTrue(new ExpressionInfo("execution(@Requires test.expression.Target.new())", NAMESPACE).getExpression().match(
228 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, null)));
229 assertFalse(new ExpressionInfo("execution(@RequiresNew test.expression.Target.new())", NAMESPACE).getExpression()
230 .match(new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, null)));
231 }
232
233 public void testConstructorAnnotations2() throws Exception {
234 assertTrue(new ExpressionInfo("execution(@Requires *..*.new(..))", NAMESPACE).getExpression().match(
235 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, null)));
236 assertFalse(new ExpressionInfo("execution(RequiresNew *..*.new(..))", NAMESPACE).getExpression().match(
237 new ExpressionContext(PointcutType.EXECUTION, constructorNoArgPublic, null)));
238 assertTrue(new ExpressionInfo("call(@Requires *..*.new(..))", NAMESPACE).getExpression().match(
239 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
240 assertFalse(new ExpressionInfo("call(RequiresNew *..*.new(..))", NAMESPACE).getExpression().match(
241 new ExpressionContext(PointcutType.CALL, constructorNoArgPublic, null)));
242 }
243
244
245 public void testMethodModifiers1() throws Exception {
246 assertFalse(new ExpressionInfo("call(public void test.expression.Target.modifiers1())", NAMESPACE)
247 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
248 assertTrue(new ExpressionInfo("call(void test.expression.Target.modifiers1())", NAMESPACE).getExpression()
249 .match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
250 assertFalse(new ExpressionInfo("call(static final void test.expression.Target.modifiers1())", NAMESPACE)
251 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
252 }
253
254 public void testMethodModifiers2() throws Exception {
255 assertTrue(new ExpressionInfo("call(public void test.expression.Target.modifiers2())", NAMESPACE)
256 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
257 assertTrue(new ExpressionInfo("call(void test.expression.Target.modifiers2())", NAMESPACE).getExpression()
258 .match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
259 assertFalse(new ExpressionInfo("call(static final void test.expression.Target.modifiers2())", NAMESPACE)
260 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
261 assertFalse(new ExpressionInfo("call(public static final void test.expression.Target.modifiers2())", NAMESPACE)
262 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
263 assertTrue(new ExpressionInfo("call(public static void test.expression.Target.modifiers2())", NAMESPACE)
264 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
265 }
266
267 public void testMethodModifiers3() throws Exception {
268 assertFalse(new ExpressionInfo("call(public void test.expression.Target.modifiers3())", NAMESPACE)
269 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
270 assertTrue(new ExpressionInfo("call(void test.expression.Target.modifiers3())", NAMESPACE).getExpression()
271 .match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
272 assertTrue(new ExpressionInfo("call(static final void test.expression.Target.modifiers3())", NAMESPACE)
273 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
274 assertFalse(new ExpressionInfo("call(public static native void test.expression.Target.modifiers3())", NAMESPACE)
275 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
276 assertFalse(new ExpressionInfo("call(public static void test.expression.Target.modifiers3())", NAMESPACE)
277 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
278 assertTrue(new ExpressionInfo("call(synchronized void test.expression.Target.modifiers3())", NAMESPACE)
279 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
280 assertTrue(new ExpressionInfo(
281 "call(protected native synchronized void test.expression.Target.modifiers3())",
282 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
283 assertTrue(new ExpressionInfo("call(native protected void test.expression.Target.modifiers3())", NAMESPACE)
284 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers3, null)));
285 }
286
287 public void testMethodModifiers4() throws Exception {
288 ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
289 assertFalse(new ExpressionInfo("call(public * test.expression.*.*(..)) && within(test.expression.*)", NAMESPACE)
290 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers4, s_declaringType)));
291 assertTrue(new ExpressionInfo("call(private * test.expression.*.*(..)) && within(test.expression.*)", NAMESPACE)
292 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers4, s_declaringType)));
293 assertFalse(new ExpressionInfo(
294 "call(protected * test.expression.*.*(..)) && within(test.expression.*)",
295 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers4, s_declaringType)));
296 assertFalse(new ExpressionInfo(
297 "call(protected * test.expression.*.*(..)) && within(test.expression.*)",
298 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers4, otherType)));
299 assertTrue(new ExpressionInfo(
300 "call(private * test.expression.*.*(..)) && within(java.lang.String)",
301 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers4, otherType)));
302 }
303
304 public void testMethodModifiers5() throws Exception {
305 assertFalse(new ExpressionInfo("call(!public void test.expression.Target.modifiers2())", NAMESPACE)
306 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
307 assertFalse(new ExpressionInfo("call(!public void test.expression.Target.modifiers2())", NAMESPACE)
308 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
309 assertTrue(new ExpressionInfo("call(!private void test.expression.Target.modifiers2())", NAMESPACE)
310 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
311 assertTrue(new ExpressionInfo("call(!private static void test.expression.Target.modifiers2())", NAMESPACE)
312 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
313 assertFalse(new ExpressionInfo("call(public !static void test.expression.Target.modifiers2())", NAMESPACE)
314 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
315 assertFalse(new ExpressionInfo("call(public !static void test.expression.Target.modifiers2())", NAMESPACE)
316 .getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers2, null)));
317 }
318
319
320 public void testMethodParameters1() throws Exception {
321 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters1())", NAMESPACE).getExpression()
322 .match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
323 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters1(..))", NAMESPACE).getExpression()
324 .match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
325 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters1(*))", NAMESPACE).getExpression()
326 .match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
327 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters1(int))", NAMESPACE).getExpression()
328 .match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
329 }
330
331 public void testMethodParameters2() throws Exception {
332 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2())", NAMESPACE).getExpression()
333 .match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
334 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..))", NAMESPACE).getExpression()
335 .match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
336 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(int, ..))", NAMESPACE)
337 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
338
339 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(int, float, byte, ..))", NAMESPACE)
340 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
341 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(.., int, float, byte, ..))", NAMESPACE)
342 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
343 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(.., int, float, byte))", NAMESPACE)
344 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
345 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(.., int, float, ..))", NAMESPACE)
346 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
347 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2bis(.., int, float, byte, ..))", NAMESPACE)
348 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
349
350
351 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(int, float, byte))", NAMESPACE)
352 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
353 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(int, *, *))", NAMESPACE)
354 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
355 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2(int, int, byte))", NAMESPACE)
356 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
357 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(*, *, byte))", NAMESPACE)
358 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
359 }
360
361 public void testMethodParameters3() throws Exception {
362 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters3())", NAMESPACE).getExpression()
363 .match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
364 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters3(..))", NAMESPACE).getExpression()
365 .match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
366 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters3(int, ..))", NAMESPACE)
367 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
368 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters3(String, ..))", NAMESPACE)
369 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
370 assertFalse(new ExpressionInfo(
371 "call(void test.expression.Target.parameters3(String, String, String))",
372 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
373 assertTrue(new ExpressionInfo(
374 "call(void test.expression.Target.parameters3(String, StringBuffer, String))",
375 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
376 assertFalse(new ExpressionInfo(
377 "call(void test.expression.Target.parameters3(String, StringBuffer, String, *))",
378 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
379 }
380
381 public void testMethodParameters4() throws Exception {
382 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters4())", NAMESPACE).getExpression()
383 .match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
384 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters4(..))", NAMESPACE).getExpression()
385 .match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
386 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters4(Object))", NAMESPACE)
387 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
388 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters4(Object[]))", NAMESPACE)
389 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
390 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters4(Object[][]))", NAMESPACE)
391 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
392 }
393
394 public void testMethodParameters5() throws Exception {
395 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters5())", NAMESPACE).getExpression()
396 .match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
397 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters5(..))", NAMESPACE).getExpression()
398 .match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
399 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters5(int))", NAMESPACE).getExpression()
400 .match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
401 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters5(int[]))", NAMESPACE)
402 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
403 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters5(int[][]))", NAMESPACE)
404 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
405 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters5(int[][][]))", NAMESPACE)
406 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
407 }
408
409
410 public void testMethodReturnType1() throws Exception {
411 assertTrue(new ExpressionInfo("call(void test.expression.Target.returnType1())", NAMESPACE).getExpression()
412 .match(new ExpressionContext(PointcutType.CALL, returnType1, null)));
413 assertFalse(new ExpressionInfo("call(String test.expression.Target.returnType1())", NAMESPACE).getExpression()
414 .match(new ExpressionContext(PointcutType.CALL, returnType1, null)));
415 assertTrue(new ExpressionInfo("call(* test.expression.Target.returnType1())", NAMESPACE).getExpression().match(
416 new ExpressionContext(PointcutType.CALL, returnType1, null)));
417 }
418
419 public void testMethodReturnType2() throws Exception {
420 assertFalse(new ExpressionInfo("call(void test.expression.Target.returnType2())", NAMESPACE).getExpression()
421 .match(new ExpressionContext(PointcutType.CALL, returnType2, null)));
422 assertFalse(new ExpressionInfo("call(String test.expression.Target.returnType2())", NAMESPACE).getExpression()
423 .match(new ExpressionContext(PointcutType.CALL, returnType2, null)));
424 assertTrue(new ExpressionInfo("call(* test.expression.Target.returnType2())", NAMESPACE).getExpression().match(
425 new ExpressionContext(PointcutType.CALL, returnType2, null)));
426 assertTrue(new ExpressionInfo("call(int test.expression.Target.returnType2())", NAMESPACE).getExpression()
427 .match(new ExpressionContext(PointcutType.CALL, returnType2, null)));
428 assertFalse(new ExpressionInfo("call(int[] test.expression.Target.returnType2())", NAMESPACE).getExpression()
429 .match(new ExpressionContext(PointcutType.CALL, returnType2, null)));
430 }
431
432 public void testMethodReturnType3() throws Exception {
433 assertFalse(new ExpressionInfo("call(void test.expression.Target.returnType3())", NAMESPACE).getExpression()
434 .match(new ExpressionContext(PointcutType.CALL, returnType3, null)));
435 assertTrue(new ExpressionInfo("call(String test.expression.Target.returnType3())", NAMESPACE).getExpression()
436 .match(new ExpressionContext(PointcutType.CALL, returnType3, null)));
437 assertTrue(new ExpressionInfo("call(* test.expression.Target.returnType3())", NAMESPACE).getExpression().match(
438 new ExpressionContext(PointcutType.CALL, returnType3, null)));
439 assertTrue(new ExpressionInfo("call(java.lang.String* test.expression.Target.returnType3())", NAMESPACE)
440 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType3, null)));
441 assertFalse(new ExpressionInfo("call(java.lang.StringBuffer test.expression.Target.returnType3())", NAMESPACE)
442 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType3, null)));
443 }
444
445 public void testMethodReturnType4() throws Exception {
446 assertFalse(new ExpressionInfo("call(void test.expression.Target.returnType4())", NAMESPACE).getExpression()
447 .match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
448 assertTrue(new ExpressionInfo("call(Process test.expression.Target.returnType4())", NAMESPACE).getExpression()
449 .match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
450 assertTrue(new ExpressionInfo("call(* test.expression.Target.returnType4())", NAMESPACE).getExpression().match(
451 new ExpressionContext(PointcutType.CALL, returnType4, null)));
452 assertTrue(new ExpressionInfo("call(java.lang.Process test.expression.Target.returnType4())", NAMESPACE)
453 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
454 assertTrue(new ExpressionInfo("call(java.lang.* test.expression.Target.returnType4())", NAMESPACE)
455 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
456 assertTrue(new ExpressionInfo("call(java..* test.expression.Target.returnType4())", NAMESPACE).getExpression()
457 .match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
458 assertTrue(new ExpressionInfo("call(java.*.Process test.expression.Target.returnType4())", NAMESPACE)
459 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType4, null)));
460 }
461
462 public void testMethodReturnType5() throws Exception {
463 assertFalse(new ExpressionInfo("call(void test.expression.Target.returnType5())", NAMESPACE).getExpression()
464 .match(new ExpressionContext(PointcutType.CALL, returnType5, null)));
465 assertFalse(new ExpressionInfo("call(float test.expression.Target.returnType5())", NAMESPACE).getExpression()
466 .match(new ExpressionContext(PointcutType.CALL, returnType5, null)));
467 assertFalse(new ExpressionInfo("call(float[] test.expression.Target.returnType5())", NAMESPACE).getExpression()
468 .match(new ExpressionContext(PointcutType.CALL, returnType5, null)));
469 assertTrue(new ExpressionInfo("call(float[][] test.expression.Target.returnType5())", NAMESPACE)
470 .getExpression().match(new ExpressionContext(PointcutType.CALL, returnType5, null)));
471 assertTrue(new ExpressionInfo("call(* test.expression.Target.returnType5())", NAMESPACE).getExpression().match(
472 new ExpressionContext(PointcutType.CALL, returnType5, null)));
473 }
474
475
476 public void testMethodName() throws Exception {
477 assertTrue(new ExpressionInfo("call(void test.expression.Target.__method$Name1())", NAMESPACE).getExpression()
478 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
479 assertTrue(new ExpressionInfo("call(void test.expression.Target.__method$*())", NAMESPACE).getExpression()
480 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
481 assertTrue(new ExpressionInfo("call(void test.expression.Target.*Name1())", NAMESPACE).getExpression().match(
482 new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
483 assertTrue(new ExpressionInfo("call(void test.expression.Target.*$*())", NAMESPACE).getExpression().match(
484 new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
485 assertTrue(new ExpressionInfo("call(void test.expression.*.__method$Name1())", NAMESPACE).getExpression()
486 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
487 assertTrue(new ExpressionInfo("call(void test..*.__method$Name1())", NAMESPACE).getExpression().match(
488 new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
489 assertTrue(new ExpressionInfo("call(void test..*.*())", NAMESPACE).getExpression().match(
490 new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
491 assertFalse(new ExpressionInfo("call(void test.expression.Target.__Method$Name1())", NAMESPACE).getExpression()
492 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
493 assertFalse(new ExpressionInfo("call(void test.expression.Target.__method$Name())", NAMESPACE).getExpression()
494 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
495 assertFalse(new ExpressionInfo("call(void test.expression.Target._methodName1())", NAMESPACE).getExpression()
496 .match(new ExpressionContext(PointcutType.CALL, _method$Name1, null)));
497 assertTrue(new ExpressionInfo("execution(* __method$Name1())", NAMESPACE).getExpression()
498 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, null)));
499 assertTrue(new ExpressionInfo("within(test.expression.Target) && execution(* __method$Name1())", NAMESPACE).getExpression()
500 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
501
502 assertTrue(new ExpressionInfo("within(test.expression.Target) && execution(* __method$Name1())", NAMESPACE).getExpression()
503 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
504 assertTrue(new ExpressionInfo("execution(* test.expression..*(..)) && execution(* *..Target.__method$Name1())", NAMESPACE).getExpression()
505 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
506 assertTrue(new ExpressionInfo("execution(* test.expression..*.*(..)) && execution(* *..Target.__method$Name1())", NAMESPACE).getExpression()
507 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
508 assertTrue(new ExpressionInfo("execution(* test..*(..)) && execution(* *.expression.Target.__method$Name1())", NAMESPACE).getExpression()
509 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
510 assertTrue(new ExpressionInfo("execution(* test..*.*(..)) && execution(* *.expression.Target.__method$Name1())", NAMESPACE).getExpression()
511 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
512
513 assertTrue(new ExpressionInfo("execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))", NAMESPACE).getExpression()
514 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
515 assertTrue(new ExpressionInfo("execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))", NAMESPACE).getAdvisedClassFilterExpression()
516 .match(new ExpressionContext(PointcutType.EXECUTION, _method$Name1, _method$Name1.getDeclaringType())));
517 assertFalse(new ExpressionInfo("execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))", NAMESPACE).getExpression()
518 .match(new ExpressionContext(PointcutType.EXECUTION, returnType1, returnType1.getDeclaringType())));
519 }
520
521
522 public void testMethodAttributes1() throws Exception {
523 assertTrue(new ExpressionInfo("call(void test.expression.Target.attributes1())", NAMESPACE).getExpression()
524 .match(new ExpressionContext(PointcutType.CALL, attributes1, null)));
525 assertTrue(new ExpressionInfo("call(@Requires void test.expression.Target.attributes1())", NAMESPACE)
526 .getExpression().match(new ExpressionContext(PointcutType.CALL, attributes1, null)));
527 assertFalse(new ExpressionInfo("call(@RequiresNew void test.expression.Target.attributes1())", NAMESPACE)
528 .getExpression().match(new ExpressionContext(PointcutType.CALL, attributes1, null)));
529 assertFalse(new ExpressionInfo(
530 "call(@Requires @RequiresNew void test.expression.Target.attributes1())",
531 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, attributes1, null)));
532 }
533
534
535 public void testFieldModifiers1() throws Exception {
536 assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier1)", NAMESPACE).getExpression().match(
537 new ExpressionContext(PointcutType.SET, modifier1, null)));
538 assertFalse(new ExpressionInfo("set(public int test.expression.Target.modifier1)", NAMESPACE).getExpression()
539 .match(new ExpressionContext(PointcutType.SET, modifier1, null)));
540 assertFalse(new ExpressionInfo("set(public int test.expression.Target.modifier1)", NAMESPACE).getExpression()
541 .match(new ExpressionContext(PointcutType.SET, modifier1, null)));
542 }
543
544 public void testFieldModifiers2() throws Exception {
545 assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier2)", NAMESPACE).getExpression().match(
546 new ExpressionContext(PointcutType.SET, modifier2, null)));
547 assertTrue(new ExpressionInfo("set(public int test.expression.Target.modifier2)", NAMESPACE).getExpression()
548 .match(new ExpressionContext(PointcutType.SET, modifier2, null)));
549 assertTrue(new ExpressionInfo("set(static public int test.expression.Target.modifier2)", NAMESPACE)
550 .getExpression().match(new ExpressionContext(PointcutType.SET, modifier2, null)));
551 assertTrue(new ExpressionInfo("set(static int test.expression.Target.modifier2)", NAMESPACE).getExpression()
552 .match(new ExpressionContext(PointcutType.SET, modifier2, null)));
553 assertFalse(new ExpressionInfo("set(protected int test.expression.Target.modifier2)", NAMESPACE)
554 .getExpression().match(new ExpressionContext(PointcutType.SET, modifier2, null)));
555 }
556
557 public void testFieldModifiers3() throws Exception {
558 assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier3)", NAMESPACE).getExpression().match(
559 new ExpressionContext(PointcutType.SET, modifier3, null)));
560 assertTrue(new ExpressionInfo("set(protected int test.expression.Target.modifier3)", NAMESPACE).getExpression()
561 .match(new ExpressionContext(PointcutType.SET, modifier3, null)));
562 assertTrue(new ExpressionInfo("set(static protected int test.expression.Target.modifier3)", NAMESPACE)
563 .getExpression().match(new ExpressionContext(PointcutType.SET, modifier3, null)));
564 assertTrue(new ExpressionInfo("set(static int test.expression.Target.modifier3)", NAMESPACE).getExpression()
565 .match(new ExpressionContext(PointcutType.SET, modifier3, null)));
566 assertTrue(new ExpressionInfo("set(transient int test.expression.Target.modifier3)", NAMESPACE).getExpression()
567 .match(new ExpressionContext(PointcutType.SET, modifier3, null)));
568 assertTrue(new ExpressionInfo(
569 "set(static transient protected final int test.expression.Target.modifier3)",
570 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier3, null)));
571 assertFalse(new ExpressionInfo("set(public int test.expression.Target.modifier3)", NAMESPACE).getExpression()
572 .match(new ExpressionContext(PointcutType.SET, modifier3, null)));
573 }
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592 public void testFieldType1() throws Exception {
593 assertTrue(new ExpressionInfo("set(int test.expression.Target.type1)", NAMESPACE).getExpression().match(
594 new ExpressionContext(PointcutType.SET, type1, null)));
595 assertTrue(new ExpressionInfo("set(* test.expression.Target.type1)", NAMESPACE).getExpression().match(
596 new ExpressionContext(PointcutType.SET, type1, null)));
597 assertFalse(new ExpressionInfo("set(Integer test.expression.Target.type1)", NAMESPACE).getExpression().match(
598 new ExpressionContext(PointcutType.SET, type1, null)));
599 assertFalse(new ExpressionInfo("set(int[] test.expression.Target.type1)", NAMESPACE).getExpression().match(
600 new ExpressionContext(PointcutType.SET, type1, null)));
601 }
602
603 public void testFieldType2() throws Exception {
604 assertFalse(new ExpressionInfo("set(int test.expression.Target.type2)", NAMESPACE).getExpression().match(
605 new ExpressionContext(PointcutType.SET, type2, null)));
606 assertTrue(new ExpressionInfo("set(* test.expression.Target.type2)", NAMESPACE).getExpression().match(
607 new ExpressionContext(PointcutType.SET, type2, null)));
608 assertFalse(new ExpressionInfo("set(Integer test.expression.Target.type2)", NAMESPACE).getExpression().match(
609 new ExpressionContext(PointcutType.SET, type2, null)));
610 assertFalse(new ExpressionInfo("set(int[] test.expression.Target.type2)", NAMESPACE).getExpression().match(
611 new ExpressionContext(PointcutType.SET, type2, null)));
612 assertTrue(new ExpressionInfo("set(int[][] test.expression.Target.type2)", NAMESPACE).getExpression().match(
613 new ExpressionContext(PointcutType.SET, type2, null)));
614 }
615
616 public void testFieldType3() throws Exception {
617 assertTrue(new ExpressionInfo("set(String test.expression.Target.type3)", NAMESPACE).getExpression().match(
618 new ExpressionContext(PointcutType.SET, type3, null)));
619 assertTrue(new ExpressionInfo("set(java.lang.String test.expression.Target.type3)", NAMESPACE).getExpression()
620 .match(new ExpressionContext(PointcutType.SET, type3, null)));
621 assertFalse(new ExpressionInfo("set(java.lang.string test.expression.Target.type3)", NAMESPACE).getExpression()
622 .match(new ExpressionContext(PointcutType.SET, type3, null)));
623 assertTrue(new ExpressionInfo("set(java..* test.expression.Target.type3)", NAMESPACE).getExpression().match(
624 new ExpressionContext(PointcutType.SET, type3, null)));
625 assertTrue(new ExpressionInfo("set(java.*.String test.expression.Target.type3)", NAMESPACE).getExpression()
626 .match(new ExpressionContext(PointcutType.SET, type3, null)));
627 assertTrue(new ExpressionInfo("set(java.lang.String* test.expression.Target.type3)", NAMESPACE).getExpression()
628 .match(new ExpressionContext(PointcutType.SET, type3, null)));
629 assertTrue(new ExpressionInfo("set(* test.expression.Target.type3)", NAMESPACE).getExpression().match(
630 new ExpressionContext(PointcutType.SET, type3, null)));
631 assertFalse(new ExpressionInfo("set(StringBuffer test.expression.Target.type3)", NAMESPACE).getExpression()
632 .match(new ExpressionContext(PointcutType.SET, type3, null)));
633 assertFalse(new ExpressionInfo("set(java.lang.StringBuffer test.expression.Target.type3)", NAMESPACE)
634 .getExpression().match(new ExpressionContext(PointcutType.SET, type3, null)));
635 assertFalse(new ExpressionInfo("set(String[] test.expression.Target.type3)", NAMESPACE).getExpression().match(
636 new ExpressionContext(PointcutType.SET, type3, null)));
637 assertFalse(new ExpressionInfo("set(java.lang.String[] test.expression.Target.type3)", NAMESPACE)
638 .getExpression().match(new ExpressionContext(PointcutType.SET, type3, null)));
639 }
640
641 public void testFieldType4() throws Exception {
642 assertFalse(new ExpressionInfo("set(String test.expression.Target.type4)", NAMESPACE).getExpression().match(
643 new ExpressionContext(PointcutType.SET, type4, null)));
644 assertFalse(new ExpressionInfo("set(java.lang.String test.expression.Target.type4)", NAMESPACE).getExpression()
645 .match(new ExpressionContext(PointcutType.SET, type4, null)));
646 assertTrue(new ExpressionInfo("set(String[] test.expression.Target.type4)", NAMESPACE).getExpression().match(
647 new ExpressionContext(PointcutType.SET, type4, null)));
648 assertTrue(new ExpressionInfo("set(java.lang.String[] test.expression.Target.type4)", NAMESPACE)
649 .getExpression().match(new ExpressionContext(PointcutType.SET, type4, null)));
650 assertTrue(new ExpressionInfo("set(* test.expression.Target.type4)", NAMESPACE).getExpression().match(
651 new ExpressionContext(PointcutType.SET, type4, null)));
652 assertFalse(new ExpressionInfo("set(String[][] test.expression.Target.type4)", NAMESPACE).getExpression()
653 .match(new ExpressionContext(PointcutType.SET, type4, null)));
654 assertFalse(new ExpressionInfo("set(int[] test.expression.Target.type4)", NAMESPACE).getExpression().match(
655 new ExpressionContext(PointcutType.SET, type4, null)));
656 }
657
658
659 public void testFieldName() throws Exception {
660 assertTrue(new ExpressionInfo("set(int test.expression.Target.__field$Name1)", NAMESPACE).getExpression()
661 .match(new ExpressionContext(PointcutType.SET, _field$Name1, null)));
662 assertFalse(new ExpressionInfo("set(int test.expression.Target.field$Name1)", NAMESPACE).getExpression().match(
663 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
664 assertTrue(new ExpressionInfo("set(int test.expression.Target.__*$Name*)", NAMESPACE).getExpression().match(
665 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
666 assertTrue(new ExpressionInfo("set(int test.expression.Target.__field*)", NAMESPACE).getExpression().match(
667 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
668 assertTrue(new ExpressionInfo("set(int test.expression.*.__field$Name1)", NAMESPACE).getExpression().match(
669 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
670 assertTrue(new ExpressionInfo("set(int test..Target.__field$Name1)", NAMESPACE).getExpression().match(
671 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
672 assertTrue(new ExpressionInfo("set(int test..*.__field$Name1)", NAMESPACE).getExpression().match(
673 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
674 assertFalse(new ExpressionInfo("set(int test..*.__fieldName1)", NAMESPACE).getExpression().match(
675 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
676
677 assertTrue(new ExpressionInfo("within(test.expression.Target) && set(int __field$Name1)", NAMESPACE).getExpression().match(
678 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
679 assertTrue(new ExpressionInfo("within(*.expression.Target) && set(int test..__field$Name1)", NAMESPACE).getExpression().match(
680 new ExpressionContext(PointcutType.SET, _field$Name1, null)));
681
682 }
683
684
685 public void testFieldAttributes1() throws Exception {
686 assertTrue(new ExpressionInfo("set(int test.expression.Target.attribute1)", NAMESPACE).getExpression().match(
687 new ExpressionContext(PointcutType.SET, attribute1, null)));
688 assertTrue(new ExpressionInfo("set(@ReadOnly int test.expression.Target.attribute1)", NAMESPACE)
689 .getExpression().match(new ExpressionContext(PointcutType.SET, attribute1, null)));
690 assertFalse(new ExpressionInfo("set(@Read int test.expression.Target.attribute1)", NAMESPACE).getExpression()
691 .match(new ExpressionContext(PointcutType.SET, attribute1, null)));
692 assertFalse(new ExpressionInfo("set(@ReadOnly @ReadWrite int test.expression.Target.attribute1)", NAMESPACE)
693 .getExpression().match(new ExpressionContext(PointcutType.SET, attribute1, null)));
694 }
695
696
697 public void testClassModifier() throws Exception {
698 assertTrue(new ExpressionInfo("within(test.expression.Target)", NAMESPACE).getExpression().match(
699 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
700 assertTrue(new ExpressionInfo("within(public test.expression.Target)", NAMESPACE).getExpression().match(
701 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
702 assertFalse(new ExpressionInfo("within(protected test.expression.Target)", NAMESPACE).getExpression().match(
703 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
704 assertTrue(new ExpressionInfo("within(final public test.expression.Target)", NAMESPACE).getExpression().match(
705 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
706
707
708
709
710
711
712 }
713
714
715 public void testClassType() throws Exception {
716 assertTrue(new ExpressionInfo("within(test.expression.Target)", NAMESPACE).getExpression().match(
717 new ExpressionContext(PointcutType.WITHIN, s_declaringType, s_declaringType)));
718 assertTrue(new ExpressionInfo("within(*)", NAMESPACE).getExpression().match(
719 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
720 assertTrue(new ExpressionInfo("within(..)", NAMESPACE).getExpression().match(
721 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
722 assertTrue(new ExpressionInfo("within(public *)", NAMESPACE).getExpression().match(
723 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
724 assertTrue(new ExpressionInfo("within(test.*.Target)", NAMESPACE).getExpression().match(
725 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
726 assertTrue(new ExpressionInfo("within(test.expression.*)", NAMESPACE).getExpression().match(
727 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
728 assertTrue(new ExpressionInfo("within(test.expression.Tar*)", NAMESPACE).getExpression().match(
729 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
730 assertTrue(new ExpressionInfo("within(test.expression.T*et)", NAMESPACE).getExpression().match(
731 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
732 assertTrue(new ExpressionInfo("within(test..*)", NAMESPACE).getExpression().match(
733 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
734 assertTrue(new ExpressionInfo("within(*.expression.*)", NAMESPACE).getExpression().match(
735 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
736 assertFalse(new ExpressionInfo("within(test.expression.target)", NAMESPACE).getExpression().match(
737 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
738 assertFalse(new ExpressionInfo("within(test.expression.Targett)", NAMESPACE).getExpression().match(
739 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
740 assertFalse(new ExpressionInfo("within(test.*.*.Target)", NAMESPACE).getExpression().match(
741 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
742 }
743
744 public void testClassTypeEarlyFiltering() throws Exception {
745 ExpressionNamespace.getNamespace(NAMESPACE).addExpressionInfo(
746 "pcWithinForCall", new ExpressionInfo("within(test.expression.Target)", NAMESPACE));
747 ExpressionInfo referenceToWithin = new ExpressionInfo("pcWithinForCall AND execution(* modifiers1(..))", NAMESPACE);
748 assertTrue(referenceToWithin.getAdvisedClassFilterExpression().match(
749 new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
750 ExpressionNamespace.getNamespace(NAMESPACE).addExpressionInfo(
751 "pcWithinForCall2", new ExpressionInfo("within(test.expression.TargetNOMATCH)", NAMESPACE));
752 ExpressionInfo referenceToWithin2 = new ExpressionInfo("pcWithinForCall2 AND execution(* modifiers1(..))", NAMESPACE);
753 assertFalse(referenceToWithin2.getAdvisedClassFilterExpression().match(
754 new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
755 }
756
757
758 public void testClassAttribute1() throws Exception {
759 assertTrue(new ExpressionInfo("within(test.expression.Target)", NAMESPACE).getExpression().match(
760 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
761 assertTrue(new ExpressionInfo("within(@Serializable test.expression.Target)", NAMESPACE).getExpression().match(
762 new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
763 assertTrue(new ExpressionInfo("within(@Serializable public final test.expression.Target)", NAMESPACE)
764 .getExpression().match(new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
765 assertFalse(new ExpressionInfo("within(@Serializable @Dummy test.expression.Target)", NAMESPACE)
766 .getExpression().match(new ExpressionContext(PointcutType.HANDLER, s_declaringType, s_declaringType)));
767 }
768
769
770 public void testClassAttribute2() throws Exception {
771 MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
772 assertTrue(new ExpressionInfo("execution(void test.expression.*.*(..)) AND within(@Serializable *..*)", NAMESPACE).getExpression().match(
773 new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
774 assertFalse(new ExpressionInfo("execution(void test.expression.*.*(..)) AND within(@FakeAnnotation *..*)", NAMESPACE).getExpression().match(
775 new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
776 }
777
778
779 public void testPointcutTypes() throws Exception {
780 MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
781 FieldInfo field = JavaFieldInfo.getFieldInfo(Target.class.getDeclaredField("modifier1"));
782 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE).getExpression()
783 .match(new ExpressionContext(PointcutType.EXECUTION, method, null)));
784 assertFalse(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE)
785 .getExpression().match(new ExpressionContext(PointcutType.CALL, method, null)));
786 assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier1)", NAMESPACE).getExpression().match(
787 new ExpressionContext(PointcutType.SET, field, null)));
788 assertFalse(new ExpressionInfo("get(int test.expression.Target.modifier1)", NAMESPACE).getExpression().match(
789 new ExpressionContext(PointcutType.SET, field, null)));
790 try {
791 assertFalse(new ExpressionInfo("set(int test.expression.Target.modifier1())", NAMESPACE).getExpression()
792 .match(new ExpressionContext(PointcutType.SET, method, null)));
793 } catch (Throwable e) {
794 return;
795 }
796 fail("expected exception");
797 }
798
799
800 public void testAdvisedClassExpression() throws Exception {
801 ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
802 assertFalse(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE)
803 .getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
804 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE)
805 .getAdvisedClassFilterExpression()
806 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
807 assertTrue(new ExpressionInfo("call(void test.expression.Target.modifiers1())", NAMESPACE)
808 .getAdvisedClassFilterExpression()
809 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
810 assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier1)", NAMESPACE)
811 .getAdvisedClassFilterExpression()
812 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
813 assertTrue(new ExpressionInfo("get(int test.expression.Target.modifier1)", NAMESPACE)
814 .getAdvisedClassFilterExpression()
815 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
816 assertTrue(new ExpressionInfo("handler(java.lang.Exception) && within(test.expression.Target)", NAMESPACE)
817 .getAdvisedClassFilterExpression()
818 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
819 assertTrue(new ExpressionInfo("handler(java.lang.Exception) && within(test.expression.Target)", NAMESPACE)
820 .getAdvisedClassFilterExpression()
821 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
822 assertTrue(new ExpressionInfo(
823 "handler(java.lang.Exception) && withincode(void test.expression.Target.modifiers1())",
824 NAMESPACE).getAdvisedClassFilterExpression().match(
825 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
826 assertTrue(new ExpressionInfo(
827 "handler(java.lang.Exception) && !withincode(void test.expression.Target.modifiers1())",
828 NAMESPACE).getAdvisedClassFilterExpression()
829 .match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
830 assertFalse(new ExpressionInfo(
831 "call(void test.expression.Dummy.modifiers1()) && within(test.expression.Target)",
832 NAMESPACE).getAdvisedClassFilterExpression().match(
833 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
834 assertFalse(new ExpressionInfo(
835 "call(void test.expression.Dummy.modifiers1()) && withincode(void test.expression.Target.modifiers1())",
836 NAMESPACE).getAdvisedClassFilterExpression().match(
837 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
838 assertFalse(new ExpressionInfo(
839 "call(void test.expression.Target.modifiers1()) && withincode(void test.expression.TargetNOMATCH.modifiers1())",
840 NAMESPACE).getAdvisedClassFilterExpression().match(
841 new ExpressionContext(PointcutType.WITHIN, s_declaringType, s_declaringType)));
842 assertTrue(new ExpressionInfo(
843 "execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
844 NAMESPACE).getAdvisedClassFilterExpression()
845 .match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
846
847 assertTrue(new ExpressionInfo(
848 "execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
849 NAMESPACE).getAdvisedClassFilterExpression().match(
850 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
851 assertTrue(new ExpressionInfo(
852 "execution(void test.expression.Target.modifiers1()) AND !execution(* java.lang.String.*(..))",
853 NAMESPACE).getAdvisedClassFilterExpression().match(
854 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
855
856
857 assertTrue(new ExpressionInfo(
858 "execution(void test.expression.Target.modifiers1()) AND cflow(execution(* *..*(..)))",
859 NAMESPACE).getAdvisedClassFilterExpression().match(
860 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
861 assertTrue(new ExpressionInfo(
862 "execution(void test.expression.Target.modifiers1()) AND !cflow(execution(* *..*(..)))",
863 NAMESPACE).getAdvisedClassFilterExpression().match(
864 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
865 assertFalse(new ExpressionInfo(
866 "execution(void test.expression.TargetNOMATCH.modifiers1()) AND cflow(execution(* *..*(..)))",
867 NAMESPACE).getAdvisedClassFilterExpression().match(
868 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
869 assertFalse(new ExpressionInfo(
870 "execution(void test.expression.TargetNOMATCH.modifiers1()) AND !cflow(execution(* *..*(..)))",
871 NAMESPACE).getAdvisedClassFilterExpression().match(
872 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
873
874
875
876 assertFalse(new ExpressionInfo(
877 "execution(void test.expression.Target.modifiers1()) OR !execution(* java.lang.String.*(..))",
878 NAMESPACE).getAdvisedClassFilterExpression().match(
879 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
880 assertFalse(new ExpressionInfo(
881 "execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
882 NAMESPACE).getAdvisedClassFilterExpression().match(
883 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
884 assertFalse(new ExpressionInfo(
885 "execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
886 NAMESPACE).getAdvisedClassFilterExpression().match(
887 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
888
889 assertTrue(new ExpressionInfo(
890 "!(execution(void test.expression.Target.modifiers1()) OR !execution(* java.lang.String.*(..)))",
891 NAMESPACE).getAdvisedClassFilterExpression()
892 .match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
893
894 }
895
896 public void testAdvisedCflowClassExpression() throws Exception {
897 ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
898 s_namespace.addExpressionInfo(
899 "string",
900 new ExpressionInfo("execution(void java.lang.String.*(..))",NAMESPACE));
901 s_namespace.addExpressionInfo(
902 "target",
903 new ExpressionInfo("execution(* test.expression.Target.*(..))",NAMESPACE));
904 s_namespace.addExpressionInfo(
905 "cflowString",
906 new ExpressionInfo("cflow(execution(void java.lang.String.*(..)))",NAMESPACE));
907 s_namespace.addExpressionInfo(
908 "cflowTarget",
909 new ExpressionInfo(
910 "cflow(call(void test.expression.Target.modifiers3()) && withincode(void test.expression.Target.*(..)))",
911 NAMESPACE));
912 assertFalse(new ExpressionInfo("string && cflowString", NAMESPACE)
913 .getAdvisedCflowClassFilterExpression()
914 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
915 assertTrue(new ExpressionInfo("string && cflowString", NAMESPACE)
916 .getAdvisedCflowClassFilterExpression().match(
917 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
918 assertFalse(new ExpressionInfo("target && cflowString", NAMESPACE).getAdvisedCflowClassFilterExpression()
919 .match(new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
920 assertTrue(new ExpressionInfo("target && cflowString", NAMESPACE)
921 .getAdvisedCflowClassFilterExpression().match(
922 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
923 assertTrue(new ExpressionInfo("! target && cflowString", NAMESPACE)
924 .getAdvisedCflowClassFilterExpression().match(
925 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
926
927 assertTrue(new ExpressionInfo("target && ! cflowString", NAMESPACE)
928 .getAdvisedCflowClassFilterExpression().match(
929 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
930 assertFalse(new ExpressionInfo("string && cflowTarget", NAMESPACE).getAdvisedCflowClassFilterExpression()
931 .match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
932 assertTrue(new ExpressionInfo("string && cflowTarget", NAMESPACE)
933 .getAdvisedCflowClassFilterExpression().match(
934 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
935 assertFalse(new ExpressionInfo("target && cflowTarget", NAMESPACE).getAdvisedCflowClassFilterExpression()
936 .match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
937 assertTrue(new ExpressionInfo("target && cflowTarget", NAMESPACE)
938 .getAdvisedCflowClassFilterExpression().match(
939 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
940 assertTrue(new ExpressionInfo(
941 "execution(void test.expression.Dummy.modifiers1()) && cflow(execution(void test.expression.Target.modifiers1()))",
942 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
943 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
944 assertFalse(new ExpressionInfo(
945 "execution(void test.expression.Dummy.modifiers1()) && cflow(execution(void test.expression.Target.modifiers1()))",
946 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
947 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
948 assertFalse(new ExpressionInfo("cflow(execution(void test.expression.Target.modifiers1()))", NAMESPACE)
949 .getAdvisedCflowClassFilterExpression().match(new ExpressionContext(PointcutType.WITHIN, otherType, null)));
950 assertTrue(new ExpressionInfo("cflow(call(void test.expression.Target.modifiers1()))", NAMESPACE)
951 .getAdvisedCflowClassFilterExpression().match(
952 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
953 assertTrue(new ExpressionInfo(
954 "cflow(execution(void test.expression.Target.modifiers1())) && within(test.expression.Target)",
955 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
956 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
957 assertTrue(new ExpressionInfo(
958 "within(test.expression.Target) && cflow(call(void test.expression.Target.modifiers1()))",
959 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
960 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
961 assertFalse(new ExpressionInfo(
962 "cflow(within(test.expression.T) && call(void test.expression.T.modifiers1()))",
963 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
964 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
965 assertTrue(new ExpressionInfo(
966 "cflow(!within(test.expression.T) && call(void test.expression.Target.modifiers1()))",
967 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
968 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
969 assertFalse(new ExpressionInfo(
970 "cflow(call(void test.expression.Target.modifiers1()) && !withincode(void test.expression.Target.modifiers1()))",
971 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
972 new ExpressionContext(PointcutType.WITHIN, otherType, null)));
973
974 assertTrue(new ExpressionInfo(
975 "!execution(void test.expression.Target.modifiers1()) && cflow(call(void test.expression.Target.modifiers1()))",
976 NAMESPACE).getAdvisedCflowClassFilterExpression().match(
977 new ExpressionContext(PointcutType.WITHIN, s_declaringType, null)));
978
979 }
980
981
982 public void testFindCflowPointcut() throws Exception {
983 MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
984 MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers2", new Class[] {}));
985 MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers3", new Class[] {}));
986 s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
987 "execution(void test.expression.Target.modifiers2())",
988 NAMESPACE));
989 s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
990 "execution(void test.expression.Target.modifiers3())",
991 NAMESPACE));
992 s_namespace.addExpressionInfo("cflowPC", new ExpressionInfo(
993 "cflow(call(void test.expression.Target.modifiers3()) AND within(test.expression.*))",
994 NAMESPACE));
995 assertTrue(new ExpressionInfo("cflow(execution(void test.expression.Target.modifiers1()))", NAMESPACE)
996 .getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
997 assertTrue(new ExpressionInfo(
998 "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
999 NAMESPACE).hasCflowPointcut());
1000 assertTrue(new ExpressionInfo(
1001 "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1002 NAMESPACE).hasCflowPointcut());
1003 assertTrue(new ExpressionInfo(
1004 "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1005 NAMESPACE).hasCflowPointcut());
1006 assertTrue(new ExpressionInfo("cflowPC && pc1", NAMESPACE).hasCflowPointcut());
1007 assertTrue(new ExpressionInfo("pc1 && cflowPC", NAMESPACE).hasCflowPointcut());
1008 assertTrue(new ExpressionInfo("cflow(pc2) && pc1", NAMESPACE).hasCflowPointcut());
1009 assertTrue(new ExpressionInfo("pc1 && cflow(pc2)", NAMESPACE).hasCflowPointcut());
1010 assertTrue(new ExpressionInfo(
1011 "pc2 && cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1012 NAMESPACE).hasCflowPointcut());
1013 assertTrue(new ExpressionInfo(
1014 "cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1())) AND pc1",
1015 NAMESPACE).hasCflowPointcut());
1016 assertTrue(new ExpressionInfo(
1017 "cflow(pc1 || call(void test.expression.Target.modifiers1())) && (execution(void test.expression.Target.modifiers3()) || pc1)",
1018 NAMESPACE).hasCflowPointcut());
1019 assertTrue(new ExpressionInfo(
1020 "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1021 NAMESPACE).hasCflowPointcut());
1022 assertTrue(new ExpressionInfo("cflow(pc1) && execution(void test.expression.Target.modifiers3())", NAMESPACE)
1023 .hasCflowPointcut());
1024 assertTrue(new ExpressionInfo(
1025 "cflow(call(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers1())",
1026 NAMESPACE).hasCflowPointcut());
1027 assertTrue(new ExpressionInfo(
1028 "cflow(call(void test.expression.Target.modifiers1())) || execution(void test.expression.Target.modifiers1())",
1029 NAMESPACE).hasCflowPointcut());
1030 assertFalse(new ExpressionInfo(
1031 "call(void test.expression.Target.modifiers1()) || execution(void test.expression.Target.modifiers1())",
1032 NAMESPACE).hasCflowPointcut());
1033 assertFalse(new ExpressionInfo(
1034 "call(void test.expression.Target.modifiers1()) && execution(void test.expression.Target.modifiers1())",
1035 NAMESPACE).hasCflowPointcut());
1036 }
1037
1038 public void testCflowTypes() throws Exception {
1039 MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
1040 MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers2", new Class[] {}));
1041 MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers3", new Class[] {}));
1042 s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1043 "execution(void test.expression.Target.modifiers2())",
1044 NAMESPACE));
1045 s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1046 "execution(void test.expression.Target.modifiers3())",
1047 NAMESPACE));
1048 s_namespace.addExpressionInfo("cflowPC", new ExpressionInfo(
1049 "cflow(call(void test.expression.Target.modifiers3()) AND within(test.expression.*))",
1050 NAMESPACE));
1051 assertTrue(new ExpressionInfo("cflow(execution(void test.expression.Target.modifiers1()))", NAMESPACE)
1052 .getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1053 assertTrue(new ExpressionInfo(
1054 "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1055 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1056 assertTrue(new ExpressionInfo(
1057 "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1058 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1059 assertTrue(new ExpressionInfo(
1060 "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1061 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1062 assertTrue(new ExpressionInfo("cflowPC && pc1", NAMESPACE).getCflowExpression().match(
1063 new ExpressionContext(PointcutType.CALL, method3, s_declaringType)));
1064 assertTrue(new ExpressionInfo("pc1 && cflowPC", NAMESPACE).getCflowExpression().match(
1065 new ExpressionContext(PointcutType.CALL, method3, s_declaringType)));
1066 assertTrue(new ExpressionInfo("cflow(pc2) && pc1", NAMESPACE).getCflowExpression().match(
1067 new ExpressionContext(PointcutType.EXECUTION, method3, s_declaringType)));
1068 assertFalse(new ExpressionInfo("pc1 && cflow(pc2)", NAMESPACE).getCflowExpression().match(
1069 new ExpressionContext(PointcutType.EXECUTION, method2, s_declaringType)));
1070 assertTrue(new ExpressionInfo(
1071 "pc2 && cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1072 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.CALL, method1, null)));
1073 assertTrue(new ExpressionInfo(
1074 "cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1())) AND pc1",
1075 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method3, null)));
1076 assertTrue(new ExpressionInfo(
1077 "cflow(pc1 || call(void test.expression.Target.modifiers1())) && (execution(void test.expression.Target.modifiers3()) || pc1)",
1078 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method2, null)));
1079 assertFalse(new ExpressionInfo(
1080 "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1081 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method2, null)));
1082 assertFalse(new ExpressionInfo("cflow(pc1) && execution(void test.expression.Target.modifiers3())", NAMESPACE)
1083 .getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method3, null)));
1084 assertFalse(new ExpressionInfo(
1085 "cflow(call(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers1())",
1086 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1087 assertFalse(new ExpressionInfo(
1088 "cflow(call(void test.expression.Target.modifiers1())) || execution(void test.expression.Target.modifiers1())",
1089 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1090 assertTrue(new ExpressionInfo(
1091 "execution(void test.expression.Target.modifiers2()) AND !cflow(call(void test.expression.Target.modifiers1()))",
1092 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method2, null)));
1093 assertTrue(new ExpressionInfo(
1094 "execution(void test.expression.Target.modifiers2()) AND !cflow(call(void test.expression.Target.modifiers1()))",
1095 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.CALL, method1, null)));
1096 }
1097
1098 public void testCflowBelowTypes() throws Exception {
1099 MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
1100 MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers2", new Class[] {}));
1101 MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers3", new Class[] {}));
1102 s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1103 "execution(void test.expression.Target.modifiers2())",
1104 NAMESPACE));
1105 s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1106 "execution(void test.expression.Target.modifiers3())",
1107 NAMESPACE));
1108 assertTrue(new ExpressionInfo("cflowbelow(execution(void test.expression.Target.modifiers1()))", NAMESPACE)
1109 .getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method1, null)));
1110 assertTrue(new ExpressionInfo(
1111 "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1112 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.CALL, method1, null)));
1113 assertTrue(new ExpressionInfo(
1114 "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1115 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method2, null)));
1116 assertTrue(new ExpressionInfo(
1117 "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1118 NAMESPACE).getCflowExpression().match(new ExpressionContext(PointcutType.EXECUTION, method3, null)));
1119 }
1120
1121
1122 public void tesHasMethod() throws Exception {
1123 ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
1124 ClassInfo string = JavaClassInfo.getClassInfo(String.class);
1125 assertTrue(new ExpressionInfo(
1126 "hasmethod(void modifiers1())",
1127 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1128 assertFalse(new ExpressionInfo(
1129 "hasmethod(void modifiers1())",
1130 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
1131
1132 assertTrue(new ExpressionInfo(
1133 "hasmethod(* getClass())",
1134 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1135
1136 assertFalse(new ExpressionInfo(
1137 "hasmethod(* getClass())",
1138 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1139
1140 assertFalse(new ExpressionInfo(
1141 "hasmethod(* java.lang.Object+.getClass())",
1142 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1143
1144 assertTrue(new ExpressionInfo(
1145 "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
1146 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1147
1148 assertFalse(new ExpressionInfo(
1149 "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
1150 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1151 }
1152
1153 public void tesHasField() throws Exception {
1154 ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
1155 ClassInfo string = JavaClassInfo.getClassInfo(String.class);
1156 assertTrue(new ExpressionInfo(
1157 "hasfield(int modifier1)",
1158 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1159 assertFalse(new ExpressionInfo(
1160 "hasfield(* modifier1)",
1161 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
1162
1163 assertTrue(new ExpressionInfo(
1164 "hasfield(* value)",
1165 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1166
1167 assertFalse(new ExpressionInfo(
1168 "hasfield(* value)",
1169 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
1170
1171 assertTrue(new ExpressionInfo(
1172 "hasfield(* value)",
1173 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
1174 }
1175
1176
1177 public void testWithinType1() throws Exception {
1178 ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
1179 MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
1180 assertTrue(new ExpressionInfo(
1181 "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
1182 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
1183 assertTrue(new ExpressionInfo(
1184 "call(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
1185 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1186 assertFalse(new ExpressionInfo(
1187 "call(void test.expression.Target.modifiers1()) AND !within(test.expression.Target)",
1188 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1189 assertTrue(new ExpressionInfo(
1190 "call(void test.expression.Target.modifiers1()) AND within(java.lang.String)",
1191 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, otherType)));
1192 assertFalse(new ExpressionInfo(
1193 "call(void test.expression.Target.modifiers1()) AND within(java.lang.String)",
1194 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1195 assertTrue(new ExpressionInfo(
1196 "call(void test.expression.Target.modifiers1()) AND !within(java.lang.String)",
1197 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1198
1199 assertTrue(new ExpressionInfo(
1200 "call(void test.expression.Target.NOMATCH()) AND within(java.lang.String)",
1201 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, otherType)));
1202 assertFalse(new ExpressionInfo(
1203 "call(void test.expression.Target.NOMATCH()) AND within(java.lang.String)",
1204 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1205 assertTrue(new ExpressionInfo(
1206 "call(void test.expression.Target.NOMATCH()) AND !within(java.lang.String)",
1207 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
1208 assertFalse(new ExpressionInfo(
1209 "call(void test.expression.NOMATCHTarget.NOMATCH()) AND within(java.lang.String)",
1210 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, otherType)));
1211 }
1212
1213 public void testWithinType2() throws Exception {
1214 ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
1215 MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
1216 assertTrue(new ExpressionInfo("execution(void *..*.modifiers1()) AND within(test.expression.Target)", NAMESPACE)
1217 .getAdvisedClassFilterExpression().match(
1218 new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
1219 assertTrue(new ExpressionInfo("execution(void *..*.modifiers1()) AND within(@Serializable *..*)", NAMESPACE)
1220 .getAdvisedClassFilterExpression().match(
1221 new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
1222 assertFalse(new ExpressionInfo(
1223 "execution(void *..*.modifiers1()) AND !within(@Serializable *..*)",
1224 NAMESPACE).getAdvisedClassFilterExpression().match(
1225 new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
1226 }
1227
1228 public void testWithinCodeType() throws Exception {
1229 MethodInfo stringtoStringMethod = JavaMethodInfo.getMethodInfo(String.class.getDeclaredMethod("toString", new Class[] {}));
1230 MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
1231 assertTrue(new ExpressionInfo(
1232 "execution(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
1233 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, method)));
1234 assertTrue(new ExpressionInfo(
1235 "call(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
1236 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
1237 assertFalse(new ExpressionInfo(
1238 "call(void test.expression.Target.modifiers1()) AND !withincode(void test.expression.Target.modifiers1())",
1239 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
1240 assertTrue(new ExpressionInfo(
1241 "execution(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.toString())",
1242 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, stringtoStringMethod)));
1243 assertFalse(new ExpressionInfo(
1244 "execution(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.toString())",
1245 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, method)));
1246
1247 assertTrue(new ExpressionInfo(
1248 "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.NOMATCHtoString())",
1249 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, stringtoStringMethod)));
1250 assertFalse(new ExpressionInfo(
1251 "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.NOMATCHtoString())",
1252 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
1253 assertFalse(new ExpressionInfo(
1254 "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.StringNOMATCH.*())",
1255 NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
1256
1257 }
1258
1259
1260 public void testPointcutReference() throws Exception {
1261 s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1262 "execution(void test.expression.Target.modifiers2())",
1263 NAMESPACE));
1264 s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1265 "execution(void test.expression.Target.modifiers3())",
1266 NAMESPACE));
1267 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1", NAMESPACE)
1268 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1269 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1", NAMESPACE)
1270 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1271 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2", NAMESPACE)
1272 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
1273 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2", NAMESPACE)
1274 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1275 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2", NAMESPACE)
1276 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1277 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2 ", NAMESPACE)
1278 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
1279 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1", NAMESPACE)
1280 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1281 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1", NAMESPACE)
1282 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1283 assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1 ", NAMESPACE)
1284 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
1285 assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
1286 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1287 assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
1288 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1289 assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
1290 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
1291 assertTrue(new ExpressionInfo(
1292 "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
1293 NAMESPACE).getExpression()
1294 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1295 assertTrue(new ExpressionInfo(
1296 "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
1297 NAMESPACE).getExpression()
1298 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, s_declaringType)));
1299 assertTrue(new ExpressionInfo(
1300 "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
1301 NAMESPACE).getExpression()
1302 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, s_declaringType)));
1303 assertTrue(new ExpressionInfo(
1304 "within(test.expression.Target) && (pc1 || pc2 || execution(void test.expression.Target.modifiers1()))",
1305 NAMESPACE).getExpression()
1306 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1307 assertTrue(new ExpressionInfo(
1308 "within(test.expression.Target) && (pc2 || pc1 || execution(void test.expression.Target.modifiers1()))",
1309 NAMESPACE).getExpression()
1310 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, s_declaringType)));
1311 assertTrue(new ExpressionInfo(
1312 "within(test.expression.Target) && (pc1 || execution(void test.expression.Target.modifiers1()) || pc2)",
1313 NAMESPACE).getExpression()
1314 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, s_declaringType)));
1315 }
1316
1317
1318 public void testPointcutReferenceOutsideScope() throws Exception {
1319 String namespace1 = "Lib";
1320 String namespace2 = "org.moneymaker.Util";
1321 ExpressionNamespace.getNamespace(namespace1).addExpressionInfo(
1322 "pc1",
1323 new ExpressionInfo("execution(void test.expression.Target.modifiers1())", namespace1));
1324 ExpressionNamespace.getNamespace(namespace2).addExpressionInfo(
1325 "pc2",
1326 new ExpressionInfo("execution(void test.expression.Target.modifiers2())", namespace2));
1327 assertTrue(new ExpressionInfo("execution(* foo.bar.*()) || Lib.pc1", NAMESPACE).getExpression().match(
1328 new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1329 assertTrue(new ExpressionInfo("Lib.pc1 || execution(* foo.bar.*())", NAMESPACE).getExpression().match(
1330 new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1331 assertTrue(new ExpressionInfo("org.moneymaker.Util.pc2 || Lib.pc1", NAMESPACE).getExpression().match(
1332 new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1333 assertTrue(new ExpressionInfo("Lib.pc1 || org.moneymaker.Util.pc2", NAMESPACE).getExpression().match(
1334 new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1335 assertFalse(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || Lib.pc1", NAMESPACE)
1336 .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
1337 }
1338
1339
1340 public void testAnd() throws Exception {
1341 assertTrue(new ExpressionInfo(
1342 "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
1343 NAMESPACE).getExpression()
1344 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1345 assertFalse(new ExpressionInfo(
1346 "execution(void test.expression.Target.modifiers1()) AND call(void test.expression.Target.modifiers1())",
1347 NAMESPACE).getExpression()
1348 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1349 assertFalse(new ExpressionInfo(
1350 "call(void test.expression.Target.modifiers1()) AND set(int test.expression.Target.modifier1)",
1351 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
1352 assertTrue(new ExpressionInfo(
1353 "execution(void test.expression.Target.modifiers1()) && within(test.expression.Target)",
1354 NAMESPACE).getExpression()
1355 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1356 assertFalse(new ExpressionInfo(
1357 "execution(void test.expression.Target.modifiers1()) && call(void test.expression.Target.modifiers1())",
1358 NAMESPACE).getExpression()
1359 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1360 assertFalse(new ExpressionInfo(
1361 "call(void test.expression.Target.modifiers1()) && set(int test.expression.Target.modifier1)",
1362 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
1363 }
1364
1365
1366 public void testOr() throws Exception {
1367 assertTrue(new ExpressionInfo(
1368 "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
1369 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1370 assertTrue(new ExpressionInfo(
1371 "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
1372 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
1373 assertTrue(new ExpressionInfo(
1374 "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifiers)",
1375 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
1376 assertTrue(new ExpressionInfo(
1377 "set(int test.expression.Target.modifier1) OR call(void test.expression.Target.modifiers1())",
1378 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
1379 assertTrue(new ExpressionInfo(
1380 "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifier1)",
1381 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
1382 assertTrue(new ExpressionInfo(
1383 "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
1384 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
1385 assertTrue(new ExpressionInfo(
1386 "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
1387 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
1388 assertTrue(new ExpressionInfo(
1389 "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
1390 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
1391 assertTrue(new ExpressionInfo(
1392 "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
1393 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
1394 }
1395
1396
1397 public void testNot() throws Exception {
1398 assertFalse(new ExpressionInfo(
1399 "execution(void test.expression.Target.modifiers1()) AND !within(test.expression.Target)",
1400 NAMESPACE).getExpression()
1401 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1402 assertTrue(new ExpressionInfo(
1403 "execution(void test.expression.Target.modifiers1()) AND !call(void test.expression.Target.modifiers1())",
1404 NAMESPACE).getExpression()
1405 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1406 assertFalse(new ExpressionInfo(
1407 "call(void test.expression.Target.modifiers1()) AND !set(int test.expression.Target.modifier1)",
1408 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
1409 assertFalse(new ExpressionInfo(
1410 "execution(void test.expression.Target.modifiers1()) && !within(test.expression.Target)",
1411 NAMESPACE).getExpression()
1412 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1413 assertTrue(new ExpressionInfo(
1414 "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers1())",
1415 NAMESPACE).getExpression()
1416 .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1417 ExpressionVisitor expression = new ExpressionInfo(
1418 "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers3()) && !(call(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers2()))",
1419 NAMESPACE).getExpression();
1420 assertTrue(expression.match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
1421 assertFalse(expression.match(new ExpressionContext(PointcutType.CALL, modifiers1, s_declaringType)));
1422 assertFalse(expression.match(new ExpressionContext(PointcutType.SET, modifier1, s_declaringType)));
1423 assertFalse(new ExpressionInfo(
1424 "call(void test.expression.Target.modifiers1()) && !set(int test.expression.Target.modifier1)",
1425 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
1426 }
1427
1428 public void testGrammar() throws Throwable {
1429
1430 new ExpressionInfo("args(..)", NAMESPACE);
1431 new ExpressionInfo("args(foo, java, String[], foo, ..)", NAMESPACE);
1432 new ExpressionInfo("args(foo, String+)", NAMESPACE);
1433 new ExpressionInfo("args(.., String+)", NAMESPACE);
1434 new ExpressionInfo("args(java.lang.String, ..)", NAMESPACE);
1435 new ExpressionInfo("args(.., String+, ..)", NAMESPACE);
1436 }
1437
1438
1439 public void testMethodArgs1() throws Exception {
1440 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters1(..)) && args(..)", NAMESPACE)
1441 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
1442 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters1(..)) && args()", NAMESPACE)
1443 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
1444 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters1(..)) && args(int)", NAMESPACE)
1445 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
1446 assertFalse(new ExpressionInfo(
1447 "execution(void test.expression.Target.parameters1(..)) && args(.., int)",
1448 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
1449 assertFalse(new ExpressionInfo(
1450 "execution(void test.expression.Target.parameters1(..)) && args(.., int)",
1451 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters1, null)));
1452 }
1453
1454 public void testMethodArgs2() throws Exception {
1455 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(..)", NAMESPACE)
1456 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1457 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args()", NAMESPACE)
1458 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1459 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(int)", NAMESPACE)
1460 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1461 assertTrue(new ExpressionInfo(
1462 "call(void test.expression.Target.parameters2(..)) && args(int, float, byte)",
1463 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1464 assertTrue(new ExpressionInfo(
1465 "call(void test.expression.Target.parameters2(..)) && args(.., float, byte)",
1466 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1467 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(.., byte)", NAMESPACE)
1468 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1469 assertTrue(new ExpressionInfo(
1470 "call(void test.expression.Target.parameters2(..)) && args(int, float, ..)",
1471 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1472 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(int, ..)", NAMESPACE)
1473 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1474
1475
1476 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(int, float, byte, ..)", NAMESPACE)
1477 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1478 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(.., int, float, byte, ..)", NAMESPACE)
1479 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1480 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(.., int, float, byte)", NAMESPACE)
1481 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1482
1483
1484 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2bis(..)) && args(int, float, byte, ..)", NAMESPACE)
1485 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
1486 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, byte, ..)", NAMESPACE)
1487 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
1488 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, byte)", NAMESPACE)
1489 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
1490 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, ..)", NAMESPACE)
1491 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
1492 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, a, b, c, d, e, f, g, h, i,..)", NAMESPACE)
1493 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2bis, null)));
1494
1495 assertFalse(new ExpressionInfo(
1496 "call(void test.expression.Target.parameters2(..)) && args(WRONG, ..)",
1497 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1498 assertFalse(new ExpressionInfo(
1499 "call(void test.expression.Target.parameters2(..)) && args(.., WRONG)",
1500 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1501 assertFalse(new ExpressionInfo(
1502 "call(void test.expression.Target.parameters2(..)) && args(int, float, WRONG)",
1503 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1504 assertFalse(new ExpressionInfo(
1505 "call(void test.expression.Target.parameters2(..)) && args(int, float, byte, WRONG)",
1506 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1507 }
1508
1509 public void testMethodArgs3() throws Exception {
1510 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters3())", NAMESPACE).getExpression()
1511 .match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1512 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters3(..))", NAMESPACE).getExpression()
1513 .match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1514 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters3(int, ..))", NAMESPACE)
1515 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1516 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters3(String, ..))", NAMESPACE)
1517 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1518 assertFalse(new ExpressionInfo(
1519 "call(void test.expression.Target.parameters3(String, String, String))",
1520 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1521 assertTrue(new ExpressionInfo(
1522 "call(void test.expression.Target.parameters3(String, StringBuffer, String))",
1523 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1524 assertTrue(new ExpressionInfo(
1525 "call(void test.expression.Target.parameters3(String, java.io.Serializable+, String))",
1526 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1527 assertFalse(new ExpressionInfo(
1528 "call(void test.expression.Target.parameters3(String, StringBuffer, String, *))",
1529 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters3, null)));
1530 }
1531
1532 public void testMethodArgs4() throws Exception {
1533 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters4(..)) && args(..)", NAMESPACE)
1534 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
1535 assertTrue(new ExpressionInfo(
1536 "call(void test.expression.Target.parameters4(..)) && args(java.lang.Object[])",
1537 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
1538
1539 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters4(..)) && args(Object[])", NAMESPACE)
1540 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
1541 assertFalse(new ExpressionInfo(
1542 "call(void test.expression.Target.parameters4(..)) && args(java.lang.Object[][])",
1543 NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, parameters4, null)));
1544 }
1545
1546 public void testMethodArgs5() throws Exception {
1547 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters5(..)) && args(..)", NAMESPACE)
1548 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
1549 assertTrue(new ExpressionInfo("call(void test.expression.Target.parameters5(..)) && args(int[][])", NAMESPACE)
1550 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
1551 assertFalse(new ExpressionInfo("call(void test.expression.Target.parameters5(..)) && args(int[])", NAMESPACE)
1552 .getExpression().match(new ExpressionContext(PointcutType.CALL, parameters5, null)));
1553 }
1554
1555 public void testMethodArgsBinding() throws Exception {
1556 ExpressionInfo info = null;
1557
1558 info = new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(i, f, b)", NAMESPACE);
1559 info.addArgument("i", "int");
1560 info.addArgument("f", "float");
1561 info.addArgument("b", "byte");
1562 assertTrue(info.getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1563
1564 info = new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(i, f, byte)", NAMESPACE);
1565 info.addArgument("i", "int");
1566 info.addArgument("f", "float");
1567 assertTrue(info.getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1568
1569 info = new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(i, f, b)", NAMESPACE);
1570 info.addArgument("i", "int");
1571 info.addArgument("f", "WRONG");
1572
1573 assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
1574 }
1575
1576 public void testAnnotationFQN() {
1577
1578 ExpressionInfo info = new ExpressionInfo("within(@examples.annotation.AnnotationA *)", NAMESPACE);
1579 info = new ExpressionInfo("within(@examples.annotation.Annotation$A *)", NAMESPACE);
1580
1581
1582 info = new ExpressionInfo("execution(@examples.annotation.AnnotationA * examples.annotation.Target.*(..))", NAMESPACE);
1583 info = new ExpressionInfo("execution(@examples.annotation.Annotation$A * examples.annotation.Target.*(..))", NAMESPACE);
1584
1585
1586 info = new ExpressionInfo("set(@examples.annotation.AnnotationA * Class.field)", NAMESPACE);
1587 }
1588
1589 public void testWithinCtor() {
1590 ExpressionInfo info = null;
1591
1592 info = new ExpressionInfo(
1593 "withincode(test.expression.Target.new())",
1594 NAMESPACE
1595 );
1596
1597 info = new ExpressionInfo(
1598 "execution(* test.expression.Target.*(..)) && withincode(test.expression.Target.new())",
1599 NAMESPACE
1600 );
1601 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1602 assertTrue(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1603
1604 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1605 assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1606
1607 info = new ExpressionInfo(
1608 "execution(* test.expression.Target.*(..)) && withincode(test.expression.Target.new(int))",
1609 NAMESPACE
1610 );
1611 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1612 assertTrue(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1613
1614 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1615 assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1616
1617 info = new ExpressionInfo(
1618 "execution(* test.expression.Target.*(..)) && withincode(private test.expression.Target.new())",
1619 NAMESPACE
1620 );
1621 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1622 assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorIntArgPrivate)));
1623 assertTrue(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1624 assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, constructorNoArgPublic)));
1625
1626
1627 info = new ExpressionInfo(
1628 "execution(* test.expression.Target.*(..)) && withincode(test.expressionWRONG.Target.new())",
1629 NAMESPACE
1630 );
1631 assertFalse(info.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifier1, constructorNoArgPublic)));
1632 }
1633
1634
1635
1636 public static void main(String[] args) {
1637 junit.textui.TestRunner.run(suite());
1638 }
1639
1640 public static junit.framework.Test suite() {
1641 return new junit.framework.TestSuite(ExpressionTest.class);
1642 }
1643 }