From: aclement Date: Thu, 26 Feb 2004 09:56:40 +0000 (+0000) Subject: Fix for preventing the use of if/target/this/args/cflow/cflowbelow in DeclareSofts. X-Git-Tag: v_preCompileLoopAlteration~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a8c17de491cf0c062c50e7a7488d5074c3f30673;p=aspectj.git Fix for preventing the use of if/target/this/args/cflow/cflowbelow in DeclareSofts. --- diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index 5f2210e34..2081e9e7c 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -7210,4 +7210,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/bugs/DeclareSoftDynamicPCDs.java b/tests/bugs/DeclareSoftDynamicPCDs.java new file mode 100644 index 000000000..934afbc9e --- /dev/null +++ b/tests/bugs/DeclareSoftDynamicPCDs.java @@ -0,0 +1,58 @@ +/* + * From: + * + * http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/semantics-declare.html#d0e6499 + * + * Pointcuts that appear inside of declare forms have certain restrictions. + * Like other pointcuts, these pick out join points, but they do so in a + * way that is statically determinable. + * + * Consequently, such pointcuts may not include, directly or indirectly + * (through user-defined pointcut declarations) pointcuts that discriminate + * based on dynamic (runtime) context. Therefore, such pointcuts may not be + * defined in terms of + * + * cflow + * cflowbelow + * this + * target + * args + * if + * + * all of which can discriminate on runtime information. + */ + +public aspect DeclareSoftDynamicPCDs { + + declare soft : MyException:if(true) ; + pointcut p(): if(false); + declare soft : MyException: p() ; + + declare soft : MyException:cflow(execution(* main(..))); + pointcut p2(): cflow(execution(* main(..))); + declare soft : MyException:p2(); + + declare soft : MyException:cflowbelow(execution(* main(..))); + pointcut p3(): cflowbelow(execution(* main(..))); + declare soft : MyException:p3(); + + declare soft : MyException: this(Object); + pointcut p4(): this(Object); + declare soft : MyException:p4(); + + declare soft : MyException:target(Object); + pointcut p5(): target(Object); + declare soft : MyException:p5(); + + declare soft : MyException:args(Object); + pointcut p6(): args(Object); + declare soft : MyException:p6(); + + class MyException extends Exception { + } + + public static void main(String[] args) { + System.err.println("In main!"); + } + +} \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java b/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java index 4a359d69a..f8db5c29a 100644 --- a/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java +++ b/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.aspectj.weaver.bcel.BcelTypeMunger; import org.aspectj.weaver.patterns.DeclareParents; /** diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java index 7c6410623..86c55b920 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java @@ -20,7 +20,6 @@ import java.io.IOException; import org.aspectj.bridge.IMessage; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.BetaException; -import org.aspectj.weaver.Checker; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.ResolvedTypeX; @@ -89,8 +88,8 @@ public class ArgsPointcut extends NameBindingPointcut { public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) { - if (bindings.getEnclosingAdvice() instanceof Checker) { - // Enforce rule about which designators are supported in deow + if (isDeclare(bindings.getEnclosingAdvice())) { + // Enforce rule about which designators are supported in declare inAspect.getWorld().showMessage(IMessage.ERROR, "args() pointcut designator cannot be used in declare statement", bindings.getEnclosingAdvice().getSourceLocation(), null); diff --git a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java index e7d5ac8b9..ef6dc5d80 100644 --- a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java @@ -25,7 +25,6 @@ import org.aspectj.bridge.IMessage; import org.aspectj.util.FileUtil; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.Advice; -import org.aspectj.weaver.Checker; import org.aspectj.weaver.CrosscuttingMembers; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.IntMap; @@ -123,8 +122,8 @@ public class CflowPointcut extends Pointcut { public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) { - if (bindings.getEnclosingAdvice() instanceof Checker) { - // Enforce rule about which designators are supported in deow + if (isDeclare(bindings.getEnclosingAdvice())) { + // Enforce rule about which designators are supported in declare inAspect.getWorld().showMessage(IMessage.ERROR, "cflow"+(isBelow?"below":"")+"() pointcut designator cannot be used in declare statement", bindings.getEnclosingAdvice().getSourceLocation(), null); diff --git a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java index 6cb181329..baf55d85b 100644 --- a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java @@ -22,7 +22,6 @@ import java.util.List; import org.aspectj.bridge.IMessage; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.Advice; -import org.aspectj.weaver.Checker; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.ResolvedMember; @@ -30,10 +29,10 @@ import org.aspectj.weaver.ResolvedPointcutDefinition; import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.ShadowMunger; -import org.aspectj.weaver.ast.*; import org.aspectj.weaver.ast.Expr; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.ast.Var; public class IfPointcut extends Pointcut { @@ -148,8 +147,8 @@ public class IfPointcut extends Pointcut { public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) { //System.err.println("concretize: " + this + " already: " + partiallyConcretized); - if (bindings.getEnclosingAdvice() instanceof Checker) { - // Enforce rule about which designators are supported in deow + if (isDeclare(bindings.getEnclosingAdvice())) { + // Enforce rule about which designators are supported in declare inAspect.getWorld().showMessage(IMessage.ERROR, "if() pointcut designator cannot be used in declare statement", bindings.getEnclosingAdvice().getSourceLocation(), diff --git a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java index 814370f15..daca6f922 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java @@ -19,7 +19,6 @@ import java.io.IOException; import org.aspectj.bridge.IMessage; import org.aspectj.util.FuzzyBoolean; -import org.aspectj.weaver.Checker; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.ResolvedTypeX; @@ -117,8 +116,8 @@ public class ThisOrTargetPointcut extends NameBindingPointcut { } public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) { - if (bindings.getEnclosingAdvice() instanceof Checker) { - // Enforce rule about which designators are supported in deow + if (isDeclare(bindings.getEnclosingAdvice())) { + // Enforce rule about which designators are supported in declare inAspect.getWorld().showMessage(IMessage.ERROR, (isThis?"this":"target")+"() pointcut designator cannot be used in declare statement", bindings.getEnclosingAdvice().getSourceLocation(), null);