Skip to content

Commit 1f79352

Browse files
committed
Allow withincode pointcuts to match method execution joinpoints
1 parent 2b0e11d commit 1f79352

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WithincodePointcut.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class WithincodePointcut extends Pointcut {
4141
// these next two are needed for inlining of field initializers
4242
flags |= Shadow.ConstructorExecution.bit;
4343
flags |= Shadow.Initialization.bit;
44+
// According to the documentation, method (and constructor) execution matches.
45+
flags |= Shadow.MethodExecution.bit;
4446
matchedShadowKinds = flags;
4547
}
4648

org.aspectj.matcher/src/test/java/org/aspectj/matcher/tools/CommonPointcutExpressionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public void testMatchingWithinCode01() {
226226
ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
227227
ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
228228

229-
assertTrue(ex.matchesMethodExecution(stringSplitMethod).neverMatches());
230-
assertTrue(ex.matchesMethodExecution(stringValueOfIntMethod).neverMatches());
229+
assertTrue(ex.matchesMethodExecution(stringSplitMethod).alwaysMatches());
230+
assertTrue(ex.matchesMethodExecution(stringValueOfIntMethod).alwaysMatches());
231231
assertTrue(ex.matchesMethodExecution(listAddMethod).neverMatches());
232232
}
233233

org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/PointcutRewriterTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public void testKindSetOfWithinCode() {
337337
Set<Shadow.Kind> matches = Shadow.toSet(p.couldMatchKinds());
338338
for (Shadow.Kind o : matches) {
339339
assertFalse("No kinds that are themselves enclosing",
340-
(o.isEnclosingKind() && o != Shadow.ConstructorExecution && o != Shadow.Initialization));
340+
(o.isEnclosingKind() && o != Shadow.ConstructorExecution && o != Shadow.Initialization
341+
&& o != Shadow.MethodExecution));
341342
}
342343
for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) {
343344
if (!Shadow.SHADOW_KINDS[i].isEnclosingKind()) {
@@ -346,6 +347,7 @@ public void testKindSetOfWithinCode() {
346347
}
347348
assertTrue("Need cons-exe for inlined field inits", matches.contains(Shadow.ConstructorExecution));
348349
assertTrue("Need init for inlined field inits", matches.contains(Shadow.Initialization));
350+
assertTrue("Needs method-exe to comply with the docs", matches.contains(Shadow.MethodExecution));
349351
// + @
350352
p = getPointcut("@withincode(Foo)");
351353
matches = Shadow.toSet(p.couldMatchKinds());

tests/bugs150/Pr103097.aj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import java.io.IOException;
33
public aspect Pr103097 {
44
declare soft: IOException:
55
within(Pr103097) &&
6-
!withincode(* *(..)) &&
6+
(!withincode(* *(..)) || execution(* *(..))) &&
77
!call(* *(..));
88

99
before() : execution(* main(..)) {

tests/src/test/resources/org/aspectj/systemtest/ajc150/ajc150.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5207,7 +5207,9 @@
52075207
<message kind="warning" line="38" text="erasure type matching in withincode ok"/>
52085208
<message kind="warning" line="39" text="erasure type matching in withincode ok"/>
52095209
<message kind="warning" line="42" text="erasure type matching in withincode ok"/>
5210+
<message kind="warning" line="61" text="withincode and parameterized method ok"/>
52105211
<message kind="warning" line="62" text="withincode and parameterized method ok"/>
5212+
<message kind="warning" line="61" text="withincode and generic interface ok"/>
52115213
<message kind="warning" line="62" text="withincode and generic interface ok"/>
52125214
<message kind="warning" line="65" text="withincode and interface control test"/>
52135215
<message kind="warning" line="35" text="match on parameterized args"/>
@@ -5218,16 +5220,27 @@
52185220

52195221
<ajc-test dir="java5/generics/pointcuts" title="withincode with overriding of inherited generic members">
52205222
<compile files="WithinCodeOverriding.aj" options="-1.8">
5223+
<message kind="warning" line="36" text="wildcard declaring type match on erasure"/>
52215224
<message kind="warning" line="37" text="wildcard declaring type match on erasure"/>
5225+
<message kind="warning" line="49" text="wildcard declaring type match on erasure"/>
52225226
<message kind="warning" line="50" text="wildcard declaring type match on erasure"/>
5227+
<message kind="warning" line="62" text="wildcard declaring type match on erasure"/>
52235228
<message kind="warning" line="63" text="wildcard declaring type match on erasure"/>
5229+
<message kind="warning" line="36" text="base declaring type match on erasure"/>
52245230
<message kind="warning" line="37" text="base declaring type match on erasure"/>
5231+
<message kind="warning" line="49" text="base declaring type match on erasure"/>
52255232
<message kind="warning" line="50" text="base declaring type match on erasure"/>
5233+
<message kind="warning" line="62" text="base declaring type match on erasure"/>
52265234
<message kind="warning" line="63" text="base declaring type match on erasure"/>
5235+
<message kind="warning" line="49" text="sub type match on erasure"/>
52275236
<message kind="warning" line="50" text="sub type match on erasure"/>
5237+
<message kind="warning" line="62" text="parameterized match on erasure"/>
52285238
<message kind="warning" line="63" text="parameterized match on erasure"/>
5239+
<message kind="warning" line="79" text="erasure match on base interface"/>
52295240
<message kind="warning" line="80" text="erasure match on base interface"/>
5241+
<message kind="warning" line="79" text="wildcard match on erasure"/>
52305242
<message kind="warning" line="80" text="wildcard match on erasure"/>
5243+
<message kind="warning" line="79" text="parameterized match"/>
52315244
<message kind="warning" line="80" text="parameterized match"/>
52325245
</compile>
52335246
</ajc-test>
@@ -5445,7 +5458,9 @@
54455458
<compile files="GenericMethods.aj" options="-1.8">
54465459
<message kind="warning" line="19" text="static generic method match"/>
54475460
<message kind="warning" line="34" text="static generic method match"/>
5461+
<message kind="warning" line="23" text="instance generic method match"/>
54485462
<message kind="warning" line="24" text="instance generic method match"/>
5463+
<message kind="warning" line="38" text="instance generic method match"/>
54495464
<message kind="warning" line="39" text="instance generic method match"/>
54505465
</compile>
54515466
</ajc-test>

tests/src/test/resources/org/aspectj/systemtest/ajc152/synchronization.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
<ajc-test dir="features152/synchronization" title="prevent double unlock weaving messages and model contents">
325325
<compile files="ThisJoinPointUnlock.java" options="-1.8 -Xjoinpoints:synchronization -showWeaveInfo -emacssym">
326326
<message kind="weave" text="Join point 'lock(void java.lang.Object.&lt;lock&gt;(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/>
327+
<message kind="weave" text="Join point 'method-execution(void ThisJoinPointUnlock.nonStaticMethod())' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:37) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/>
327328
<message kind="weave" text="Join point 'method-call(void ThisJoinPointUnlock.staticMethod())' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:39) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/>
328329
<message kind="weave" text="Join point 'unlock(void java.lang.Object.&lt;unlock&gt;(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/>
329330
</compile>

weaver/src/test/java/org/aspectj/weaver/tools/PointcutExpressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void testMatchesMethodExecution() {
118118

119119
// withincode
120120
ex = p.parsePointcutExpression("withincode(* a*(..))");
121-
assertTrue("Should not match", ex.matchesMethodExecution(a).neverMatches());
121+
assertTrue("Should match", ex.matchesMethodExecution(a).alwaysMatches());
122122
}
123123

124124
public void testMatchesConstructorCall() {

0 commit comments

Comments
 (0)