]> source.dussan.org Git - aspectj.git/commitdiff
early "parameterizeWith" support for pointcuts
authoracolyer <acolyer>
Thu, 11 Aug 2005 15:29:35 +0000 (15:29 +0000)
committeracolyer <acolyer>
Thu, 11 Aug 2005 15:29:35 +0000 (15:29 +0000)
weaver/src/org/aspectj/weaver/patterns/AndPointcut.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java
weaver/src/org/aspectj/weaver/patterns/NotPointcut.java
weaver/src/org/aspectj/weaver/patterns/OrPointcut.java
weaver/src/org/aspectj/weaver/patterns/Pointcut.java
weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java
weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java

index c046f6be8da8126efa96d2d57945a725653a0dae..ed74f33c836eec7450e00235d9d82976b62cca4e 100644 (file)
@@ -17,6 +17,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Member;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.lang.JoinPoint;
@@ -141,6 +142,13 @@ public class AndPointcut extends Pointcut {
                ret.copyLocationFrom(this);
                return ret;
        }
+       
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               AndPointcut ret =  new AndPointcut(left.parameterizeWith(typeVariableMap),
+                                                                                   right.parameterizeWith(typeVariableMap));
+               ret.copyLocationFrom(this);
+               return ret;
+       }
 
        public Pointcut getLeft() {
                return left;
index c0e5abbdf66cccaa16391746f9e2b0dc2fc17edc..f641d8f8ca10249b741d5ad721d5394bae8cdb6b 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Member;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.IMessage;
@@ -379,6 +380,11 @@ public class IfPointcut extends Pointcut {
                return ret;
        }
 
+       // we can't touch "if" methods
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               return this;
+       }
+       
 //     public static Pointcut MatchesNothing = new MatchesNothingPointcut();
 //     ??? there could possibly be some good optimizations to be done at this point
        public static IfPointcut makeIfFalsePointcut(State state) {
index 655ed1bbd0eef7e8b7573ac350c65d358991b55f..c2d6658e47b7b91a539873da07ec3dc49f58c99a 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.weaver.patterns;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.ISourceLocation;
@@ -395,6 +396,12 @@ public class KindedPointcut extends Pointcut {
         ret.copyLocationFrom(this);
         return ret;
        }
+       
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               Pointcut ret = new KindedPointcut(kind, signature.parameterizeWith(typeVariableMap), munger );
+        ret.copyLocationFrom(this);
+        return ret;
+       }
 
        public Shadow.Kind getKind() {
                return kind;
index 7687750bf73f89e376438458e5727512e445f810..4c727bd9c0e1405fd2eed5442a3979ff5711e801 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.weaver.patterns;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Member;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.lang.JoinPoint;
@@ -136,6 +137,12 @@ public class NotPointcut extends Pointcut {
                ret.copyLocationFrom(this);
                return ret;
        }
+       
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               Pointcut ret = new NotPointcut(body.parameterizeWith(typeVariableMap));
+               ret.copyLocationFrom(this);
+               return ret;
+       }
 
     public Object accept(PatternNodeVisitor visitor, Object data) {
         return visitor.visit(this, data);
index 7801227c31f833055a9f6934f3513374c09f38b1..ad3eec289428c10b24ce6327590f953386bd2f56 100644 (file)
@@ -17,6 +17,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Member;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.lang.JoinPoint;
@@ -144,6 +145,13 @@ public class OrPointcut extends Pointcut {
                return ret;
        }
        
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               Pointcut ret = new OrPointcut(left.parameterizeWith(typeVariableMap),
+                                                                         right.parameterizeWith(typeVariableMap));
+               ret.copyLocationFrom(this);
+               return ret;
+       }
+       
        public Pointcut getLeft() {
                return left;
        }
index 2cb14cca3bf4e3ec73aa57ffa58c01b829b152cb..d752c98ae64edd23d4e954032664c3307b282557 100644 (file)
@@ -17,6 +17,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Member;
 import java.util.Collections;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.lang.JoinPoint;
@@ -438,6 +439,10 @@ public abstract class Pointcut extends PatternNode implements PointcutExpression
         public Object accept(PatternNodeVisitor visitor, Object data) {
             return visitor.visit(this, data);
         }
+        
+        public Pointcut parameterizeWith(Map typeVariableMap) {
+               return this;
+        }
        }
     
     //public static Pointcut MatchesNothing = new MatchesNothingPointcut();
@@ -454,6 +459,10 @@ public abstract class Pointcut extends PatternNode implements PointcutExpression
                        throw new BCException("expected state: " + state + " got: " + this.state);
                }
        }
+       
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               throw new UnsupportedOperationException("this method needs to be defined in all subtypes and then made abstract when the work is complete");
+       }
 
 
 }
index f6baf83b85813a52515f49ce31d60447fb7712d0..4e8803626bf2459555ceaf60e5c07fc9e23a63d3 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.weaver.patterns;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Modifier;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.IMessage;
@@ -43,6 +44,11 @@ public class ReferencePointcut extends Pointcut {
        public String name;
        public TypePatternList arguments;
        
+       /**
+        * if this is non-null then when the pointcut is concretized the result will be parameterized too.
+        */
+       private Map typeVariableMap;
+       
        //public ResolvedPointcut binding;
        
        public ReferencePointcut(TypePattern onTypeSymbolic, String name, TypePatternList arguments) {
@@ -287,7 +293,9 @@ public class ReferencePointcut extends Pointcut {
                        newBindings.copyContext(bindings);
                        newBindings.pushEnclosingDefinition(pointcutDec);
                        try {
-                               return pointcutDec.getPointcut().concretize(searchStart, newBindings);
+                               Pointcut ret = pointcutDec.getPointcut();
+                               if (typeVariableMap != null) ret = ret.parameterizeWith(typeVariableMap);
+                               return ret.concretize(searchStart, newBindings);
                        } finally {
                                newBindings.popEnclosingDefinitition();
                        }
@@ -296,7 +304,19 @@ public class ReferencePointcut extends Pointcut {
                        concretizing = false;
                }
        }
-    
+
+       /**
+        * make a version of this pointcut with any refs to typeVariables replaced by their entry in the map.
+        * Tricky thing is, we can't do this at the point in time this method will be called, so we make a
+        * version that will parameterize the pointcut it ultimately resolves to.
+        */
+       public Pointcut parameterizeWith(Map typeVariableMap) {
+               ReferencePointcut ret = new ReferencePointcut(onType,name,arguments);
+               ret.onTypeSymbolic = onTypeSymbolic;
+               ret.typeVariableMap = typeVariableMap;
+               return ret;
+       }
+       
     // We want to keep the original source location, not the reference location
     protected boolean shouldCopyLocationForConcretize() {
         return false;
index 6c9d19d6b7b40856a71208f766e360d6f3d07c40..37c0266c11b4f1c816c0d6731b95b235c969d674 100644 (file)
@@ -12,6 +12,7 @@ package org.aspectj.weaver.patterns;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.lang.JoinPoint;
@@ -59,6 +60,10 @@ public class PointcutTestCase extends TestCase {
                        protected Pointcut concretize1(ResolvedType inAspect, IntMap bindings) {
                                return null;
                        }
+                       
+                       public Pointcut parameterizeWith(Map typeVariableMap) {
+                               return null;
+                       }
 
                        protected Test findResidueInternal(Shadow shadow, ExposedState state) {
                                return null;