From ee0b12f950c0c24acf8df868e529385aec523c06 Mon Sep 17 00:00:00 2001 From: acolyer Date: Thu, 16 Dec 2004 11:04:19 +0000 Subject: [PATCH] it is now safe to short-circuit in and/or pc matching (all side-effects removed) --- tests/java5/varargs/SimpleVarargs.java | 9 +++++++-- .../systemtest/ajc150/VarargsTests.java | 20 +++++++------------ .../aspectj/weaver/patterns/AndPointcut.java | 4 +++- .../aspectj/weaver/patterns/OrPointcut.java | 4 +++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/java5/varargs/SimpleVarargs.java b/tests/java5/varargs/SimpleVarargs.java index bcd1e1bdf..c32047ab6 100644 --- a/tests/java5/varargs/SimpleVarargs.java +++ b/tests/java5/varargs/SimpleVarargs.java @@ -2,12 +2,17 @@ public class SimpleVarargs { public SimpleVarargs(Integer... strings) {} - public void foo(Integer... strings) { } + public void foo(Integer... strings) { + moo(); + } //public void bar(Integer[] array) { } - public void fooInt(int i,Integer... strings) {} + public void fooInt(int i,Integer... strings) { + moo(); + } + private void moo() {} //public void barInt(int i,Integer[] strings) {} public static void main(String[] argv) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java b/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java index 178e82b18..14f4532c7 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java @@ -56,15 +56,9 @@ public class VarargsTests extends TestUtils { } // check when signature is from an withincode PCD - // In this test, it can be tricky to understand the results!! The reason being that the shadow - // isn't included in the error message (it really should be, but thats a bit hard to do cleanly) public void test003_cantMatchVarargsWithObjectArray_withincodePCD() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect04.aj",0,6,true); + CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect04.aj",0,1,true); - // There are 7. Each piece of the pointcut is matched against all the shadows, so both - // the 'withincode' PCD and the 'call' PCD are matched against every join point. - // AMC - there are now SIX. We detect early that a call(* *(..)) pcd cannot match - // constructor call shadows and never do the match. assertTrue("Did not get expected message about a varargs mismatch, instead got: "+cR.getWarningMessages(), ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("varargs declared method")!=-1); @@ -79,9 +73,9 @@ public class VarargsTests extends TestUtils { System.err.println(cR.getErrorMessages()); System.err.println(cR.getInfoMessages()); verifyWeavingMessagesOutput(cR,new String[]{ - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:15) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:16) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:17) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)"}); + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:20) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:21) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:22) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)"}); } // before(): call(* *(int,Integer...)) { } - slightly more complex pcut @@ -92,9 +86,9 @@ public class VarargsTests extends TestUtils { System.err.println(cR.getInfoMessages()); verifyWeavingMessagesOutput(cR,new String[]{ - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:20) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:21) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:22) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)"}); + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:25) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:26) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", + "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:27) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)"}); } } \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java index 1775ba3db..dcb951d46 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java @@ -53,7 +53,9 @@ public class AndPointcut extends Pointcut { } protected FuzzyBoolean matchInternal(Shadow shadow) { - return left.match(shadow).and(right.match(shadow)); + FuzzyBoolean leftMatch = left.match(shadow); + if (leftMatch.alwaysFalse()) return leftMatch; + return leftMatch.and(right.match(shadow)); } public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) { diff --git a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java index e204ef329..2eca6de01 100644 --- a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java @@ -51,7 +51,9 @@ public class OrPointcut extends Pointcut { } protected FuzzyBoolean matchInternal(Shadow shadow) { - return left.match(shadow).or(right.match(shadow)); + FuzzyBoolean leftMatch = left.match(shadow); + if (leftMatch.alwaysTrue()) return leftMatch; + return leftMatch.or(right.match(shadow)); } public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) { -- 2.39.5