From: aclement Date: Thu, 17 Feb 2005 09:11:59 +0000 (+0000) Subject: Support for @within(), @withincode() annotation binding. X-Git-Tag: V1_5_0M2~154 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=479d5a8d83a5e30047900c2d878c457a67d6ef65;p=aspectj.git Support for @within(), @withincode() annotation binding. --- diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 9427e1c3e..edeb4f05f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -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())); + } } diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java index 7dc8c60f3..1ae0e1db9 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java @@ -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(); diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java index b91ee20e3..163a83fb0 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java @@ -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();