From d09fb718207be8b9a920f060b439eb89e1b1b544 Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 25 Apr 2006 12:05:43 +0000 Subject: [PATCH] fix for 138215 :- we need to resolve the pointcut expressions associated with declare warning / error from an @AJ declaration *after* all the pointcut attributes have been processed. --- .../aspectj/weaver/bcel/AtAjAttributes.java | 16 +--------- .../aspectj/weaver/bcel/BcelObjectType.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index 397e8951c..bc63e0d8a 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -1236,17 +1236,10 @@ public class AtAjAttributes { reportError("@DeclareError used on a non String constant field", struct); return false; } - FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; - IScope binding = new BindingScope( - struct.enclosingType, - struct.context, - bindings - ); Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct, false); if (pc == null) { hasError = false;//cannot parse pointcut - } else { - pc .resolve(binding); + } else { DeclareErrorOrWarning deow = new DeclareErrorOrWarning(true, pc, struct.field.getConstantValue().toString()); setDeclareErrorOrWarningLocation(deow,struct); struct.ajAttributes.add(new AjAttribute.DeclareAttribute(deow)); @@ -1263,17 +1256,10 @@ public class AtAjAttributes { reportError("@DeclareWarning used on a non String constant field", struct); return false; } - FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; - IScope binding = new BindingScope( - struct.enclosingType, - struct.context, - bindings - ); Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct, false); if (pc == null) { hasWarning = false;//cannot parse pointcut } else { - pc.resolve(binding); DeclareErrorOrWarning deow = new DeclareErrorOrWarning(false, pc, struct.field.getConstantValue().toString()); setDeclareErrorOrWarningLocation(deow,struct); struct.ajAttributes.add(new AjAttribute.DeclareAttribute(deow)); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 2bcd7a7d3..d48eaa8f8 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -48,7 +48,12 @@ import org.aspectj.weaver.TypeVariable; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.WeaverStateInfo; import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.AtAjAttributes.BindingScope; import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException; +import org.aspectj.weaver.patterns.Declare; +import org.aspectj.weaver.patterns.DeclareErrorOrWarning; +import org.aspectj.weaver.patterns.FormalBinding; +import org.aspectj.weaver.patterns.IScope; import org.aspectj.weaver.patterns.PerClause; public class BcelObjectType extends AbstractReferenceTypeDelegate { @@ -304,6 +309,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { this.pointcuts = (ResolvedPointcutDefinition[]) pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]); + + resolveAnnotationDeclares(l); if (deferredAspectAttribute != null) { // we can finally process the aspect and its associated perclause... @@ -348,6 +355,29 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { } return deferredAspectAttribute; } + + /** + * Extra processing step needed because declares that come from annotations are not pre-resolved. + * We can't do the resolution until *after* the pointcuts have been resolved. + * @param attributeList + */ + private void resolveAnnotationDeclares(List attributeList) { + FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; + IScope bindingScope = new BindingScope( + getResolvedTypeX(), + getResolvedTypeX().getSourceContext(), + bindings + ); + for (Iterator iter = attributeList.iterator(); iter.hasNext();) { + AjAttribute a = (AjAttribute) iter.next(); + if (a instanceof AjAttribute.DeclareAttribute) { + Declare decl = (((AjAttribute.DeclareAttribute)a).getDeclare()); + if (decl instanceof DeclareErrorOrWarning) { + decl.resolve(bindingScope); + } + } + } + } public PerClause getPerClause() { ensureAspectJAttributesUnpacked(); -- 2.39.5