1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
|
/*******************************************************************************
* Copyright (c) 2008 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*
* Contributors:
* Andy Clement
*******************************************************************************/
package org.aspectj.matcher.tools;
import org.aspectj.weaver.ResolvedMember;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
import org.aspectj.weaver.tools.ShadowMatch;
import org.aspectj.weaver.tools.StandardPointcutExpression;
import org.aspectj.weaver.tools.StandardPointcutParser;
import junit.framework.TestCase;
/**
* Test the use of the pointcut parser and matching infrastructure. The org.aspectj.matcher.tools infrastructure used should not be
* aware of what kind of World it is working with and only operate in terms of the type abstraction expressed in the
* org.aspectj.matcher project (so Members, etc). These tests only use base java types, there is no other testdata.
*
* This is based on the Reflection oriented PointcutExpressionTest in the weaver project.
*
* @author Andy Clement
*/
public abstract class CommonPointcutExpressionTests extends TestCase {
private World world;
private StandardPointcutParser pointcutParser;
protected abstract World getWorld();
protected void setUp() throws Exception {
super.setUp();
world = getWorld();
pointcutParser = StandardPointcutParser.getPointcutParserSupportingAllPrimitives(world);
}
// -- some very basic stuff, if these don't pass it isn't worth continuing
public void testResolvingOneType() {
// do it via name
ResolvedType type = world.resolve("java.lang.String");
assertNotNull(type);
// do it via signature
type = world.resolve(UnresolvedType.forSignature("Ljava/lang/String;"));
assertNotNull(type);
}
public void testResolveTypeAndRetrieveMethod() {
ResolvedType type = world.resolve("java.lang.String");
assertNotNull(type);
ResolvedMember method = getMethod(type, "valueOf", "(Z)Ljava/lang/String;"); // grab the method 'String valueOf()'
assertNotNull(method);
}
// -- next few tests relate to matching different pointcut expressions against a method-execution join point
public void testMethodExecutionMatching01() {
checkAlwaysMatches("execution(String valueOf(boolean))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
}
public void testMethodExecutionMatching02() {
checkAlwaysMatches("execution(* *val*(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkAlwaysMatches("execution(String *(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkAlwaysMatches("execution(* *(boolean))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkAlwaysMatches("execution(* j*..*.valueOf(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkAlwaysMatches("execution(* *(*))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkNeverMatches("execution(* vulueOf(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkNeverMatches("execution(int *(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkNeverMatches("execution(* valueOf(String))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
checkNeverMatches("execution(private * valueOf(..))", "java.lang.String", "valueOf", "(Z)Ljava/lang/String;");
}
public void testMethodExecutionMatching03() {
checkAlwaysMatches("execution(* *())", "java.util.List", "toArray", "()[Ljava/lang/Object;");
checkAlwaysMatches("execution(*[] *())", "java.util.List", "toArray", "()[Ljava/lang/Object;");
checkAlwaysMatches("execution(*b*[] *())", "java.util.List", "toArray", "()[Ljava/lang/Object;");
}
public void testConstructorExecutionMatching01() {
checkAlwaysMatches("execution(new())", "java.lang.String", "<init>", "()V");
}
public void testConstructorExecutionMatching02() {
checkAlwaysMatches("execution(new(char[]))", "java.lang.String", "<init>", "([C)V");
checkAlwaysMatches("execution(new(..))", "java.lang.String", "<init>", "()V");
checkAlwaysMatches("execution(new(..))", "java.lang.String", "<init>", "(Ljava/lang/String;)V");
checkAlwaysMatches("execution(new(*))", "java.lang.String", "<init>", "(Ljava/lang/String;)V");
checkNeverMatches("execution(new(*))", "java.lang.String", "<init>", "()V");
checkAlwaysMatches("execution(new(*,*,*))", "java.lang.String", "<init>", "([CII)V");
checkAlwaysMatches("execution(new(*,int,*))", "java.lang.String", "<init>", "([III)V");
checkNeverMatches("execution(new(..,int[]))", "java.lang.String", "<init>", "([III)V");
}
public void testConstructorExecutionMatching03() {
ResolvedType jlArrayList = world.resolve("java.util.ArrayList");
ResolvedType juList = world.resolve("java.util.List");
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("execution(java.util.ArrayList.new(..))");
assertNotNull(ex);
// simple constructor
ShadowMatch shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
ex = pointcutParser.parsePointcutExpression("execution(ArrayList.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
ex = pointcutParser.parsePointcutExpression("execution(*Arr*.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
ex = pointcutParser.parsePointcutExpression("execution(java.util.*.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
ex = pointcutParser.parsePointcutExpression("execution(java.*.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.neverMatches());
ex = pointcutParser.parsePointcutExpression("execution(java..*.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
ex = pointcutParser.parsePointcutExpression("execution(*..ArrayList.new(..))");
shadowMatch = ex.matchesMethodExecution(getMethod(jlArrayList, "<init>", "()V"));
assertTrue(shadowMatch.alwaysMatches());
}
public void testMatchingThis01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("this(java.lang.String)");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
// regular method
ShadowMatch shadowMatch = ex.matchesMethodExecution(getMethod(jlString, "toLowerCase", "()Ljava/lang/String;"));
assertTrue(shadowMatch.alwaysMatches());
// static method
shadowMatch = ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;"));
assertTrue(shadowMatch.neverMatches());
// maybe match: this could be an ArrayList when clear() is called
ex = pointcutParser.parsePointcutExpression("this(java.util.ArrayList)");
shadowMatch = ex.matchesMethodExecution(getMethod(juList, "clear", "()V"));
assertTrue(shadowMatch.maybeMatches());
assertFalse(shadowMatch.neverMatches());
assertFalse(shadowMatch.alwaysMatches());
}
public void testMatchingTarget01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("target(java.lang.String)");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
// regular method
ShadowMatch shadowMatch = ex.matchesMethodExecution(getMethod(jlString, "toLowerCase", "()Ljava/lang/String;"));
assertTrue(shadowMatch.alwaysMatches());
// static method
shadowMatch = ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;"));
assertTrue(shadowMatch.neverMatches());
// maybe match: target could be an ArrayList when clear() is called
ex = pointcutParser.parsePointcutExpression("target(java.util.ArrayList)");
shadowMatch = ex.matchesMethodExecution(getMethod(juList, "clear", "()V"));
assertTrue(shadowMatch.maybeMatches());
assertFalse(shadowMatch.neverMatches());
assertFalse(shadowMatch.alwaysMatches());
}
public void testMatchingArgs01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("args(..,int)");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
ResolvedMember stringValueOfLongMethod = getMethod(jlString, "valueOf", "(J)Ljava/lang/String;");
ShadowMatch shadowMatch = ex.matchesMethodExecution(stringSplitMethod);
assertTrue(shadowMatch.alwaysMatches());
shadowMatch = ex.matchesMethodExecution(stringValueOfIntMethod);
assertTrue(shadowMatch.alwaysMatches());
shadowMatch = ex.matchesMethodExecution(stringValueOfLongMethod);
assertTrue(shadowMatch.neverMatches());
// at List.add(Object) the Object might be a String
ex = pointcutParser.parsePointcutExpression("args(java.lang.String)");
shadowMatch = ex.matchesMethodExecution(getMethod(juList, "add", "(Ljava/lang/Object;)Z"));
assertTrue(shadowMatch.maybeMatches());
}
public void testMatchingWithin01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("within(java.lang.String)");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
assertTrue(ex.matchesMethodExecution(stringSplitMethod).alwaysMatches());
assertTrue(ex.matchesMethodExecution(stringValueOfIntMethod).alwaysMatches());
assertTrue(ex.matchesMethodExecution(listAddMethod).neverMatches());
}
public void testMatchingWithinCode01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("withincode(* *..String.*(..))");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
assertTrue(ex.matchesMethodExecution(stringSplitMethod).neverMatches());
assertTrue(ex.matchesMethodExecution(stringValueOfIntMethod).neverMatches());
assertTrue(ex.matchesMethodExecution(listAddMethod).neverMatches());
}
// -- next few tests relate to matching different pointcut expressions against a method-call join point
public void testCallMatchesMethodCall() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("call(* *..String.*(..))");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
// call from list to string, should be OK
assertTrue(ex.matchesMethodCall(stringSplitMethod, listAddMethod).alwaysMatches());
assertTrue(ex.matchesMethodCall(stringValueOfIntMethod, listAddMethod).alwaysMatches());
assertTrue(ex.matchesMethodCall(listAddMethod, stringSplitMethod).neverMatches());
ex = pointcutParser.parsePointcutExpression("call(* *..ArrayList.*(..))");
assertTrue(ex.matchesMethodCall(listAddMethod, stringSplitMethod).neverMatches());
}
public void testCall() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("call(* *..A.a*(..))");
// assertTrue("Should match call to A.a()", ex.matchesMethodCall(a, a).alwaysMatches());
// assertTrue("Should match call to A.aaa()", ex.matchesMethodCall(aaa, a).alwaysMatches());
// assertTrue("Should match call to B.aa()", ex.matchesMethodCall(bsaa, a).alwaysMatches());
// assertTrue("Should not match call to B.b()", ex.matchesMethodCall(b, a).neverMatches());
// ex = p.parsePointcutExpression("call(* *..A.a*(int))");
// assertTrue("Should match call to A.aa()", ex.matchesMethodCall(aa, a).alwaysMatches());
// assertTrue("Should not match call to A.a()", ex.matchesMethodCall(a, a).neverMatches());
// ex = p.parsePointcutExpression("call(void aaa(..)) && this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match call to A.aaa() from Client", ex.matchesMethodCall(aaa, foo).alwaysMatches());
// ex = p.parsePointcutExpression("call(void aaa(..)) && this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Should match call to A.aaa() from B", ex.matchesMethodCall(aaa, b).alwaysMatches());
// assertTrue("May match call to A.aaa() from A", ex.matchesMethodCall(aaa, a).maybeMatches());
// assertFalse("May match call to A.aaa() from A", ex.matchesMethodCall(aaa, a).alwaysMatches());
// ex = p.parsePointcutExpression("execution(* *.*(..))");
// assertTrue("Should not match call to A.aa", ex.matchesMethodCall(aa, a).neverMatches());
}
public void testCallAndThisMatchesMethodCall() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("call(* *(..)) && this(java.util.ArrayList)");
ResolvedType jlString = world.resolve("java.lang.String");
ResolvedType juList = world.resolve("java.util.List");
ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
// Calling from list.add() to string split, the callee *might* be an ArrayList, so possible match
assertTrue(ex.matchesMethodCall(stringSplitMethod, listAddMethod).maybeMatches());
}
// // this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesMethodCall(a, foo).alwaysMatches());
// assertTrue("Should not match A", ex.matchesMethodCall(a, a).neverMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Should maybe match B", ex.matchesMethodCall(bsaa, a).maybeMatches());
// assertFalse("Should maybe match B", ex.matchesMethodCall(bsaa, a).alwaysMatches());
// // target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should not match Client", ex.matchesMethodCall(a, a).neverMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should match A", ex.matchesMethodCall(a, a).alwaysMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Should maybe match A", ex.matchesMethodCall(aa, a).maybeMatches());
// assertFalse("Should maybe match A", ex.matchesMethodCall(aa, a).alwaysMatches());
// // test args
// ex = p.parsePointcutExpression("args(..,int)");
// assertTrue("Should match A.aa", ex.matchesMethodCall(aa, a).alwaysMatches());
// assertTrue("Should match A.aaa", ex.matchesMethodCall(aaa, a).alwaysMatches());
// assertTrue("Should not match A.a", ex.matchesMethodCall(a, a).neverMatches());
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesMethodCall(a, a).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesMethodCall(a, b).neverMatches());
// assertTrue("Matches in class A", ex.matchesMethodCall(a, A.class).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesMethodCall(a, B.class).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Should match", ex.matchesMethodCall(b, bsaa).alwaysMatches());
// assertTrue("Should not match", ex.matchesMethodCall(b, b).neverMatches());
// }
// public void testMatchesConstructorCall() {
// PointcutExpression ex = p.parsePointcutExpression("call(new(String))");
// assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons, b).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesConstructorCall(bsStringCons, b).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesConstructorCall(bsCons, foo).neverMatches());
// ex = p.parsePointcutExpression("call(*..A.new(String))");
// assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons, b).alwaysMatches());
// assertTrue("Should not match B(String)", ex.matchesConstructorCall(bsStringCons, foo).neverMatches());
// // this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesConstructorCall(asCons, foo).alwaysMatches());
// assertTrue("Should not match A", ex.matchesConstructorCall(asCons, a).neverMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Should maybe match B", ex.matchesConstructorCall(asCons, a).maybeMatches());
// assertFalse("Should maybe match B", ex.matchesConstructorCall(asCons, a).alwaysMatches());
// // target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should not match Client", ex.matchesConstructorCall(asCons, foo).neverMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should not match A (no target)", ex.matchesConstructorCall(asCons, a).neverMatches());
// // args
// ex = p.parsePointcutExpression("args(String)");
// assertTrue("Should match A(String)", ex.matchesConstructorCall(asCons, b).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesConstructorCall(bsStringCons, foo).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesConstructorCall(bsCons, foo).neverMatches());
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesConstructorCall(asCons, a).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesConstructorCall(asCons, b).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Should match", ex.matchesConstructorCall(bsCons, aa).alwaysMatches());
// assertTrue("Should not match", ex.matchesConstructorCall(bsCons, b).neverMatches());
// }
//
//
// // test this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should match A", ex.matchesConstructorExecution(asCons).alwaysMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesConstructorExecution(asCons).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesConstructorExecution(asCons).alwaysMatches());
// assertTrue("Should match B", ex.matchesConstructorExecution(bsCons).alwaysMatches());
// assertTrue("Does not match client", ex.matchesConstructorExecution(clientCons).neverMatches());
//
// // test target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should match A", ex.matchesConstructorExecution(asCons).alwaysMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesConstructorExecution(asCons).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesConstructorExecution(asCons).alwaysMatches());
// assertTrue("Should match B", ex.matchesConstructorExecution(bsCons).alwaysMatches());
// assertTrue("Does not match client", ex.matchesConstructorExecution(clientCons).neverMatches());
//
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesConstructorExecution(asCons).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesConstructorExecution(bsCons).neverMatches());
//
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Does not match", ex.matchesConstructorExecution(bsCons).neverMatches());
//
// // args
// ex = p.parsePointcutExpression("args(String)");
// assertTrue("Should match A(String)", ex.matchesConstructorExecution(asCons).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesConstructorExecution(bsStringCons).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesConstructorExecution(bsCons).neverMatches());
// }
//
// public void testMatchesAdviceExecution() {
// PointcutExpression ex = p.parsePointcutExpression("adviceexecution()");
// assertTrue("Should match (advice) A.a", ex.matchesAdviceExecution(a).alwaysMatches());
// // test this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesAdviceExecution(foo).alwaysMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesAdviceExecution(a).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesAdviceExecution(a).alwaysMatches());
// assertTrue("Does not match client", ex.matchesAdviceExecution(foo).neverMatches());
//
// // test target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesAdviceExecution(foo).alwaysMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesAdviceExecution(a).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesAdviceExecution(a).alwaysMatches());
// assertTrue("Does not match client", ex.matchesAdviceExecution(foo).neverMatches());
//
// // test within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesAdviceExecution(a).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesAdviceExecution(b).neverMatches());
//
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Does not match", ex.matchesAdviceExecution(a).neverMatches());
//
// // test args
// ex = p.parsePointcutExpression("args(..,int)");
// assertTrue("Should match A.aa", ex.matchesAdviceExecution(aa).alwaysMatches());
// assertTrue("Should match A.aaa", ex.matchesAdviceExecution(aaa).alwaysMatches());
// assertTrue("Should not match A.a", ex.matchesAdviceExecution(a).neverMatches());
// }
//
// public void testMatchesHandler() {
// PointcutExpression ex = p.parsePointcutExpression("handler(Exception)");
// assertTrue("Should match catch(Exception)", ex.matchesHandler(Exception.class, Client.class).alwaysMatches());
// assertTrue("Should not match catch(Throwable)", ex.matchesHandler(Throwable.class, Client.class).neverMatches());
// // test this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesHandler(Exception.class, foo).alwaysMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesHandler(Exception.class, a).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesHandler(Exception.class, a).alwaysMatches());
// assertTrue("Does not match client", ex.matchesHandler(Exception.class, foo).neverMatches());
// // target - no target for exception handlers
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("Should match Client", ex.matchesHandler(Exception.class, foo).neverMatches());
// // args
// ex = p.parsePointcutExpression("args(Exception)");
// assertTrue("Should match Exception", ex.matchesHandler(Exception.class, foo).alwaysMatches());
// assertTrue("Should match RuntimeException", ex.matchesHandler(RuntimeException.class, foo).alwaysMatches());
// assertTrue("Should not match String", ex.matchesHandler(String.class, foo).neverMatches());
// assertTrue("Maybe matches Throwable", ex.matchesHandler(Throwable.class, foo).maybeMatches());
// assertFalse("Maybe matches Throwable", ex.matchesHandler(Throwable.class, foo).alwaysMatches());
// // within
// ex = p.parsePointcutExpression("within(*..Client)");
// assertTrue("Matches in class Client", ex.matchesHandler(Exception.class, foo).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesHandler(Exception.class, b).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Matches within aa", ex.matchesHandler(Exception.class, aa).alwaysMatches());
// assertTrue("Does not match within b", ex.matchesHandler(Exception.class, b).neverMatches());
// }
// -- next few tests relate to matching different pointcut expressions against a staticinitialization join point
public void testMethodMatchesStaticInitialization01() {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("staticinitialization(java.lang.String)");
assertNotNull(ex);
ResolvedType jlString = world.resolve("java.lang.String");
boolean b = ex.matchesStaticInitialization(jlString).alwaysMatches();
assertTrue(b);
}
public void testMethodMatchesStaticInitialization02() {
ResolvedType jlString = world.resolve("java.lang.String");
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("staticinitialization(java..*)");
assertTrue(ex.matchesStaticInitialization(jlString).alwaysMatches());
ex = pointcutParser.parsePointcutExpression("staticinitialization(java..*)");
assertTrue(ex.matchesStaticInitialization(jlString).alwaysMatches());
ex = pointcutParser.parsePointcutExpression("staticinitialization(java.*)");
assertTrue(ex.matchesStaticInitialization(jlString).neverMatches());
}
public void testMethodMatchesStaticInitialization03() {
ResolvedType juArrayList = world.resolve("java.util.ArrayList");
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("staticinitialization(java..*)");
assertTrue(ex.matchesStaticInitialization(juArrayList).alwaysMatches());
ex = pointcutParser.parsePointcutExpression("staticinitialization(java.util.ArrayList)");
assertTrue(ex.matchesStaticInitialization(juArrayList).alwaysMatches());
ex = pointcutParser.parsePointcutExpression("staticinitialization(java.util.List+)");
assertTrue(ex.matchesStaticInitialization(juArrayList).alwaysMatches());
ex = pointcutParser.parsePointcutExpression("staticinitialization(List)");
assertTrue(ex.matchesStaticInitialization(juArrayList).neverMatches());
}
//
// public void testMatchesInitialization() {
// PointcutExpression ex = p.parsePointcutExpression("initialization(new(String))");
// assertTrue("Should match A(String)", ex.matchesInitialization(asCons).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesInitialization(bsStringCons).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesInitialization(bsCons).neverMatches());
// ex = p.parsePointcutExpression("initialization(*..A.new(String))");
// assertTrue("Should match A(String)", ex.matchesInitialization(asCons).alwaysMatches());
// assertTrue("Should not match B(String)", ex.matchesInitialization(bsStringCons).neverMatches());
// // test this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should match A", ex.matchesInitialization(asCons).alwaysMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesInitialization(asCons).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesInitialization(asCons).alwaysMatches());
//
// // test target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("Should match A", ex.matchesInitialization(asCons).alwaysMatches());
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("Maybe matches B", ex.matchesInitialization(asCons).maybeMatches());
// assertFalse("Maybe matches B", ex.matchesInitialization(asCons).alwaysMatches());
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesInitialization(asCons).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesInitialization(bsCons).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Does not match", ex.matchesInitialization(bsCons).neverMatches());
// // args
// ex = p.parsePointcutExpression("args(String)");
// assertTrue("Should match A(String)", ex.matchesInitialization(asCons).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesInitialization(bsStringCons).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesInitialization(bsCons).neverMatches());
// }
//
// public void testMatchesPreInitialization() {
// PointcutExpression ex = p.parsePointcutExpression("preinitialization(new(String))");
// assertTrue("Should match A(String)", ex.matchesPreInitialization(asCons).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesPreInitialization(bsStringCons).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesPreInitialization(bsCons).neverMatches());
// ex = p.parsePointcutExpression("preinitialization(*..A.new(String))");
// assertTrue("Should match A(String)", ex.matchesPreInitialization(asCons).alwaysMatches());
// assertTrue("Should not match B(String)", ex.matchesPreInitialization(bsStringCons).neverMatches());
// // test this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("No match, no this at preinit", ex.matchesPreInitialization(asCons).neverMatches());
//
// // test target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("No match, no target at preinit", ex.matchesPreInitialization(asCons).neverMatches());
//
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesPreInitialization(asCons).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesPreInitialization(bsCons).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Does not match", ex.matchesPreInitialization(bsCons).neverMatches());
// // args
// ex = p.parsePointcutExpression("args(String)");
// assertTrue("Should match A(String)", ex.matchesPreInitialization(asCons).alwaysMatches());
// assertTrue("Should match B(String)", ex.matchesPreInitialization(bsStringCons).alwaysMatches());
// assertTrue("Should not match B()", ex.matchesPreInitialization(bsCons).neverMatches());
// }
//
// public void testMatchesStaticInitialization() {
// // this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("No this", ex.matchesStaticInitialization(A.class).neverMatches());
// // target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// assertTrue("No target", ex.matchesStaticInitialization(A.class).neverMatches());
//
// // args
// ex = p.parsePointcutExpression("args()");
// assertTrue("No args", ex.matchesStaticInitialization(A.class).alwaysMatches());
// ex = p.parsePointcutExpression("args(String)");
// assertTrue("No args", ex.matchesStaticInitialization(A.class).neverMatches());
//
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesStaticInitialization(A.class).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesStaticInitialization(B.class).neverMatches());
//
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Does not match", ex.matchesStaticInitialization(A.class).neverMatches());
// }
//
// public void testMatchesFieldSet() {
// PointcutExpression ex = p.parsePointcutExpression("set(* *..A+.*)");
// assertTrue("matches x", ex.matchesFieldSet(x, a).alwaysMatches());
// assertTrue("matches y", ex.matchesFieldSet(y, foo).alwaysMatches());
// assertTrue("does not match n", ex.matchesFieldSet(n, foo).neverMatches());
// // this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("matches Client", ex.matchesFieldSet(x, foo).alwaysMatches());
// assertTrue("does not match A", ex.matchesFieldSet(n, a).neverMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("maybe matches A", ex.matchesFieldSet(x, a).maybeMatches());
// assertFalse("maybe matches A", ex.matchesFieldSet(x, a).alwaysMatches());
// // target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("matches B", ex.matchesFieldSet(y, foo).alwaysMatches());
// assertTrue("maybe matches A", ex.matchesFieldSet(x, foo).maybeMatches());
// assertFalse("maybe matches A", ex.matchesFieldSet(x, foo).alwaysMatches());
// // args
// ex = p.parsePointcutExpression("args(int)");
// assertTrue("matches x", ex.matchesFieldSet(x, a).alwaysMatches());
// assertTrue("matches y", ex.matchesFieldSet(y, a).alwaysMatches());
// assertTrue("does not match n", ex.matchesFieldSet(n, a).neverMatches());
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesFieldSet(x, a).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesFieldSet(x, b).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Should match", ex.matchesFieldSet(x, aa).alwaysMatches());
// assertTrue("Should not match", ex.matchesFieldSet(x, b).neverMatches());
// }
//
// public void testMatchesFieldGet() {
// PointcutExpression ex = p.parsePointcutExpression("get(* *..A+.*)");
// assertTrue("matches x", ex.matchesFieldGet(x, a).alwaysMatches());
// assertTrue("matches y", ex.matchesFieldGet(y, foo).alwaysMatches());
// assertTrue("does not match n", ex.matchesFieldGet(n, foo).neverMatches());
// // this
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.Client)");
// assertTrue("matches Client", ex.matchesFieldGet(x, foo).alwaysMatches());
// assertTrue("does not match A", ex.matchesFieldGet(n, a).neverMatches());
// ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("maybe matches A", ex.matchesFieldGet(x, a).maybeMatches());
// assertFalse("maybe matches A", ex.matchesFieldGet(x, a).alwaysMatches());
// // target
// ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertTrue("matches B", ex.matchesFieldGet(y, foo).alwaysMatches());
// assertTrue("maybe matches A", ex.matchesFieldGet(x, foo).maybeMatches());
// assertFalse("maybe matches A", ex.matchesFieldGet(x, foo).alwaysMatches());
// // args - no args at get join point
// ex = p.parsePointcutExpression("args(int)");
// assertTrue("matches x", ex.matchesFieldGet(x, a).neverMatches());
// // within
// ex = p.parsePointcutExpression("within(*..A)");
// assertTrue("Matches in class A", ex.matchesFieldGet(x, a).alwaysMatches());
// assertTrue("Does not match in class B", ex.matchesFieldGet(x, b).neverMatches());
// // withincode
// ex = p.parsePointcutExpression("withincode(* a*(..))");
// assertTrue("Should match", ex.matchesFieldGet(x, aa).alwaysMatches());
// assertTrue("Should not match", ex.matchesFieldGet(x, b).neverMatches());
// }
//
// public void testArgsMatching() {
// // too few args
// PointcutExpression ex = p.parsePointcutExpression("args(*,*,*,*)");
// assertTrue("Too few args", ex.matchesMethodExecution(foo).neverMatches());
// assertTrue("Matching #args", ex.matchesMethodExecution(bar).alwaysMatches());
// // one too few + ellipsis
// ex = p.parsePointcutExpression("args(*,*,*,..)");
// assertTrue("Matches with ellipsis", ex.matchesMethodExecution(foo).alwaysMatches());
// // exact number + ellipsis
// assertTrue("Matches with ellipsis", ex.matchesMethodExecution(bar).alwaysMatches());
// assertTrue("Does not match with ellipsis", ex.matchesMethodExecution(a).neverMatches());
// // too many + ellipsis
// ex = p.parsePointcutExpression("args(*,..,*)");
// assertTrue("Matches with ellipsis", ex.matchesMethodExecution(bar).alwaysMatches());
// assertTrue("Does not match with ellipsis", ex.matchesMethodExecution(a).neverMatches());
// assertTrue("Matches with ellipsis", ex.matchesMethodExecution(aaa).alwaysMatches());
// // exact match
// ex = p.parsePointcutExpression("args(String,int,Number)");
// assertTrue("Matches exactly", ex.matchesMethodExecution(foo).alwaysMatches());
// // maybe match
// ex = p.parsePointcutExpression("args(String,int,Double)");
// assertTrue("Matches maybe", ex.matchesMethodExecution(foo).maybeMatches());
// assertFalse("Matches maybe", ex.matchesMethodExecution(foo).alwaysMatches());
// // never match
// ex = p.parsePointcutExpression("args(String,Integer,Number)");
// if (LangUtil.isVMGreaterOrEqual(15)) {
// assertTrue("matches", ex.matchesMethodExecution(foo).alwaysMatches());
// } else {
// assertTrue("Does not match", ex.matchesMethodExecution(foo).neverMatches());
// }
// }
//
// // public void testMatchesDynamically() {
// // // everything other than this,target,args should just return true
// // PointcutExpression ex = p.parsePointcutExpression("call(* *.*(..)) && execution(* *.*(..)) &&" +
// // "get(* *) && set(* *) && initialization(new(..)) && preinitialization(new(..)) &&" +
// // "staticinitialization(X) && adviceexecution() && within(Y) && withincode(* *.*(..)))");
// // assertTrue("Matches dynamically",ex.matchesDynamically(a,b,new Object[0]));
// // // this
// // ex = p.parsePointcutExpression("this(String)");
// // assertTrue("String matches",ex.matchesDynamically("",this,new Object[0]));
// // assertFalse("Object doesn't match",ex.matchesDynamically(new Object(),this,new Object[0]));
// // ex = p.parsePointcutExpression("this(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// // assertTrue("A matches",ex.matchesDynamically(new A(""),this,new Object[0]));
// // assertTrue("B matches",ex.matchesDynamically(new B(""),this,new Object[0]));
// // // target
// // ex = p.parsePointcutExpression("target(String)");
// // assertTrue("String matches",ex.matchesDynamically(this,"",new Object[0]));
// // assertFalse("Object doesn't match",ex.matchesDynamically(this,new Object(),new Object[0]));
// // ex = p.parsePointcutExpression("target(org.aspectj.weaver.tools.PointcutExpressionTest.A)");
// // assertTrue("A matches",ex.matchesDynamically(this,new A(""),new Object[0]));
// // assertTrue("B matches",ex.matchesDynamically(this,new B(""),new Object[0]));
// // // args
// // ex = p.parsePointcutExpression("args(*,*,*,*)");
// // assertFalse("Too few args",ex.matchesDynamically(null,null,new Object[]{a,b}));
// // assertTrue("Matching #args",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa}));
// // // one too few + ellipsis
// // ex = p.parsePointcutExpression("args(*,*,*,..)");
// // assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa}));
// // // exact number + ellipsis
// // assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa}));
// // assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b}));
// // // too many + ellipsis
// // ex = p.parsePointcutExpression("args(*,..,*)");
// // assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b,aa,aaa}));
// // assertFalse("Does not match with ellipsis",ex.matchesDynamically(null,null,new Object[]{a}));
// // assertTrue("Matches with ellipsis",ex.matchesDynamically(null,null,new Object[]{a,b}));
// // // exact match
// // ex = p.parsePointcutExpression("args(String,int,Number)");
// // assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)}));
// // ex = p.parsePointcutExpression("args(String,Integer,Number)");
// // assertTrue("Matches exactly",ex.matchesDynamically(null,null,new Object[]{"",new Integer(5),new Double(5.0)}));
// // // never match
// // ex = p.parsePointcutExpression("args(String,Integer,Number)");
// // assertFalse("Does not match",ex.matchesDynamically(null,null,new Object[]{a,b,aa}));
// // }
//
// public void testGetPointcutExpression() {
// PointcutExpression ex = p.parsePointcutExpression("staticinitialization(*..A+)");
// assertEquals("staticinitialization(*..A+)", ex.getPointcutExpression());
// }
//
// public void testCouldMatchJoinPointsInType() {
// PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))");
// assertTrue("Could maybe match String (as best we know at this point)", ex.couldMatchJoinPointsInType(String.class));
// assertTrue("Will always match B", ex.couldMatchJoinPointsInType(B.class));
// ex = p.parsePointcutExpression("within(org.aspectj.weaver.tools.PointcutExpressionTest.B)");
// assertFalse("Will never match String", ex.couldMatchJoinPointsInType(String.class));
// assertTrue("Will always match B", ex.couldMatchJoinPointsInType(B.class));
// }
//
// public void testMayNeedDynamicTest() {
// PointcutExpression ex = p.parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..))");
// assertFalse("No dynamic test needed", ex.mayNeedDynamicTest());
// ex = p
// .parsePointcutExpression("execution(* org.aspectj.weaver.tools.PointcutExpressionTest.B.*(..)) && args(org.aspectj.weaver.tools.PointcutExpressionTest.X)");
// assertTrue("Dynamic test needed", ex.mayNeedDynamicTest());
// }
// -- helpers
private ResolvedMember getMethod(ResolvedType type, String methodName, String methodSignature) {
ResolvedMember[] methods = type.getDeclaredMethods();
for (ResolvedMember method : methods) {
if (method.getName().equals(methodName)
&& (methodSignature == null || methodSignature.equals(method.getSignature()))) {
return method;
}
}
return null;
}
private void checkAlwaysMatches(String pointcutExpression, String type, String methodName, String methodSignature) {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression(pointcutExpression);
assertNotNull(ex);
ResolvedType resolvedType = world.resolve(type);
ResolvedMember method = getMethod(resolvedType, methodName, methodSignature);
assertNotNull("Couldn't find a method with signature " + methodSignature, method);
boolean b = ex.matchesMethodExecution(method).alwaysMatches();
assertTrue("Match failed", b);
}
private void checkNeverMatches(String pointcutExpression, String type, String methodName, String methodSignature) {
StandardPointcutExpression ex = pointcutParser.parsePointcutExpression(pointcutExpression);
assertNotNull(ex);
ResolvedType resolvedType = world.resolve(type);
ResolvedMember method = getMethod(resolvedType, methodName, methodSignature);
assertNotNull(method);
boolean b = ex.matchesMethodExecution(method).neverMatches();
assertTrue(b);
}
}
|