Browse Source

Support for @within(), @withincode() annotation binding.

tags/V1_5_0M2
aclement 19 years ago
parent
commit
479d5a8d83

+ 19
- 3
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java View 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()));
}
}

+ 9
- 1
weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java View 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();

+ 9
- 1
weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java View 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();

Loading…
Cancel
Save