]> source.dussan.org Git - aspectj.git/commitdiff
Support for @within(), @withincode() annotation binding.
authoraclement <aclement>
Thu, 17 Feb 2005 09:11:59 +0000 (09:11 +0000)
committeraclement <aclement>
Thu, 17 Feb 2005 09:11:59 +0000 (09:11 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java

index 9427e1c3ee2becd8a158a1c2c91db1ef20a33166..edeb4f05f1fb2fce79cf6f9ef7e1e00be08afefe 100644 (file)
@@ -1316,7 +1316,7 @@ public class BcelShadow extends Shadow {
        // Then create one BcelVar entry in the map for each annotation, keyed by
        // annotation type (TypeX).
        
-       // !!! PREAJ5FINAL Refactor these once all shadow kinds added - there is lots of commonality
+       // FIXME Refactor these once all shadow kinds added - there is lots of commonality
        ResolvedTypeX[] annotations = null;
        TypeX relevantType = null;
        
@@ -1412,12 +1412,28 @@ public class BcelShadow extends Shadow {
     public void initializeWithinAnnotationVars() {
        if (withinAnnotationVars != null) return;
        withinAnnotationVars = new HashMap();
-       // populate
+       
+       ResolvedTypeX[] annotations = getEnclosingType().getAnnotationTypes();
+               for (int i = 0; i < annotations.length; i++) {
+                       ResolvedTypeX ann = annotations[i];
+                       Kind k = Shadow.StaticInitialization;
+                       withinAnnotationVars.put(ann,new KindedAnnotationAccessVar(k,ann,getEnclosingType(),null));
+               }
     }
+    
     public void initializeWithinCodeAnnotationVars() {
        if (withincodeAnnotationVars != null) return;
        withincodeAnnotationVars = new HashMap();
-       // populate
+    
+       // For some shadow we are interested in annotations on the method containing that shadow.
+               ResolvedTypeX[] annotations = getEnclosingMethod().getMemberView().getAnnotationTypes();
+               for (int i = 0; i < annotations.length; i++) {
+                       ResolvedTypeX ann = annotations[i];
+                       Kind k = (getEnclosingMethod().getMemberView().getKind()==Member.CONSTRUCTOR?
+                                         Shadow.ConstructorExecution:Shadow.MethodExecution);
+                       withincodeAnnotationVars.put(ann,
+                                       new KindedAnnotationAccessVar(k,ann,getEnclosingType(),getEnclosingCodeSignature()));
+               }
     }
     
             
index 7dc8c60f307e349ec0897af9e3d18b9be40ce6a7..1ae0e1db9fe7b0451cec5666490963ad3e8e356a 100644 (file)
@@ -20,6 +20,7 @@ import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
 import org.aspectj.util.FuzzyBoolean;
+import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.ResolvedTypeX;
@@ -117,7 +118,14 @@ public class WithinAnnotationPointcut extends NameBindingPointcut {
                        BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)annotationTypePattern;
                        TypeX annotationType = btp.annotationType;
                        Var var = shadow.getWithinAnnotationVar(annotationType);
-                       if (var == null) return Literal.FALSE;
+                       
+                       // This should not happen, we shouldn't have gotten this far 
+                       // if we weren't going to find the annotation
+                       if (var == null) 
+                               throw new BCException("Impossible! annotation=["+annotationType+
+                        "]  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(); 
index b91ee20e3d5789771a3c39f223927f85b6e4019b..163a83fb05c5384e198623574d420374211bceaf 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.AnnotatedElement;
+import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.Member;
@@ -130,7 +131,14 @@ public class WithinCodeAnnotationPointcut extends NameBindingPointcut {
                        BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)annotationTypePattern;
                        TypeX annotationType = btp.annotationType;
                        Var var = shadow.getWithinCodeAnnotationVar(annotationType);
-                       if (var == null) return Literal.FALSE;
+       
+                       // This should not happen, we shouldn't have gotten this far 
+                       // if we weren't going to find the annotation
+                       if (var == null) 
+                               throw new BCException("Impossible! annotation=["+annotationType+
+                        "]  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();