]> source.dussan.org Git - aspectj.git/commitdiff
fixes for pr113447 - dont do bindings check at each shadow.
authoraclement <aclement>
Fri, 11 Nov 2005 11:24:10 +0000 (11:24 +0000)
committeraclement <aclement>
Fri, 11 Nov 2005 11:24:10 +0000 (11:24 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
weaver/src/org/aspectj/weaver/patterns/ExposedState.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java
weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java

index c2049533bdc68fc2dd406cbc79955ef224e6ddc7..8d730932cfee1eabf05312950d2f8d366d876f50 100644 (file)
@@ -437,6 +437,9 @@ public class BcelWeaver implements IWeaver {
 
                shadowMungerList = xcutSet.getShadowMungers();
                rewritePointcuts(shadowMungerList);
+               // Sometimes an error occurs during rewriting pointcuts (for example, if ambiguous bindings
+               // are detected) - we ought to fail the prepare when this happens because continuing with
+               // inconsistent pointcuts could lead to problems
                typeMungerList = xcutSet.getTypeMungers();
         lateTypeMungerList = xcutSet.getLateTypeMungers();
                declareParentsList = xcutSet.getDeclareParents();
index 3cf61459a1654df076514a48662455afbd5c20ef..b6ee8ee0872a49f610f279aa78622eb0726a5b15 100644 (file)
@@ -197,18 +197,7 @@ public class AnnotationPointcut extends NameBindingPointcut {
                        if (var == null) throw new BCException("Impossible! annotation=["+annotationType+
                                                                       "]  shadow=["+shadow+" at "+shadow.getSourceLocation()+
                                                                                                   "]    pointcut is at ["+getSourceLocation()+"]");//return Literal.FALSE;
-                       // Check if we have already bound something to this formal
-                       if ((state.get(btp.getFormalIndex())!=null) &&(lastMatchedShadowId == shadow.shadowId)) {
-//                             ISourceLocation pcdSloc = getSourceLocation(); 
-//                             ISourceLocation shadowSloc = shadow.getSourceLocation();
-//                             Message errorMessage = new Message(
-//                                     "Cannot use @pointcut to match at this location and bind a formal to type '"+var.getType()+
-//                                     "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
-//                                     ".  The secondary source location points to the problematic binding.",
-//                                     shadowSloc,true,new ISourceLocation[]{pcdSloc}); 
-//                             shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
-                               state.setErroneousVar(btp.getFormalIndex());
-                       }
+
                        state.set(btp.getFormalIndex(),var);
                }
                if (matchInternal(shadow).alwaysTrue()) 
index c8bdee759220ad6f9b0fd3de38aa06fab82415f3..6ddb09e7d70cc71aa530c3ffff3f0876bb2e7ea7 100644 (file)
@@ -212,19 +212,6 @@ public class ArgsPointcut extends NameBindingPointcut {
                                if (type.matchesInstanceof(argRTX).alwaysTrue()) {
                                        continue;
                                }
-                       } else {
-                         BindingTypePattern btp = (BindingTypePattern)type;
-                         // Check if we have already bound something to this formal
-                         if ((state.get(btp.getFormalIndex())!=null) &&(lastMatchedShadowId != shadow.shadowId)) {
-//                             ISourceLocation isl = getSourceLocation();
-//                             Message errorMessage = new Message(
-//                    "Ambiguous binding of type "+type.getExactType().toString()+
-//                    " using args(..) at this line - formal is already bound"+
-//                    ".  See secondary source location for location of args(..)",
-//                                     shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()});
-//                             shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
-                               state.setErroneousVar(btp.getFormalIndex());
-                         }
                        }
 
                        World world = shadow.getIWorld();
index 03dd40e1530627c6d4c5663881535bb9a93d8acf..230abdb694506cd5112c15aeaa660abb3873a7c8 100644 (file)
@@ -16,6 +16,8 @@ package org.aspectj.weaver.patterns;
 import java.util.Arrays;
 
 import org.aspectj.weaver.Member;
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.ast.Expr;
 import org.aspectj.weaver.ast.Var;
 
@@ -23,6 +25,7 @@ public class ExposedState {
        public Var[] vars;
        private boolean[] erroneousVars;
        private Expr aspectInstance;
+       private UnresolvedType[] expectedVarTypes; // enables us to check that binding is occurring with the *right* types
 
        public ExposedState(int size) {
                super();
@@ -33,6 +36,13 @@ public class ExposedState {
        public ExposedState(Member signature) {
                // XXX there maybe something about target for non-static sigs
                this(signature.getParameterTypes().length);
+               expectedVarTypes = new UnresolvedType[signature.getParameterTypes().length];
+               if (expectedVarTypes.length>0) {
+                       for (int i = 0; i < signature.getParameterTypes().length; i++) {
+                               expectedVarTypes[i] = signature.getParameterTypes()[i];
+                       }
+               }
+               
        }
        
        public boolean isFullySetUp() {
@@ -43,12 +53,18 @@ public class ExposedState {
        }
 
        public void set(int i, Var var) {
-               //XXX add sanity checks
-               // Some checks added in ArgsPointcut and ThisOrTargetPointcut
-//             if (vars[i]!=null) {
-//                     if (!var.getType().equals(vars[i].getType()))
-//                       throw new RuntimeException("Shouldn't allow a slot to change type! Currently="+var.getType()+"   New="+vars[i].getType());
-//             }
+               // check the type is OK if we can... these are the same rules as in matchesInstanceOf() processing
+               if (expectedVarTypes!=null) {
+                       ResolvedType expected = expectedVarTypes[i].resolve(var.getType().getWorld());
+                       if (!expected.equals(ResolvedType.OBJECT)) {
+                               if (!expected.isAssignableFrom(var.getType())) {
+                                       if (!var.getType().isCoerceableFrom(expected)) {
+//                                             throw new BCException("Expected type "+expectedVarTypes[i]+" in slot "+i+" but attempt to put "+var.getType()+" into it");
+                                               return;
+                                       }
+                               }
+                       }
+               }
                vars[i] = var;
        }
     public Var get(int i) {
index 72c262c649d334d55a43834306b9060a83fd8c7c..54f26a01d5834d9ad361101d2244dc8767bd0b04 100644 (file)
@@ -192,18 +192,7 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut {
                                shadow.getTargetAnnotationVar(annotationType);
                        if (annVar == null)
                                throw new RuntimeException("Impossible!");
-                       // Check if we have already bound something to this formal
-                       if ((state.get(btp.getFormalIndex())!=null) &&(lastMatchedShadowId == shadow.shadowId)) {
-//                             ISourceLocation pcdSloc = getSourceLocation(); 
-//                             ISourceLocation shadowSloc = shadow.getSourceLocation();
-//                             Message errorMessage = new Message(
-//                                     "Cannot use @pointcut to match at this location and bind a formal to type '"+annVar.getType()+
-//                                     "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
-//                                     ".  The secondary source location points to the problematic binding.",
-//                                     shadowSloc,true,new ISourceLocation[]{pcdSloc}); 
-//                             shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
-                               state.setErroneousVar(btp.getFormalIndex());
-                       }
+
                        state.set(btp.getFormalIndex(),annVar);
                }
 
index da23506eaf9abbe75bc9d572ceb1e8f90b43b328..916fff9359f88bdbd52abdd45b8923144b767b0d 100644 (file)
@@ -169,31 +169,19 @@ public class ThisOrTargetPointcut extends NameBindingPointcut {
                return (isThis ? "this(" : "target(") + type + ")";
        }
 
+       /** 
+        * Residue is the remainder of the pointcut match that couldn't be
+        * performed with the purely static information at compile time and
+        * this method returns the residue of a pointcut at a particular shadow.
+        */
        protected Test findResidueInternal(Shadow shadow, ExposedState state) {
                if (!couldMatch(shadow)) return Literal.FALSE;
                
+               // if no preference is specified, just say TRUE which means no residue
                if (type == TypePattern.ANY) return Literal.TRUE;
                
                Var var = isThis ? shadow.getThisVar() : shadow.getTargetVar(); 
 
-               if (type instanceof BindingTypePattern) {
-                 BindingTypePattern btp = (BindingTypePattern)type;
-                 // Check if we have already bound something to this formal
-                 Var existingVarInThisSlot = state.get(btp.getFormalIndex());
-                 
-                 if (existingVarInThisSlot != null ) {
-                         
-                       // Is it already bound to exactly the same thing?
-                       if (existingVarInThisSlot.equals(var)) return Literal.TRUE;
-                       
-                       // If state.get() returned non-null then someone has already bound the variable in that slot at
-                       // the shadow 'shadow.shadowId'.  If our 'lastMatchedShadowId' is not the same as 'shadow.shadowId'
-                       // then this pointcut wasn't involved in matching and so shouldn't contribute to binding - so just
-                       // return Literal.TRUE meaning 'no residue'
-                   if (lastMatchedShadowId != shadow.shadowId) return Literal.TRUE;
-                       state.setErroneousVar(btp.getFormalIndex());
-                 }
-               }
                return exposeStateForVar(var, type, state, shadow.getIWorld());
        }
 
index fc87efde1c76ef3ee01e3a8066bf82530580f4c0..c15d35787e93dd851ddc9986387542f36b1d31be 100644 (file)
@@ -137,18 +137,6 @@ public class WithinAnnotationPointcut extends NameBindingPointcut {
                         "]  shadow=["+shadow+" at "+shadow.getSourceLocation()+
                                                   "]    pointcut is at ["+getSourceLocation()+"]");
                        
-                       // Check if we have already bound something to this formal
-                       if ((state.get(btp.getFormalIndex())!=null)  &&(lastMatchedShadowId == shadow.shadowId)) {
-//                             ISourceLocation pcdSloc = getSourceLocation(); 
-//                             ISourceLocation shadowSloc = shadow.getSourceLocation();
-//                             Message errorMessage = new Message(
-//                                     "Cannot use @pointcut to match at this location and bind a formal to type '"+var.getType()+
-//                                     "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
-//                                     ".  The secondary source location points to the problematic binding.",
-//                                     shadowSloc,true,new ISourceLocation[]{pcdSloc}); 
-//                             shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
-                               state.setErroneousVar(btp.getFormalIndex());
-                       }
                        state.set(btp.getFormalIndex(),var);
                } 
                return Literal.TRUE;
index 7a4bc988f5dcc7d2963b613c0ff6fa3124df3093..0a67b285e44caee5dfae2ff79b3b53df50482f27 100644 (file)
@@ -150,18 +150,6 @@ public class WithinCodeAnnotationPointcut extends NameBindingPointcut {
                         "]  shadow=["+shadow+" at "+shadow.getSourceLocation()+
                                                   "]    pointcut is at ["+getSourceLocation()+"]");
                                
-                       // Check if we have already bound something to this formal
-                       if ((state.get(btp.getFormalIndex())!=null)  &&(lastMatchedShadowId == shadow.shadowId)) {
-//                             ISourceLocation pcdSloc = getSourceLocation(); 
-//                             ISourceLocation shadowSloc = shadow.getSourceLocation();
-//                             Message errorMessage = new Message(
-//                                     "Cannot use @pointcut to match at this location and bind a formal to type '"+var.getType()+
-//                                     "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
-//                                     ".  The secondary source location points to the problematic binding.",
-//                                     shadowSloc,true,new ISourceLocation[]{pcdSloc}); 
-//                             shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
-                               state.setErroneousVar(btp.getFormalIndex());
-                       }
                        state.set(btp.getFormalIndex(),var);
                } 
                return Literal.TRUE;