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