]> source.dussan.org Git - aspectj.git/commitdiff
Fix for preventing the use of if/target/this/args/cflow/cflowbelow in DeclareSofts.
authoraclement <aclement>
Thu, 26 Feb 2004 09:56:40 +0000 (09:56 +0000)
committeraclement <aclement>
Thu, 26 Feb 2004 09:56:40 +0000 (09:56 +0000)
tests/ajcTests.xml
tests/bugs/DeclareSoftDynamicPCDs.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java
weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java

index 5f2210e347026909cd9e228723be1162cd877891..2081e9e7c582bff26c3bd56a82c5556cc2f22692 100644 (file)
         </compile>
     </ajc-test>
        
+        <ajc-test dir="bugs" pr="51320"
+               title="ClasscastException on concretization of if(false)">
+        <compile files="DeclareSoftDynamicPCDs.java">
+        
+         <!-- These are the illegal PCDs against a deow -->
+         <message kind="error" line="27" text="if() pointcut designator cannot be used"/>
+         <message kind="error" line="29" text="if() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="31" text="cflow() pointcut designator cannot be used"/>
+         <message kind="error" line="33" text="cflow() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="35" text="cflowbelow() pointcut designator cannot be used"/>
+         <message kind="error" line="37" text="cflowbelow() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="39" text="this() pointcut designator cannot be used"/>
+         <message kind="error" line="41" text="this() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="43" text="target() pointcut designator cannot be used"/>
+         <message kind="error" line="45" text="target() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="47" text="args() pointcut designator cannot be used"/>
+         <message kind="error" line="49" text="args() pointcut designator cannot be used"/>
+         
+        </compile>
+    </ajc-test>
+    
 </suite>
diff --git a/tests/bugs/DeclareSoftDynamicPCDs.java b/tests/bugs/DeclareSoftDynamicPCDs.java
new file mode 100644 (file)
index 0000000..934afbc
--- /dev/null
@@ -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
index 4a359d69a880f7212903224f8958b09261a80c9f..f8db5c29a22d6bd5be559f7d1de6538dd323238b 100644 (file)
@@ -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;
 
 /**
index 7c64106235b84c34f2ef9b7197843d5b072c32da..86c55b920595c20006e45cda39c7c47df40ef2de 100644 (file)
@@ -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);
index e7d5ac8b9c0261be7249602da96e1efeb61fd025..ef6dc5d80163e0c8ce7ccbc7d078fa4ee77e7ecc 100644 (file)
@@ -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);
index 6cb181329c084b530e3d70a6ec4fe25194d556a9..baf55d85b12164b02de55bb9817b4825f825b8f1 100644 (file)
@@ -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(),
index 814370f15043b9ca12f17d33a0db34b9fae4482e..daca6f9227fd40194787c391b3c4b6d03c011457 100644 (file)
@@ -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);