diff options
author | aclement <aclement> | 2008-09-04 23:29:49 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-09-04 23:29:49 +0000 |
commit | 31a415662a0ffa6f0425e5096e04fc1902726c9e (patch) | |
tree | 0a00982ef69f27c0dbafb5e8103c0f11a0126537 | |
parent | ec9ebe73bbce1ac45e064be0ebd287b3563d4835 (diff) | |
download | aspectj-31a415662a0ffa6f0425e5096e04fc1902726c9e.tar.gz aspectj-31a415662a0ffa6f0425e5096e04fc1902726c9e.zip |
breaking the weaver apart
24 files changed, 2045 insertions, 2237 deletions
diff --git a/weaver/src/org/aspectj/weaver/Advice.java b/weaver/src/org/aspectj/weaver/Advice.java index 731ee9b86..b63fff6cb 100644 --- a/weaver/src/org/aspectj/weaver/Advice.java +++ b/weaver/src/org/aspectj/weaver/Advice.java @@ -30,6 +30,7 @@ public abstract class Advice extends ShadowMunger { protected AdviceKind kind; // alias of attribute.getKind() protected Member signature; + protected boolean hasMatchedAtLeastOnce = false; // not necessarily declaring aspect, this is a semantics change from 1.0 protected ResolvedType concreteAspect; // null until after concretize @@ -416,4 +417,14 @@ public abstract class Advice extends ShadowMunger { return concreteAspect; } + public boolean hasMatchedSomething() { + return hasMatchedAtLeastOnce; + } + + public void setHasMatchedSomething(boolean hasMatchedSomething) { + hasMatchedAtLeastOnce = hasMatchedSomething; + } + + public abstract boolean hasDynamicTests(); + } diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java index e42b93501..e78dbe77f 100644 --- a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java +++ b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java @@ -27,7 +27,6 @@ import org.aspectj.asm.IRelationshipMap; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.SourceLocation; -import org.aspectj.weaver.bcel.BcelAdvice; public class AsmRelationshipProvider { @@ -183,7 +182,7 @@ public class AsmRelationshipProvider { IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow); if (targetNode == null) return; - boolean runtimeTest = ((BcelAdvice) munger).hasDynamicTests(); + boolean runtimeTest = advice.hasDynamicTests(); // Work out extra info to inform interested UIs ! IProgramElement.ExtraInformation ai = new IProgramElement.ExtraInformation(); diff --git a/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java b/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java index 1a3fb248c..524d091be 100644 --- a/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java @@ -124,4 +124,21 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab } public abstract ConcreteTypeMunger parameterizeWith(Map parameterizationMap, World world); + + /** + * Some type mungers are created purely to help with the implementation of shadow mungers. For example to support the cflow() + * pointcut we create a new cflow field in the aspect, and that is added via a BcelCflowCounterFieldAdder. + * + * During compilation we need to compare sets of type mungers, and if some only come into existence after the 'shadowy' type + * things have been processed, we need to ignore them during the comparison. + * + * Returning true from this method indicates the type munger exists to support 'shadowy' stuff - and so can be ignored in some + * comparison. + */ + public boolean existsToSupportShadowMunging() { + if (munger != null) { + return munger.existsToSupportShadowMunging(); + } + return false; + } } diff --git a/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java b/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java index 783bacbb5..4d21667cc 100644 --- a/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java +++ b/weaver/src/org/aspectj/weaver/CrosscuttingMembers.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.aspectj.weaver.bcel.BcelAdvice; import org.aspectj.weaver.bcel.BcelMethod; import org.aspectj.weaver.bcel.BcelTypeMunger; import org.aspectj.weaver.patterns.Declare; @@ -33,14 +32,12 @@ import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; import org.aspectj.weaver.patterns.PointcutRewriter; - /** - * This holds on to all members that have an invasive effect outside of - * there own compilation unit. These members need to be all gathered up and in - * a world before any weaving can take place. + * This holds on to all members that have an invasive effect outside of there own compilation unit. These members need to be all + * gathered up and in a world before any weaving can take place. * - * They are also important in the compilation process and need to be gathered - * up before the inter-type declaration weaving stage (unsurprisingly). + * They are also important in the compilation process and need to be gathered up before the inter-type declaration weaving stage + * (unsurprisingly). * * All members are concrete. * @@ -49,104 +46,106 @@ import org.aspectj.weaver.patterns.PointcutRewriter; public class CrosscuttingMembers { private ResolvedType inAspect; private World world; - + private PerClause perClause; - + private List shadowMungers = new ArrayList(4); private List typeMungers = new ArrayList(4); - private List lateTypeMungers = new ArrayList(0); + private List lateTypeMungers = new ArrayList(0); private List declareParents = new ArrayList(4); private List declareSofts = new ArrayList(0); private List declareDominates = new ArrayList(4); - + // These are like declare parents type mungers - private List declareAnnotationsOnType = new ArrayList(); - private List declareAnnotationsOnField = new ArrayList(); + private List declareAnnotationsOnType = new ArrayList(); + private List declareAnnotationsOnField = new ArrayList(); private List declareAnnotationsOnMethods = new ArrayList(); // includes ctors - + private boolean shouldConcretizeIfNeeded = true; - + public CrosscuttingMembers(ResolvedType inAspect, boolean shouldConcretizeIfNeeded) { this.inAspect = inAspect; this.world = inAspect.getWorld(); this.shouldConcretizeIfNeeded = shouldConcretizeIfNeeded; } - private Hashtable cflowFields = new Hashtable(); private Hashtable cflowBelowFields = new Hashtable(); - -// public void addConcreteShadowMungers(Collection c) { -// shadowMungers.addAll(c); -// } - + + // public void addConcreteShadowMungers(Collection c) { + // shadowMungers.addAll(c); + // } + public void addConcreteShadowMunger(ShadowMunger m) { // assert m is concrete shadowMungers.add(m); } public void addShadowMungers(Collection c) { - for (Iterator i = c.iterator(); i.hasNext(); ) { - addShadowMunger( (ShadowMunger)i.next() ); + for (Iterator i = c.iterator(); i.hasNext();) { + addShadowMunger((ShadowMunger) i.next()); } } - + private void addShadowMunger(ShadowMunger m) { - if (inAspect.isAbstract()) return; // we don't do mungers for abstract aspects + if (inAspect.isAbstract()) + return; // we don't do mungers for abstract aspects addConcreteShadowMunger(m.concretize(inAspect, world, perClause)); } - + public void addTypeMungers(Collection c) { typeMungers.addAll(c); } - + public void addTypeMunger(ConcreteTypeMunger m) { - if (m == null) throw new Error("FIXME AV - should not happen or what ?");//return; //??? + if (m == null) + throw new Error("FIXME AV - should not happen or what ?");// return; //??? typeMungers.add(m); } - public void addLateTypeMungers(Collection c) { - lateTypeMungers.addAll(c); - } + public void addLateTypeMungers(Collection c) { + lateTypeMungers.addAll(c); + } - public void addLateTypeMunger(ConcreteTypeMunger m) { - lateTypeMungers.add(m); - } + public void addLateTypeMunger(ConcreteTypeMunger m) { + lateTypeMungers.add(m); + } public void addDeclares(Collection c) { - for (Iterator i = c.iterator(); i.hasNext(); ) { - addDeclare( (Declare)i.next() ); + for (Iterator i = c.iterator(); i.hasNext();) { + addDeclare((Declare) i.next()); } } - + public void addDeclare(Declare declare) { // this is not extensible, oh well if (declare instanceof DeclareErrorOrWarning) { - ShadowMunger m = new Checker((DeclareErrorOrWarning)declare); + ShadowMunger m = new Checker((DeclareErrorOrWarning) declare); m.setDeclaringType(declare.getDeclaringType()); addShadowMunger(m); } else if (declare instanceof DeclarePrecedence) { declareDominates.add(declare); } else if (declare instanceof DeclareParents) { - DeclareParents dp = (DeclareParents)declare; + DeclareParents dp = (DeclareParents) declare; exposeTypes(dp.getParents().getExactTypes()); declareParents.add(dp); } else if (declare instanceof DeclareSoft) { - DeclareSoft d = (DeclareSoft)declare; + DeclareSoft d = (DeclareSoft) declare; // Ordered so that during concretization we can check the related munger - ShadowMunger m = Advice.makeSoftener(world, d.getPointcut(), d.getException(),inAspect,d); + ShadowMunger m = Advice.makeSoftener(world, d.getPointcut(), d.getException(), inAspect, d); m.setDeclaringType(d.getDeclaringType()); - Pointcut concretePointcut = d.getPointcut().concretize(inAspect, d.getDeclaringType(), 0,m); + Pointcut concretePointcut = d.getPointcut().concretize(inAspect, d.getDeclaringType(), 0, m); m.pointcut = concretePointcut; declareSofts.add(new DeclareSoft(d.getException(), concretePointcut)); addConcreteShadowMunger(m); } else if (declare instanceof DeclareAnnotation) { - // FIXME asc perf Possible Improvement. Investigate why this is called twice in a weave ? - DeclareAnnotation da = (DeclareAnnotation)declare; - if (da.getAspect() == null) da.setAspect(this.inAspect); + // FIXME asc perf Possible Improvement. Investigate why this is called twice in a weave ? + DeclareAnnotation da = (DeclareAnnotation) declare; + if (da.getAspect() == null) + da.setAspect(this.inAspect); if (da.isDeclareAtType()) { - declareAnnotationsOnType.add(da); + declareAnnotationsOnType.add(da); } else if (da.isDeclareAtField()) { declareAnnotationsOnField.add(da); } else if (da.isDeclareAtMethod() || da.isDeclareAtConstuctor()) { @@ -156,18 +155,19 @@ public class CrosscuttingMembers { throw new RuntimeException("unimplemented"); } } - + public void exposeTypes(Collection typesToExpose) { - for (Iterator i = typesToExpose.iterator(); i.hasNext(); ) { - exposeType((UnresolvedType)i.next()); + for (Iterator i = typesToExpose.iterator(); i.hasNext();) { + exposeType((UnresolvedType) i.next()); } } - + public void exposeType(UnresolvedType typeToExpose) { - if (ResolvedType.isMissing(typeToExpose)) return; + if (ResolvedType.isMissing(typeToExpose)) + return; if (typeToExpose.isParameterizedType() || typeToExpose.isRawType()) { if (typeToExpose instanceof ResolvedType) { - typeToExpose = ((ResolvedType)typeToExpose).getGenericType(); + typeToExpose = ((ResolvedType) typeToExpose).getGenericType(); } else { typeToExpose = UnresolvedType.forSignature(typeToExpose.getErasureSignature()); } @@ -177,37 +177,36 @@ public class CrosscuttingMembers { for (Iterator iterator = typeMungers.iterator(); iterator.hasNext();) { ConcreteTypeMunger cTM = (ConcreteTypeMunger) iterator.next(); ResolvedTypeMunger rTM = cTM.getMunger(); - if (rTM!=null && rTM instanceof ExposeTypeMunger) { - String exposedType = ((ExposeTypeMunger)rTM).getExposedTypeSignature(); - if (exposedType.equals(signatureToLookFor)) return; // dont need to bother + if (rTM != null && rTM instanceof ExposeTypeMunger) { + String exposedType = ((ExposeTypeMunger) rTM).getExposedTypeSignature(); + if (exposedType.equals(signatureToLookFor)) + return; // dont need to bother } } addTypeMunger(world.concreteTypeMunger(new ExposeTypeMunger(typeToExpose), inAspect)); -// ResolvedMember member = new ResolvedMemberImpl( -// Member.STATIC_INITIALIZATION, typeToExpose, 0, ResolvedType.VOID, "<clinit>", UnresolvedType.NONE); -// addTypeMunger(world.concreteTypeMunger( -// new PrivilegedAccessMunger(member), inAspect)); + // ResolvedMember member = new ResolvedMemberImpl( + // Member.STATIC_INITIALIZATION, typeToExpose, 0, ResolvedType.VOID, "<clinit>", UnresolvedType.NONE); + // addTypeMunger(world.concreteTypeMunger( + // new PrivilegedAccessMunger(member), inAspect)); } - + public void addPrivilegedAccesses(Collection accessedMembers) { - for (Iterator i = accessedMembers.iterator(); i.hasNext(); ) { - addPrivilegedAccess( (ResolvedMember)i.next() ); + for (Iterator i = accessedMembers.iterator(); i.hasNext();) { + addPrivilegedAccess((ResolvedMember) i.next()); } } private void addPrivilegedAccess(ResolvedMember member) { - //System.err.println("add priv access: " + member); + // System.err.println("add priv access: " + member); addTypeMunger(world.concreteTypeMunger(new PrivilegedAccessMunger(member), inAspect)); } - - public Collection getCflowEntries() { ArrayList ret = new ArrayList(); - for (Iterator i = shadowMungers.iterator(); i.hasNext(); ) { - ShadowMunger m = (ShadowMunger)i.next(); + for (Iterator i = shadowMungers.iterator(); i.hasNext();) { + ShadowMunger m = (ShadowMunger) i.next(); if (m instanceof Advice) { - Advice a = (Advice)m; + Advice a = (Advice) m; if (a.getKind().isCflow()) { ret.add(a); } @@ -217,42 +216,37 @@ public class CrosscuttingMembers { } /** - * Updates the records if something has changed. This is called at most twice, firstly - * whilst collecting ITDs and declares. At this point the CrosscuttingMembers we're - * comparing ourselves with doesn't know about shadowmungers. Therefore a straight comparison - * with the existing list of shadowmungers would return that something has changed - * even though it might not have, so in this first round we ignore the shadowMungers. - * The second time this is called is whilst we're preparing to weave. At this point - * we know everything in the system and so we're able to compare the shadowMunger list. - * (see bug 129163) + * Updates the records if something has changed. This is called at most twice, firstly whilst collecting ITDs and declares. At + * this point the CrosscuttingMembers we're comparing ourselves with doesn't know about shadowmungers. Therefore a straight + * comparison with the existing list of shadowmungers would return that something has changed even though it might not have, so + * in this first round we ignore the shadowMungers. The second time this is called is whilst we're preparing to weave. At this + * point we know everything in the system and so we're able to compare the shadowMunger list. (see bug 129163) * * @param other * @param careAboutShadowMungers - * @return true if something has changed since the last time this method was - * called, false otherwise + * @return true if something has changed since the last time this method was called, false otherwise */ - public boolean replaceWith(CrosscuttingMembers other,boolean careAboutShadowMungers) { + public boolean replaceWith(CrosscuttingMembers other, boolean careAboutShadowMungers) { boolean changed = false; - + if (careAboutShadowMungers) { if (perClause == null || !perClause.equals(other.perClause)) { changed = true; perClause = other.perClause; } } - - //XXX all of the below should be set equality rather than list equality - //System.err.println("old: " + shadowMungers + " new: " + other.shadowMungers); - - if (careAboutShadowMungers) { - // bug 129163: use set equality rather than list equality + + // XXX all of the below should be set equality rather than list equality + // System.err.println("old: " + shadowMungers + " new: " + other.shadowMungers); + + if (careAboutShadowMungers) { + // bug 129163: use set equality rather than list equality Set theseShadowMungers = new HashSet(); Set theseInlinedAroundMungers = new HashSet(); - for (Iterator iter = shadowMungers.iterator(); iter - .hasNext();) { + for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); if (munger instanceof Advice) { - Advice adviceMunger = (Advice)munger; + Advice adviceMunger = (Advice) munger; // bug 154054: if we're around advice that has been inlined // then we need to do more checking than existing equals // methods allow @@ -272,7 +266,7 @@ public class CrosscuttingMembers { for (Iterator iter = tempSet.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); if (munger instanceof Advice) { - Advice adviceMunger = (Advice)munger; + Advice adviceMunger = (Advice) munger; // bug 154054: if we're around advice that has been inlined // then we need to do more checking than existing equals // methods allow @@ -288,34 +282,33 @@ public class CrosscuttingMembers { if (!theseShadowMungers.equals(otherShadowMungers)) { changed = true; } - if (!equivalent(theseInlinedAroundMungers,otherInlinedAroundMungers)) { + if (!equivalent(theseInlinedAroundMungers, otherInlinedAroundMungers)) { changed = true; } - + // bug 158573 - if there are no changes then preserve whether // or not a particular shadowMunger has matched something. if (!changed) { - for (Iterator iter = shadowMungers.iterator(); iter - .hasNext();) { + for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); int i = other.shadowMungers.indexOf(munger); ShadowMunger otherMunger = (ShadowMunger) other.shadowMungers.get(i); - if (munger instanceof BcelAdvice) { - ((BcelAdvice)otherMunger).setHasMatchedSomething(((BcelAdvice)munger).hasMatchedSomething()); + if (munger instanceof Advice) { + ((Advice) otherMunger).setHasMatchedSomething(((Advice) munger).hasMatchedSomething()); } } - } - // replace the existing list of shadowmungers with the + } + // replace the existing list of shadowmungers with the // new ones in case anything like the sourcelocation has // changed, however, don't want this flagged as a change // which will force a full build - bug 134541 - shadowMungers = other.shadowMungers; - } - + shadowMungers = other.shadowMungers; + } + // bug 129163: use set equality rather than list equality and - // if we dont care about shadow mungers then ignore those - // typeMungers which are created to help with the implementation - // of shadowMungers + // if we dont care about shadow mungers then ignore those + // typeMungers which are created to help with the implementation + // of shadowMungers Set theseTypeMungers = new HashSet(); Set otherTypeMungers = new HashSet(); if (!careAboutShadowMungers) { @@ -325,12 +318,12 @@ public class CrosscuttingMembers { BcelTypeMunger typeMunger = (BcelTypeMunger) o; if (!typeMunger.existsToSupportShadowMunging()) { theseTypeMungers.add(typeMunger); - } + } } else { theseTypeMungers.add(o); } } - + for (Iterator iter = other.typeMungers.iterator(); iter.hasNext();) { Object o = iter.next(); if (o instanceof BcelTypeMunger) { @@ -346,80 +339,80 @@ public class CrosscuttingMembers { theseTypeMungers.addAll(typeMungers); otherTypeMungers.addAll(other.typeMungers); } - - // initial go at equivalence logic rather than set compare (see pr133532) -// if (theseTypeMungers.size()!=otherTypeMungers.size()) { -// changed = true; -// typeMungers = other.typeMungers; -// } else { -// boolean foundInequality=false; -// for (Iterator iter = theseTypeMungers.iterator(); iter.hasNext() && !foundInequality;) { -// Object thisOne = (Object) iter.next(); -// boolean foundInOtherSet = false; -// for (Iterator iterator = otherTypeMungers.iterator(); iterator.hasNext();) { -// Object otherOne = (Object) iterator.next(); -// if (thisOne instanceof ConcreteTypeMunger && otherOne instanceof ConcreteTypeMunger) { -// if (((ConcreteTypeMunger)thisOne).equivalentTo(otherOne)) { -// foundInOtherSet=true; -// } else if (thisOne.equals(otherOne)) { -// foundInOtherSet=true; -// } -// } else { -// if (thisOne.equals(otherOne)) { -// foundInOtherSet=true; -// } -// } -// } -// if (!foundInOtherSet) foundInequality=true; -// } -// if (foundInequality) { -// changed = true; -// typeMungers = other.typeMungers; -//// } else { -//// typeMungers = other.typeMungers; -// } -// } - if (!theseTypeMungers.equals(otherTypeMungers)) { + + // initial go at equivalence logic rather than set compare (see pr133532) + // if (theseTypeMungers.size()!=otherTypeMungers.size()) { + // changed = true; + // typeMungers = other.typeMungers; + // } else { + // boolean foundInequality=false; + // for (Iterator iter = theseTypeMungers.iterator(); iter.hasNext() && !foundInequality;) { + // Object thisOne = (Object) iter.next(); + // boolean foundInOtherSet = false; + // for (Iterator iterator = otherTypeMungers.iterator(); iterator.hasNext();) { + // Object otherOne = (Object) iterator.next(); + // if (thisOne instanceof ConcreteTypeMunger && otherOne instanceof ConcreteTypeMunger) { + // if (((ConcreteTypeMunger)thisOne).equivalentTo(otherOne)) { + // foundInOtherSet=true; + // } else if (thisOne.equals(otherOne)) { + // foundInOtherSet=true; + // } + // } else { + // if (thisOne.equals(otherOne)) { + // foundInOtherSet=true; + // } + // } + // } + // if (!foundInOtherSet) foundInequality=true; + // } + // if (foundInequality) { + // changed = true; + // typeMungers = other.typeMungers; + // // } else { + // // typeMungers = other.typeMungers; + // } + // } + if (!theseTypeMungers.equals(otherTypeMungers)) { changed = true; typeMungers = other.typeMungers; } - if (!lateTypeMungers.equals(other.lateTypeMungers)) { - changed = true; - lateTypeMungers = other.lateTypeMungers; - } + if (!lateTypeMungers.equals(other.lateTypeMungers)) { + changed = true; + lateTypeMungers = other.lateTypeMungers; + } if (!declareDominates.equals(other.declareDominates)) { changed = true; declareDominates = other.declareDominates; } - + if (!declareParents.equals(other.declareParents)) { changed = true; declareParents = other.declareParents; } - + if (!declareSofts.equals(other.declareSofts)) { changed = true; declareSofts = other.declareSofts; } - + // DECAT for when attempting to replace an aspect if (!declareAnnotationsOnType.equals(other.declareAnnotationsOnType)) { changed = true; declareAnnotationsOnType = other.declareAnnotationsOnType; } - + if (!declareAnnotationsOnField.equals(other.declareAnnotationsOnField)) { changed = true; declareAnnotationsOnField = other.declareAnnotationsOnField; } - + if (!declareAnnotationsOnMethods.equals(other.declareAnnotationsOnMethods)) { changed = true; declareAnnotationsOnMethods = other.declareAnnotationsOnMethods; } - + return changed; } @@ -431,14 +424,13 @@ public class CrosscuttingMembers { Advice thisAdvice = (Advice) iter.next(); boolean foundIt = false; for (Iterator iterator = otherInlinedAroundMungers.iterator(); iterator.hasNext();) { - Advice otherAdvice = (Advice) iterator.next(); + Advice otherAdvice = (Advice) iterator.next(); if (thisAdvice.equals(otherAdvice)) { - if(thisAdvice.getSignature() instanceof BcelMethod) { - if (((BcelMethod)thisAdvice.getSignature()) - .isEquivalentTo(otherAdvice.getSignature()) ) { + if (thisAdvice.getSignature() instanceof BcelMethod) { + if (((BcelMethod) thisAdvice.getSignature()).isEquivalentTo(otherAdvice.getSignature())) { foundIt = true; continue; - } + } } return false; } @@ -452,15 +444,15 @@ public class CrosscuttingMembers { private ShadowMunger rewritePointcutInMunger(ShadowMunger munger) { PointcutRewriter pr = new PointcutRewriter(); - Pointcut p = munger.getPointcut(); - Pointcut newP = pr.rewrite(p); - if (p.m_ignoreUnboundBindingForNames.length!=0) {// *sigh* dirty fix for dirty hacky implementation pr149305 + Pointcut p = munger.getPointcut(); + Pointcut newP = pr.rewrite(p); + if (p.m_ignoreUnboundBindingForNames.length != 0) {// *sigh* dirty fix for dirty hacky implementation pr149305 newP.m_ignoreUnboundBindingForNames = p.m_ignoreUnboundBindingForNames; } munger.setPointcut(newP); return munger; } - + public void setPerClause(PerClause perClause) { if (this.shouldConcretizeIfNeeded) { this.perClause = perClause.concretize(inAspect); @@ -489,21 +481,21 @@ public class CrosscuttingMembers { return typeMungers; } - public List getLateTypeMungers() { - return lateTypeMungers; - } + public List getLateTypeMungers() { + return lateTypeMungers; + } public List getDeclareAnnotationOnTypes() { return declareAnnotationsOnType; } - + public List getDeclareAnnotationOnFields() { return declareAnnotationsOnField; } - - /** - * includes declare @method and @constructor - */ + + /** + * includes declare @method and @constructor + */ public List getDeclareAnnotationOnMethods() { return declareAnnotationsOnMethods; } @@ -515,7 +507,7 @@ public class CrosscuttingMembers { public Map getCflowFields() { return cflowFields; } - + public void clearCaches() { cflowFields.clear(); cflowBelowFields.clear(); diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index eec19ac69..346d60ff3 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -32,7 +32,6 @@ import org.aspectj.lang.JoinPoint; import org.aspectj.util.PartialOrder; import org.aspectj.util.TypeSafeEnum; import org.aspectj.weaver.ast.Var; -import org.aspectj.weaver.bcel.BcelAdvice; /* * The superclass of anything representing a the shadow of a join point. A shadow represents @@ -553,9 +552,9 @@ public abstract class Shadow { Object b = mungers.get(j); // Make sure they are the right type - if (a instanceof BcelAdvice && b instanceof BcelAdvice) { - BcelAdvice adviceA = (BcelAdvice) a; - BcelAdvice adviceB = (BcelAdvice) b; + if (a instanceof Advice && b instanceof Advice) { + Advice adviceA = (Advice) a; + Advice adviceB = (Advice) b; if (!adviceA.concreteAspect.equals(adviceB.concreteAspect)) { AdviceKind adviceKindA = adviceA.getKind(); AdviceKind adviceKindB = adviceB.getKind(); @@ -678,7 +677,7 @@ public abstract class Shadow { beautifyLocation(getSourceLocation()), advisingType, beautifyLocation(munger.getSourceLocation()) }, advisedType, advisingType); } else { - boolean runtimeTest = ((BcelAdvice) advice).hasDynamicTests(); + boolean runtimeTest = advice.hasDynamicTests(); String joinPointDescription = this.toString(); msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ADVISES, new String[] { joinPointDescription, advisedType, beautifyLocation(getSourceLocation()), description, advisingType, @@ -739,7 +738,7 @@ public abstract class Shadow { world.getCrossReferenceHandler().addCrossReference(munger.getSourceLocation(), // What is being applied this.getSourceLocation(), // Where is it being applied determineRelKind(munger), // What kind of advice? - ((BcelAdvice) munger).hasDynamicTests() // Is a runtime test being stuffed in the code? + ((Advice) munger).hasDynamicTests() // Is a runtime test being stuffed in the code? ); } diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java index 1328f02ae..2154c1d09 100644 --- a/weaver/src/org/aspectj/weaver/ShadowMunger.java +++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver; import java.io.File; @@ -26,26 +25,22 @@ import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.SourceLocation; import org.aspectj.util.PartialOrder; -import org.aspectj.weaver.bcel.BcelAdvice; import org.aspectj.weaver.patterns.DeclareErrorOrWarning; import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; /** - * For every shadow munger, nothing can be done with it until it is concretized. Then... + * For every shadow munger, nothing can be done with it until it is concretized. Then... * * (Then we call fast match.) * - * For every shadow munger, for every shadow, - * first match is called, - * then (if match returned true) the shadow munger is specialized for the shadow, - * which may modify state. - * Then implement is called. + * For every shadow munger, for every shadow, first match is called, then (if match returned true) the shadow munger is specialized + * for the shadow, which may modify state. Then implement is called. */ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IHasPosition { protected Pointcut pointcut; - + // these three fields hold the source location of this munger protected int start, end; protected ISourceContext sourceContext; @@ -53,34 +48,34 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH private ISourceLocation binarySourceLocation; private File binaryFile; private String handle = null; - private ResolvedType declaringType; // the type that declared this munger. + private ResolvedType declaringType; // the type that declared this munger. - public ShadowMunger(Pointcut pointcut, int start, int end, ISourceContext sourceContext) { this.pointcut = pointcut; this.start = start; this.end = end; this.sourceContext = sourceContext; } - - public abstract ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause); - public abstract void specializeOn(Shadow shadow); - public abstract void implementOn(Shadow shadow); - + public abstract ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause); + + public abstract void specializeOn(Shadow shadow); + + public abstract void implementOn(Shadow shadow); + /** * All overriding methods should call super */ - public boolean match(Shadow shadow, World world) { - return pointcut.match(shadow).maybeTrue(); - } - - public abstract ShadowMunger parameterizeWith(ResolvedType declaringType,Map typeVariableMap); - + public boolean match(Shadow shadow, World world) { + return pointcut.match(shadow).maybeTrue(); + } + + public abstract ShadowMunger parameterizeWith(ResolvedType declaringType, Map typeVariableMap); + public int fallbackCompareTo(Object other) { return toString().compareTo(toString()); } - + public int getEnd() { return end; } @@ -88,21 +83,21 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH public int getStart() { return start; } - - public ISourceLocation getSourceLocation() { - if (sourceLocation == null) { - if (sourceContext != null) { + + public ISourceLocation getSourceLocation() { + if (sourceLocation == null) { + if (sourceContext != null) { sourceLocation = sourceContext.makeSourceLocation(this); - } - } - if (isBinary()) { + } + } + if (isBinary()) { if (binarySourceLocation == null) { binarySourceLocation = getBinarySourceLocation(sourceLocation); } return binarySourceLocation; } - return sourceLocation; - } + return sourceLocation; + } public String getHandle() { if (null == handle) { @@ -116,15 +111,13 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH } // ---- fields - - public static final ShadowMunger[] NONE = new ShadowMunger[0]; - + public static final ShadowMunger[] NONE = new ShadowMunger[0]; public Pointcut getPointcut() { return pointcut; } - + // pointcut may be updated during rewriting... public void setPointcut(Pointcut pointcut) { this.pointcut = pointcut; @@ -132,78 +125,71 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH /** * Invoked when the shadow munger of a resolved type are processed. + * * @param aType */ public void setDeclaringType(ResolvedType aType) { this.declaringType = aType; } - + public ResolvedType getDeclaringType() { return this.declaringType; } - + /** - * @return a Collection of ResolvedType for all checked exceptions that - * might be thrown by this munger + * @return a Collection of ResolvedType for all checked exceptions that might be thrown by this munger */ public abstract Collection getThrownExceptions(); - /** - * Does the munger has to check that its exception are accepted by the shadow ? - * ATAJ: It s not the case for @AJ around advice f.e. that can throw Throwable, even if the advised - * method does not throw any exceptions. - * @return true if munger has to check that its exceptions can be throwned based on the shadow - */ - public abstract boolean mustCheckExceptions(); - - /** - * Creates the hierarchy for binary aspects - */ - public void createHierarchy() { - if (!isBinary()) return; - - IProgramElement sourceFileNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(getSourceLocation()); - // the call to findElementForSourceLine(ISourceLocation) returns a file node - // if it can't find a node in the hierarchy for the given sourcelocation. - // Therefore, if this is returned, we know we can't find one and have to - // continue to fault in the model. - if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) { + /** + * Does the munger has to check that its exception are accepted by the shadow ? ATAJ: It s not the case for @AJ around advice + * f.e. that can throw Throwable, even if the advised method does not throw any exceptions. + * + * @return true if munger has to check that its exceptions can be throwned based on the shadow + */ + public abstract boolean mustCheckExceptions(); + + /** + * Creates the hierarchy for binary aspects + */ + public void createHierarchy() { + if (!isBinary()) + return; + + IProgramElement sourceFileNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(getSourceLocation()); + // the call to findElementForSourceLine(ISourceLocation) returns a file node + // if it can't find a node in the hierarchy for the given sourcelocation. + // Therefore, if this is returned, we know we can't find one and have to + // continue to fault in the model. + if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) { return; } - - ResolvedType aspect = getDeclaringType(); - - // create the class file node - IProgramElement classFileNode = new ProgramElement( - sourceFileNode.getName() + " (binary)", - IProgramElement.Kind.CLASS, - getBinarySourceLocation(aspect.getSourceLocation()), - 0,null,null); - - // create package ipe if one exists.... - IProgramElement root = AsmManager.getDefault().getHierarchy().getRoot(); - if (aspect.getPackageName() != null) { - // check that there doesn't already exist a node with this name - IProgramElement pkgNode = AsmManager.getDefault().getHierarchy().findElementForLabel( - root,IProgramElement.Kind.PACKAGE,aspect.getPackageName()); - // note packages themselves have no source location - if (pkgNode == null) { - pkgNode = new ProgramElement( - aspect.getPackageName(), - IProgramElement.Kind.PACKAGE, - new ArrayList()); - root.addChild(pkgNode); - pkgNode.addChild(classFileNode); + + ResolvedType aspect = getDeclaringType(); + + // create the class file node + IProgramElement classFileNode = new ProgramElement(sourceFileNode.getName() + " (binary)", IProgramElement.Kind.CLASS, + getBinarySourceLocation(aspect.getSourceLocation()), 0, null, null); + + // create package ipe if one exists.... + IProgramElement root = AsmManager.getDefault().getHierarchy().getRoot(); + if (aspect.getPackageName() != null) { + // check that there doesn't already exist a node with this name + IProgramElement pkgNode = AsmManager.getDefault().getHierarchy().findElementForLabel(root, + IProgramElement.Kind.PACKAGE, aspect.getPackageName()); + // note packages themselves have no source location + if (pkgNode == null) { + pkgNode = new ProgramElement(aspect.getPackageName(), IProgramElement.Kind.PACKAGE, new ArrayList()); + root.addChild(pkgNode); + pkgNode.addChild(classFileNode); } else { // need to add it first otherwise the handle for classFileNode - // may not be generated correctly if it uses information from + // may not be generated correctly if it uses information from // it's parent node pkgNode.addChild(classFileNode); for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) { IProgramElement element = (IProgramElement) iter.next(); - if (!element.equals(classFileNode) && - element.getHandleIdentifier().equals( - classFileNode.getHandleIdentifier())) { + if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { // already added the classfile so have already // added the structure for this aspect pkgNode.removeChild(classFileNode); @@ -213,187 +199,158 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH } } else { // need to add it first otherwise the handle for classFileNode - // may not be generated correctly if it uses information from + // may not be generated correctly if it uses information from // it's parent node root.addChild(classFileNode); for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) { IProgramElement element = (IProgramElement) iter.next(); - if (!element.equals(classFileNode) && - element.getHandleIdentifier().equals( - classFileNode.getHandleIdentifier())) { + if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { // already added the sourcefile so have already // added the structure for this aspect root.removeChild(classFileNode); return; - } + } } } - - // add and create empty import declaration ipe - classFileNode.addChild(new ProgramElement( - "import declarations", - IProgramElement.Kind.IMPORT_REFERENCE, - null,0,null,null)); - - // add and create aspect ipe - IProgramElement aspectNode = new ProgramElement( - aspect.getSimpleName(), - IProgramElement.Kind.ASPECT, - getBinarySourceLocation(aspect.getSourceLocation()), - aspect.getModifiers(), - null,null); - classFileNode.addChild(aspectNode); - - addChildNodes(aspectNode,aspect.getDeclaredPointcuts()); - - addChildNodes(aspectNode,aspect.getDeclaredAdvice()); - addChildNodes(aspectNode,aspect.getDeclares()); - } - - private void addChildNodes(IProgramElement parent,ResolvedMember[] children) { - for (int i = 0; i < children.length; i++) { + + // add and create empty import declaration ipe + classFileNode + .addChild(new ProgramElement("import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null, 0, null, null)); + + // add and create aspect ipe + IProgramElement aspectNode = new ProgramElement(aspect.getSimpleName(), IProgramElement.Kind.ASPECT, + getBinarySourceLocation(aspect.getSourceLocation()), aspect.getModifiers(), null, null); + classFileNode.addChild(aspectNode); + + addChildNodes(aspectNode, aspect.getDeclaredPointcuts()); + + addChildNodes(aspectNode, aspect.getDeclaredAdvice()); + addChildNodes(aspectNode, aspect.getDeclares()); + } + + private void addChildNodes(IProgramElement parent, ResolvedMember[] children) { + for (int i = 0; i < children.length; i++) { ResolvedMember pcd = children[i]; if (pcd instanceof ResolvedPointcutDefinition) { - ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition)pcd; + ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition) pcd; ISourceLocation sLoc = rpcd.getPointcut().getSourceLocation(); if (sLoc == null) { sLoc = rpcd.getSourceLocation(); } - parent.addChild(new ProgramElement( - pcd.getName(), - IProgramElement.Kind.POINTCUT, - getBinarySourceLocation(sLoc), - pcd.getModifiers(), - null, - Collections.EMPTY_LIST)); - } + parent.addChild(new ProgramElement(pcd.getName(), IProgramElement.Kind.POINTCUT, getBinarySourceLocation(sLoc), pcd + .getModifiers(), null, Collections.EMPTY_LIST)); + } } - } - - private void addChildNodes(IProgramElement parent, Collection children) { - int afterCtr = 1; - int aroundCtr = 1; - int beforeCtr = 1; - int deCtr = 1; - int dwCtr = 1; - for (Iterator iter = children.iterator(); iter.hasNext();) { + } + + private void addChildNodes(IProgramElement parent, Collection children) { + int afterCtr = 1; + int aroundCtr = 1; + int beforeCtr = 1; + int deCtr = 1; + int dwCtr = 1; + for (Iterator iter = children.iterator(); iter.hasNext();) { Object element = iter.next(); if (element instanceof DeclareErrorOrWarning) { - DeclareErrorOrWarning decl = (DeclareErrorOrWarning)element; + DeclareErrorOrWarning decl = (DeclareErrorOrWarning) element; int counter = 0; if (decl.isError()) { counter = deCtr++; } else { counter = dwCtr++; } - parent.addChild(createDeclareErrorOrWarningChild(decl,counter)); - } else if (element instanceof BcelAdvice) { - BcelAdvice advice = (BcelAdvice)element; + parent.addChild(createDeclareErrorOrWarningChild(decl, counter)); + } else if (element instanceof Advice) { + Advice advice = (Advice) element; int counter = 0; if (advice.getKind().equals(AdviceKind.Before)) { counter = beforeCtr++; - } else if (advice.getKind().equals(AdviceKind.Around)){ + } else if (advice.getKind().equals(AdviceKind.Around)) { counter = aroundCtr++; } else { counter = afterCtr++; } - parent.addChild(createAdviceChild(advice,counter)); + parent.addChild(createAdviceChild(advice, counter)); } } - } - - private IProgramElement createDeclareErrorOrWarningChild( - DeclareErrorOrWarning decl, int count) { - IProgramElement deowNode = new ProgramElement( - decl.getName(), - decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING, - getBinarySourceLocation(decl.getSourceLocation()), - decl.getDeclaringType().getModifiers(), - null,null); - deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\""); - if (count != -1) { - deowNode.setBytecodeName(decl.getName() + "_" + count); - } - return deowNode; - } - - private IProgramElement createAdviceChild(BcelAdvice advice, int counter ) { - IProgramElement adviceNode = new ProgramElement( - advice.kind.getName(), - IProgramElement.Kind.ADVICE, - getBinarySourceLocation(advice.getSourceLocation()), - advice.signature.getModifiers(),null,Collections.EMPTY_LIST); - adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); - if (counter != 1) { + } + + private IProgramElement createDeclareErrorOrWarningChild(DeclareErrorOrWarning decl, int count) { + IProgramElement deowNode = new ProgramElement(decl.getName(), decl.isError() ? IProgramElement.Kind.DECLARE_ERROR + : IProgramElement.Kind.DECLARE_WARNING, getBinarySourceLocation(decl.getSourceLocation()), decl.getDeclaringType() + .getModifiers(), null, null); + deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\""); + if (count != -1) { + deowNode.setBytecodeName(decl.getName() + "_" + count); + } + return deowNode; + } + + private IProgramElement createAdviceChild(Advice advice, int counter) { + IProgramElement adviceNode = new ProgramElement(advice.kind.getName(), IProgramElement.Kind.ADVICE, + getBinarySourceLocation(advice.getSourceLocation()), advice.signature.getModifiers(), null, Collections.EMPTY_LIST); + adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); + if (counter != 1) { adviceNode.setBytecodeName(advice.getKind().getName() + "$" + counter + "$"); } - return adviceNode; - } - - /** - * Returns the binarySourceLocation for the given sourcelocation. This - * isn't cached because it's used when faulting in the binary nodes - * and is called with ISourceLocations for all advice, pointcuts and deows - * contained within the resolvedDeclaringAspect. - */ - private ISourceLocation getBinarySourceLocation(ISourceLocation sl) { - if (sl == null) return null; - String sourceFileName = null; - if (getDeclaringType() instanceof ReferenceType) { - String s = ((ReferenceType)getDeclaringType()).getDelegate().getSourcefilename(); + return adviceNode; + } + + /** + * Returns the binarySourceLocation for the given sourcelocation. This isn't cached because it's used when faulting in the + * binary nodes and is called with ISourceLocations for all advice, pointcuts and deows contained within the + * resolvedDeclaringAspect. + */ + private ISourceLocation getBinarySourceLocation(ISourceLocation sl) { + if (sl == null) + return null; + String sourceFileName = null; + if (getDeclaringType() instanceof ReferenceType) { + String s = ((ReferenceType) getDeclaringType()).getDelegate().getSourcefilename(); int i = s.lastIndexOf('/'); if (i != -1) { - sourceFileName = s.substring(i+1); + sourceFileName = s.substring(i + 1); } else { sourceFileName = s; } } - ISourceLocation sLoc = new SourceLocation( - getBinaryFile(), - sl.getLine(), - sl.getEndLine(), - ((sl.getColumn() == 0) ? ISourceLocation.NO_COLUMN : sl.getColumn()), - sl.getContext(), - sourceFileName); + ISourceLocation sLoc = new SourceLocation(getBinaryFile(), sl.getLine(), sl.getEndLine(), + ((sl.getColumn() == 0) ? ISourceLocation.NO_COLUMN : sl.getColumn()), sl.getContext(), sourceFileName); return sLoc; - } - - /** - * Returns the File with pathname to the class file, for example either - * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp\simple.jar!pkg\BinaryAspect.class - * if the class file is in a jar file, or - * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp!pkg\BinaryAspect.class - * if the class file is in a directory - */ - private File getBinaryFile() { - if (binaryFile == null) { - String s = getDeclaringType().getBinaryPath(); - File f = getDeclaringType().getSourceLocation().getSourceFile(); - int i = f.getPath().lastIndexOf('.'); - String path = f.getPath().substring(0,i) + ".class"; - binaryFile = new File(s + "!" + path); + } + + /** + * Returns the File with pathname to the class file, for example either + * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp\simple.jar!pkg\BinaryAspect.class if the class file is in a jar file, or + * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp!pkg\BinaryAspect.class if the class file is in a directory + */ + private File getBinaryFile() { + if (binaryFile == null) { + String s = getDeclaringType().getBinaryPath(); + File f = getDeclaringType().getSourceLocation().getSourceFile(); + int i = f.getPath().lastIndexOf('.'); + String path = f.getPath().substring(0, i) + ".class"; + binaryFile = new File(s + "!" + path); } - return binaryFile; - } - - /** - * Returns whether or not this shadow munger came from - * a binary aspect - keep a record of whether or not we've - * checked if we're binary otherwise we keep caluclating the - * same thing many times - */ - protected boolean isBinary() { - if (!checkedIsBinary) { - ResolvedType rt = getDeclaringType(); - if (rt != null) { - isBinary = ((rt.getBinaryPath() == null) ? false : true); - } + return binaryFile; + } + + /** + * Returns whether or not this shadow munger came from a binary aspect - keep a record of whether or not we've checked if we're + * binary otherwise we keep caluclating the same thing many times + */ + protected boolean isBinary() { + if (!checkedIsBinary) { + ResolvedType rt = getDeclaringType(); + if (rt != null) { + isBinary = ((rt.getBinaryPath() == null) ? false : true); + } checkedIsBinary = true; } - return isBinary; - } - - private boolean isBinary; - private boolean checkedIsBinary; - + return isBinary; + } + + private boolean isBinary; + private boolean checkedIsBinary; + } diff --git a/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessFieldVar.java b/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessFieldVar.java index f99d6d6b4..7232cfd64 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessFieldVar.java +++ b/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessFieldVar.java @@ -33,7 +33,7 @@ import org.aspectj.weaver.UnresolvedType; * * @author Andy Clement */ -public class AnnotationAccessFieldVar extends BcelVar { +class AnnotationAccessFieldVar extends BcelVar { private AnnotationAccessVar annoAccessor; private ResolvedType annoFieldOfInterest; @@ -71,7 +71,7 @@ public class AnnotationAccessFieldVar extends BcelVar { if (!doneAndDusted) { ResolvedMember[] annotationFields = toType.getWorld().resolve( UnresolvedType.forSignature(annotation.getTypeSignature())).getDeclaredMethods(); - + // ResolvedMember[] fs = rt.getDeclaredFields(); for (int ii = 0; ii < annotationFields.length; ii++) { if (annotationFields[ii].getType().equals(annoFieldOfInterest)) { diff --git a/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessVar.java b/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessVar.java index 2fdab6937..991dfdda0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessVar.java +++ b/weaver/src/org/aspectj/weaver/bcel/AnnotationAccessVar.java @@ -24,6 +24,7 @@ import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.Shadow.Kind; +import org.aspectj.weaver.ast.Var; /** * Represents access to an annotation on an element, relating to some kinded pointcut. Depending on the kind of pointcut the element @@ -193,4 +194,13 @@ public class AnnotationAccessVar extends BcelVar { return member; } + /** + * Return an object that can access a particular value of this annotation. + * + * @param valueType The type from the annotation that is of interest + * @return a variable that represents access to that annotation value + */ + public Var getAccessorForValue(ResolvedType valueType) { + return new AnnotationAccessFieldVar(this, valueType); + } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 31fcef6dd..59c77e6b4 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -11,7 +11,6 @@ * Alexandre Vasseur support for @AJ aspects * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; @@ -55,123 +54,120 @@ import org.aspectj.weaver.patterns.Pointcut; * @author Erik Hilsdale * @author Jim Hugunin */ -public class BcelAdvice extends Advice { +class BcelAdvice extends Advice { private Test pointcutTest; private ExposedState exposedState; - - private boolean hasMatchedAtLeastOnce = false; - - public BcelAdvice( - AjAttribute.AdviceAttribute attribute, - Pointcut pointcut, - Member signature, - ResolvedType concreteAspect) - { - super(attribute, pointcut,shrink(attribute.getKind(),concreteAspect,signature));// (signature==null?null:signature.slimline())); + + public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member signature, ResolvedType concreteAspect) { + super(attribute, pointcut, shrink(attribute.getKind(), concreteAspect, signature));//(signature==null?null:signature.slimline + // ())); this.concreteAspect = concreteAspect; } + /** - * We don't always need to represent the signature with a heavyweight BcelMethod object - only if its around advice - * and inlining is active - * @param concreteAspect - * @param attribute + * We don't always need to represent the signature with a heavyweight BcelMethod object - only if its around advice and inlining + * is active + * + * @param concreteAspect + * @param attribute */ private static Member shrink(AdviceKind kind, ResolvedType concreteAspect, Member m) { - if (m==null) return null; + if (m == null) + return null; UnresolvedType dType = m.getDeclaringType(); // if it isnt around advice or it is but inlining is turned off then shrink it to a ResolvedMemberImpl - if (kind != AdviceKind.Around || - ((dType instanceof ResolvedType) && ((ResolvedType)dType).getWorld().isXnoInline())) { + if (kind != AdviceKind.Around || ((dType instanceof ResolvedType) && ((ResolvedType) dType).getWorld().isXnoInline())) { if (m instanceof BcelMethod) { - BcelMethod bm = (BcelMethod)m; - if (bm.getMethod()!=null && bm.getMethod().getAnnotations()!=null) return m; - ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(),bm.getDeclaringType(), - bm.getModifiers(),bm.getReturnType(),bm.getName(), - bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember()); + BcelMethod bm = (BcelMethod) m; + if (bm.getMethod() != null && bm.getMethod().getAnnotations() != null) + return m; + ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(), bm.getDeclaringType(), bm.getModifiers(), + bm.getReturnType(), bm.getName(), bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember() + // ); simplermember.setParameterNames(bm.getParameterNames()); return simplermember; } } return m; } + /** * For testing only */ - public BcelAdvice(AdviceKind kind, Pointcut pointcut, Member signature, - int extraArgumentFlags, - int start, int end, ISourceContext sourceContext, ResolvedType concreteAspect) - { - this(new AjAttribute.AdviceAttribute(kind, pointcut, extraArgumentFlags, start, end, sourceContext), - pointcut, signature, concreteAspect); - thrownExceptions = Collections.EMPTY_LIST; //!!! interaction with unit tests + public BcelAdvice(AdviceKind kind, Pointcut pointcut, Member signature, int extraArgumentFlags, int start, int end, + ISourceContext sourceContext, ResolvedType concreteAspect) { + this(new AjAttribute.AdviceAttribute(kind, pointcut, extraArgumentFlags, start, end, sourceContext), pointcut, signature, + concreteAspect); + thrownExceptions = Collections.EMPTY_LIST; // !!! interaction with unit tests } - // ---- implementations of ShadowMunger's methods - + // ---- implementations of ShadowMunger's methods + public ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause) { suppressLintWarnings(world); ShadowMunger ret = super.concretize(fromType, world, clause); - clearLintSuppressions(world,this.suppressedLintKinds); + clearLintSuppressions(world, this.suppressedLintKinds); IfFinder ifinder = new IfFinder(); - ret.getPointcut().accept(ifinder,null); + ret.getPointcut().accept(ifinder, null); boolean hasGuardTest = ifinder.hasIf && getKind() != AdviceKind.Around; boolean isAround = getKind() == AdviceKind.Around; if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - if (!isAround && !hasGuardTest && world.getLint().noGuardForLazyTjp.isEnabled()) { - // can't build tjp lazily, no suitable test... - // ... only want to record it once against the advice(bug 133117) - world.getLint().noGuardForLazyTjp.signal("",getSourceLocation()); - } + if (!isAround && !hasGuardTest && world.getLint().noGuardForLazyTjp.isEnabled()) { + // can't build tjp lazily, no suitable test... + // ... only want to record it once against the advice(bug 133117) + world.getLint().noGuardForLazyTjp.signal("", getSourceLocation()); + } } return ret; } - - public ShadowMunger parameterizeWith(ResolvedType declaringType,Map typeVariableMap) { - Pointcut pc = getPointcut().parameterizeWith(typeVariableMap,declaringType.getWorld()); - + + public ShadowMunger parameterizeWith(ResolvedType declaringType, Map typeVariableMap) { + Pointcut pc = getPointcut().parameterizeWith(typeVariableMap, declaringType.getWorld()); + BcelAdvice ret = null; - Member adviceSignature = signature; + Member adviceSignature = signature; // allows for around advice where the return value is a type variable (see pr115250) if (signature instanceof ResolvedMember && signature.getDeclaringType().isGenericType()) { - adviceSignature = ((ResolvedMember)signature).parameterizedWith(declaringType.getTypeParameters(),declaringType,declaringType.isParameterizedType()); + adviceSignature = ((ResolvedMember) signature).parameterizedWith(declaringType.getTypeParameters(), declaringType, + declaringType.isParameterizedType()); } - ret = new BcelAdvice(this.attribute,pc,adviceSignature,this.concreteAspect); + ret = new BcelAdvice(this.attribute, pc, adviceSignature, this.concreteAspect); return ret; } - + public boolean match(Shadow shadow, World world) { suppressLintWarnings(world); boolean ret = super.match(shadow, world); - clearLintSuppressions(world,this.suppressedLintKinds); + clearLintSuppressions(world, this.suppressedLintKinds); return ret; } - - public void specializeOn(Shadow shadow) { - if (getKind() == AdviceKind.Around) { - ((BcelShadow)shadow).initializeForAroundClosure(); - } - - //XXX this case is just here for supporting lazy test code - if (getKind() == null) { + + public void specializeOn(Shadow shadow) { + if (getKind() == AdviceKind.Around) { + ((BcelShadow) shadow).initializeForAroundClosure(); + } + + // XXX this case is just here for supporting lazy test code + if (getKind() == null) { exposedState = new ExposedState(0); - return; - } - if (getKind().isPerEntry()) { - exposedState = new ExposedState(0); - } else if (getKind().isCflow()) { - exposedState = new ExposedState(nFreeVars); - } else if (getSignature() != null) { + return; + } + if (getKind().isPerEntry()) { + exposedState = new ExposedState(0); + } else if (getKind().isCflow()) { + exposedState = new ExposedState(nFreeVars); + } else if (getSignature() != null) { exposedState = new ExposedState(getSignature()); - } else { - exposedState = new ExposedState(0); - return; //XXX this case is just here for supporting lazy test code - } - - World world = shadow.getIWorld(); - suppressLintWarnings(world); + } else { + exposedState = new ExposedState(0); + return; // XXX this case is just here for supporting lazy test code + } + + World world = shadow.getIWorld(); + suppressLintWarnings(world); pointcutTest = getPointcut().findResidue(shadow, exposedState); - clearLintSuppressions(world,this.suppressedLintKinds); - + clearLintSuppressions(world, this.suppressedLintKinds); + // these initializations won't be performed by findResidue, but need to be // so that the joinpoint is primed for weaving if (getKind() == AdviceKind.PerThisEntry) { @@ -179,186 +175,181 @@ public class BcelAdvice extends Advice { } else if (getKind() == AdviceKind.PerTargetEntry) { shadow.getTargetVar(); } - - - // make sure thisJoinPoint parameters are initialized - if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { - ((BcelShadow)shadow).getThisJoinPointStaticPartVar(); - ((BcelShadow)shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow,getSourceLocation()); - } - - if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - boolean hasGuardTest = pointcutTest != Literal.TRUE && getKind() != AdviceKind.Around; - boolean isAround = getKind() == AdviceKind.Around; - ((BcelShadow)shadow).requireThisJoinPoint(hasGuardTest,isAround); - ((BcelShadow)shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow,getSourceLocation()); + + // make sure thisJoinPoint parameters are initialized + if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { + ((BcelShadow) shadow).getThisJoinPointStaticPartVar(); + ((BcelShadow) shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow, getSourceLocation()); + } + + if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { + boolean hasGuardTest = pointcutTest != Literal.TRUE && getKind() != AdviceKind.Around; + boolean isAround = getKind() == AdviceKind.Around; + ((BcelShadow) shadow).requireThisJoinPoint(hasGuardTest, isAround); + ((BcelShadow) shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow, getSourceLocation()); if (!hasGuardTest && world.getLint().multipleAdviceStoppingLazyTjp.isEnabled()) { // collect up the problematic advice - ((BcelShadow)shadow).addAdvicePreventingLazyTjp(this); + ((BcelShadow) shadow).addAdvicePreventingLazyTjp(this); } - } - - if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { - ((BcelShadow)shadow).getThisEnclosingJoinPointStaticPartVar(); - ((BcelShadow)shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow,getSourceLocation()); - } - } - - private boolean canInline(Shadow s) { - if (attribute.isProceedInInners()) return false; - //XXX this guard seems to only be needed for bad test cases - if (concreteAspect == null || concreteAspect.isMissing()) return false; - - if (concreteAspect.getWorld().isXnoInline()) return false; - //System.err.println("isWoven? " + ((BcelObjectType)concreteAspect).getLazyClassGen().getWeaverState()); - return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven(); - } - - public void implementOn(Shadow s) { - hasMatchedAtLeastOnce=true; - BcelShadow shadow = (BcelShadow) s; - - // remove any unnecessary exceptions if the compiler option is set to - // error or warning and if this piece of advice throws exceptions - // (bug 129282). This may be expanded to include other compiler warnings - // at the moment it only deals with 'declared exception is not thrown' - if (!shadow.getWorld().isIgnoringUnusedDeclaredThrownException() - && !getThrownExceptions().isEmpty()) { - Member member = shadow.getSignature(); - if (member instanceof BcelMethod) { - removeUnnecessaryProblems((BcelMethod)member, - ((BcelMethod)member).getDeclarationLineNumber()); + } + + if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { + ((BcelShadow) shadow).getThisEnclosingJoinPointStaticPartVar(); + ((BcelShadow) shadow).getEnclosingClass().warnOnAddedStaticInitializer(shadow, getSourceLocation()); + } + } + + private boolean canInline(Shadow s) { + if (attribute.isProceedInInners()) + return false; + // XXX this guard seems to only be needed for bad test cases + if (concreteAspect == null || concreteAspect.isMissing()) + return false; + + if (concreteAspect.getWorld().isXnoInline()) + return false; + // System.err.println("isWoven? " + ((BcelObjectType)concreteAspect).getLazyClassGen().getWeaverState()); + return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven(); + } + + public void implementOn(Shadow s) { + hasMatchedAtLeastOnce = true; + BcelShadow shadow = (BcelShadow) s; + + // remove any unnecessary exceptions if the compiler option is set to + // error or warning and if this piece of advice throws exceptions + // (bug 129282). This may be expanded to include other compiler warnings + // at the moment it only deals with 'declared exception is not thrown' + if (!shadow.getWorld().isIgnoringUnusedDeclaredThrownException() && !getThrownExceptions().isEmpty()) { + Member member = shadow.getSignature(); + if (member instanceof BcelMethod) { + removeUnnecessaryProblems((BcelMethod) member, ((BcelMethod) member).getDeclarationLineNumber()); } else { // we're in a call shadow therefore need the line number of the // declared method (which may be in a different type). However, - // we want to remove the problems from the CompilationResult + // we want to remove the problems from the CompilationResult // held within the current type's EclipseSourceContext so need // the enclosing shadow too ResolvedMember resolvedMember = shadow.getSignature().resolve(shadow.getWorld()); - if (resolvedMember instanceof BcelMethod - && shadow.getEnclosingShadow() instanceof BcelShadow) { + if (resolvedMember instanceof BcelMethod && shadow.getEnclosingShadow() instanceof BcelShadow) { Member enclosingMember = shadow.getEnclosingShadow().getSignature(); if (enclosingMember instanceof BcelMethod) { - removeUnnecessaryProblems((BcelMethod)enclosingMember, - ((BcelMethod)resolvedMember).getDeclarationLineNumber()); + removeUnnecessaryProblems((BcelMethod) enclosingMember, ((BcelMethod) resolvedMember) + .getDeclarationLineNumber()); } } } } - if (shadow.getIWorld().isJoinpointSynchronizationEnabled() && - shadow.getKind()==Shadow.MethodExecution && - (s.getSignature().getModifiers() & Modifier.SYNCHRONIZED)!=0) { - shadow.getIWorld().getLint().advisingSynchronizedMethods.signal(new String[]{shadow.toString()},shadow.getSourceLocation(),new ISourceLocation[]{getSourceLocation()}); - } - - //FIXME AV - see #75442, this logic is not enough so for now comment it out until we fix the bug -// // callback for perObject AJC MightHaveAspect postMunge (#75442) -// if (getConcreteAspect() != null -// && getConcreteAspect().getPerClause() != null -// && PerClause.PEROBJECT.equals(getConcreteAspect().getPerClause().getKind())) { -// final PerObject clause; -// if (getConcreteAspect().getPerClause() instanceof PerFromSuper) { -// clause = (PerObject)((PerFromSuper) getConcreteAspect().getPerClause()).lookupConcretePerClause(getConcreteAspect()); -// } else { -// clause = (PerObject) getConcreteAspect().getPerClause(); -// } -// if (clause.isThis()) { -// PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getThisVar().getType(), getConcreteAspect()); -// } else { -// PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getTargetVar().getType(), getConcreteAspect()); -// } -// } - - if (getKind() == AdviceKind.Before) { - shadow.weaveBefore(this); - } else if (getKind() == AdviceKind.AfterReturning) { - shadow.weaveAfterReturning(this); - } else if (getKind() == AdviceKind.AfterThrowing) { - UnresolvedType catchType = - hasExtraParameter() - ? getExtraParameterType() - : UnresolvedType.THROWABLE; - shadow.weaveAfterThrowing(this, catchType); - } else if (getKind() == AdviceKind.After) { - shadow.weaveAfter(this); - } else if (getKind() == AdviceKind.Around) { - // Note: under regular LTW the aspect is usually loaded after the first use of any class affecteted by it - // This means that as long as the aspect has not been thru the LTW, it's woven state is unknown - // and thus canInline(s) will return false. - // To force inlining (test), ones can do Class aspect = FQNAspect.class in the clinit of the target class - // FIXME AV : for AJC compiled @AJ aspect (or any code style aspect), the woven state can never be known - // if the aspect belongs to a parent classloader. In that case the aspect will never be inlined. - // It might be dangerous to change that especially for @AJ aspect non compiled with AJC since if those - // are not weaved (f.e. use of some limiteed LTW etc) then they cannot be prepared for inlining. - // One solution would be to flag @AJ aspect with an annotation as "prepared" and query that one. - if (!canInline(s)) { - shadow.weaveAroundClosure(this, hasDynamicTests()); - } else { - shadow.weaveAroundInline(this, hasDynamicTests()); - } - } else if (getKind() == AdviceKind.InterInitializer) { - shadow.weaveAfterReturning(this); - } else if (getKind().isCflow()) { - shadow.weaveCflowEntry(this, getSignature()); - } else if (getKind() == AdviceKind.PerThisEntry) { - shadow.weavePerObjectEntry(this, (BcelVar)shadow.getThisVar()); - } else if (getKind() == AdviceKind.PerTargetEntry) { - shadow.weavePerObjectEntry(this, (BcelVar)shadow.getTargetVar()); - } else if (getKind() == AdviceKind.Softener) { - shadow.weaveSoftener(this, ((ExactTypePattern)exceptionType).getType()); - } else if (getKind() == AdviceKind.PerTypeWithinEntry) { - // PTWIMPL Entry to ptw is the static initialization of a type that matched the ptw type pattern - shadow.weavePerTypeWithinAspectInitialization(this,shadow.getEnclosingType()); - } else { - throw new BCException("unimplemented kind: " + getKind()); - } - } - - private void removeUnnecessaryProblems(BcelMethod method, int problemLineNumber) { + if (shadow.getIWorld().isJoinpointSynchronizationEnabled() && shadow.getKind() == Shadow.MethodExecution + && (s.getSignature().getModifiers() & Modifier.SYNCHRONIZED) != 0) { + shadow.getIWorld().getLint().advisingSynchronizedMethods.signal(new String[] { shadow.toString() }, shadow + .getSourceLocation(), new ISourceLocation[] { getSourceLocation() }); + } + + // FIXME AV - see #75442, this logic is not enough so for now comment it out until we fix the bug + // // callback for perObject AJC MightHaveAspect postMunge (#75442) + // if (getConcreteAspect() != null + // && getConcreteAspect().getPerClause() != null + // && PerClause.PEROBJECT.equals(getConcreteAspect().getPerClause().getKind())) { + // final PerObject clause; + // if (getConcreteAspect().getPerClause() instanceof PerFromSuper) { + // clause = (PerObject)((PerFromSuper) getConcreteAspect().getPerClause()).lookupConcretePerClause(getConcreteAspect()); + // } else { + // clause = (PerObject) getConcreteAspect().getPerClause(); + // } + // if (clause.isThis()) { + // PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getThisVar().getType(), getConcreteAspect()); + // } else { + // PerObjectInterfaceTypeMunger.registerAsAdvisedBy(s.getTargetVar().getType(), getConcreteAspect()); + // } + // } + + if (getKind() == AdviceKind.Before) { + shadow.weaveBefore(this); + } else if (getKind() == AdviceKind.AfterReturning) { + shadow.weaveAfterReturning(this); + } else if (getKind() == AdviceKind.AfterThrowing) { + UnresolvedType catchType = hasExtraParameter() ? getExtraParameterType() : UnresolvedType.THROWABLE; + shadow.weaveAfterThrowing(this, catchType); + } else if (getKind() == AdviceKind.After) { + shadow.weaveAfter(this); + } else if (getKind() == AdviceKind.Around) { + // Note: under regular LTW the aspect is usually loaded after the first use of any class affecteted by it + // This means that as long as the aspect has not been thru the LTW, it's woven state is unknown + // and thus canInline(s) will return false. + // To force inlining (test), ones can do Class aspect = FQNAspect.class in the clinit of the target class + // FIXME AV : for AJC compiled @AJ aspect (or any code style aspect), the woven state can never be known + // if the aspect belongs to a parent classloader. In that case the aspect will never be inlined. + // It might be dangerous to change that especially for @AJ aspect non compiled with AJC since if those + // are not weaved (f.e. use of some limiteed LTW etc) then they cannot be prepared for inlining. + // One solution would be to flag @AJ aspect with an annotation as "prepared" and query that one. + if (!canInline(s)) { + shadow.weaveAroundClosure(this, hasDynamicTests()); + } else { + shadow.weaveAroundInline(this, hasDynamicTests()); + } + } else if (getKind() == AdviceKind.InterInitializer) { + shadow.weaveAfterReturning(this); + } else if (getKind().isCflow()) { + shadow.weaveCflowEntry(this, getSignature()); + } else if (getKind() == AdviceKind.PerThisEntry) { + shadow.weavePerObjectEntry(this, (BcelVar) shadow.getThisVar()); + } else if (getKind() == AdviceKind.PerTargetEntry) { + shadow.weavePerObjectEntry(this, (BcelVar) shadow.getTargetVar()); + } else if (getKind() == AdviceKind.Softener) { + shadow.weaveSoftener(this, ((ExactTypePattern) exceptionType).getType()); + } else if (getKind() == AdviceKind.PerTypeWithinEntry) { + // PTWIMPL Entry to ptw is the static initialization of a type that matched the ptw type pattern + shadow.weavePerTypeWithinAspectInitialization(this, shadow.getEnclosingType()); + } else { + throw new BCException("unimplemented kind: " + getKind()); + } + } + + private void removeUnnecessaryProblems(BcelMethod method, int problemLineNumber) { ISourceContext sourceContext = method.getSourceContext(); if (sourceContext instanceof IEclipseSourceContext) { - ((IEclipseSourceContext)sourceContext).removeUnnecessaryProblems(method, problemLineNumber); + ((IEclipseSourceContext) sourceContext).removeUnnecessaryProblems(method, problemLineNumber); } - } - - // ---- implementations - + } + + // ---- implementations + private Collection collectCheckedExceptions(UnresolvedType[] excs) { - if (excs == null || excs.length == 0) return Collections.EMPTY_LIST; - + if (excs == null || excs.length == 0) + return Collections.EMPTY_LIST; + Collection ret = new ArrayList(); World world = concreteAspect.getWorld(); ResolvedType runtimeException = world.getCoreType(UnresolvedType.RUNTIME_EXCEPTION); ResolvedType error = world.getCoreType(UnresolvedType.ERROR); - - for (int i=0, len=excs.length; i < len; i++) { - ResolvedType t = world.resolve(excs[i],true); - if (t.isMissing()) { - world.getLint().cantFindType.signal( - WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()), - getSourceLocation() - ); -// IMessage msg = new Message( -// WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()), -// "",IMessage.ERROR,getSourceLocation(),null,null); -// world.getMessageHandler().handleMessage(msg); - } + + for (int i = 0, len = excs.length; i < len; i++) { + ResolvedType t = world.resolve(excs[i], true); + if (t.isMissing()) { + world.getLint().cantFindType.signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE, excs[i] + .getName()), getSourceLocation()); + // IMessage msg = new Message( + // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()), + // "",IMessage.ERROR,getSourceLocation(),null,null); + // world.getMessageHandler().handleMessage(msg); + } if (!(runtimeException.isAssignableFrom(t) || error.isAssignableFrom(t))) { ret.add(t); } } - + return ret; } private Collection thrownExceptions = null; + public Collection getThrownExceptions() { if (thrownExceptions == null) { - //??? can we really lump in Around here, how does this interact with Throwable + // ??? can we really lump in Around here, how does this interact with Throwable if (concreteAspect != null && concreteAspect.getWorld() != null && // null tests for test harness - (getKind().isAfter() || getKind() == AdviceKind.Before || getKind() == AdviceKind.Around)) - { + (getKind().isAfter() || getKind() == AdviceKind.Before || getKind() == AdviceKind.Around)) { World world = concreteAspect.getWorld(); ResolvedMember m = world.resolve(signature); if (m == null) { @@ -373,311 +364,261 @@ public class BcelAdvice extends Advice { return thrownExceptions; } - /** - * The munger must not check for the advice exceptions to be declared by the shadow in the case - * of @AJ aspects so that around can throws Throwable - * - * @return - */ - public boolean mustCheckExceptions() { - if (getConcreteAspect() == null) { - return true; - } - return !getConcreteAspect().isAnnotationStyleAspect(); - } - - - - // only call me after prepare has been called - public boolean hasDynamicTests() { -// if (hasExtraParameter() && getKind() == AdviceKind.AfterReturning) { -// UnresolvedType extraParameterType = getExtraParameterType(); -// if (! extraParameterType.equals(UnresolvedType.OBJECT) -// && ! extraParameterType.isPrimitive()) -// return true; -// } - - - return pointcutTest != null && - !(pointcutTest == Literal.TRUE);// || pointcutTest == Literal.NO_TEST); - } + /** + * The munger must not check for the advice exceptions to be declared by the shadow in the case of @AJ aspects so that around + * can throws Throwable + * + * @return + */ + public boolean mustCheckExceptions() { + if (getConcreteAspect() == null) { + return true; + } + return !getConcreteAspect().isAnnotationStyleAspect(); + } + + // only call me after prepare has been called + public boolean hasDynamicTests() { + // if (hasExtraParameter() && getKind() == AdviceKind.AfterReturning) { + // UnresolvedType extraParameterType = getExtraParameterType(); + // if (! extraParameterType.equals(UnresolvedType.OBJECT) + // && ! extraParameterType.isPrimitive()) + // return true; + // } + return pointcutTest != null && !(pointcutTest == Literal.TRUE);// || pointcutTest == Literal.NO_TEST); + } /** - * get the instruction list for the really simple version of this advice. - * Is broken apart - * for other advice, but if you want it in one block, this is the method to call. + * get the instruction list for the really simple version of this advice. Is broken apart for other advice, but if you want it + * in one block, this is the method to call. * * @param s The shadow around which these instructions will eventually live. - * @param extraArgVar The var that will hold the return value or thrown exception - * for afterX advice - * @param ifNoAdvice The instructionHandle to jump to if the dynamic - * tests for this munger fails. + * @param extraArgVar The var that will hold the return value or thrown exception for afterX advice + * @param ifNoAdvice The instructionHandle to jump to if the dynamic tests for this munger fails. */ - InstructionList getAdviceInstructions( - BcelShadow s, - BcelVar extraArgVar, - InstructionHandle ifNoAdvice) - { - BcelShadow shadow = s; - InstructionFactory fact = shadow.getFactory(); - BcelWorld world = shadow.getWorld(); - + InstructionList getAdviceInstructions(BcelShadow s, BcelVar extraArgVar, InstructionHandle ifNoAdvice) { + BcelShadow shadow = s; + InstructionFactory fact = shadow.getFactory(); + BcelWorld world = shadow.getWorld(); + InstructionList il = new InstructionList(); - // we test to see if we have the right kind of thing... - // after throwing does this just by the exception mechanism. - if (hasExtraParameter() && getKind() == AdviceKind.AfterReturning) { - UnresolvedType extraParameterType = getExtraParameterType(); - if (! extraParameterType.equals(UnresolvedType.OBJECT) - && ! extraParameterType.isPrimitiveType()) { - il.append( - BcelRenderer.renderTest( - fact, - world, - Test.makeInstanceof( - extraArgVar, getExtraParameterType().resolve(world)), - null, - ifNoAdvice, - null)); - } - } - il.append(getAdviceArgSetup(shadow, extraArgVar, null)); - il.append(getNonTestAdviceInstructions(shadow)); - - InstructionHandle ifYesAdvice = il.getStart(); - il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice)); - - // If inserting instructions at the start of a method, we need a nice line number for this entry - // in the stack trace - if (shadow.getKind()==Shadow.MethodExecution && getKind()==AdviceKind.Before) { - int lineNumber=0; - // Uncomment this code if you think we should use the method decl line number when it exists... -// // If the advised join point is in a class built by AspectJ, we can use the declaration line number -// boolean b = shadow.getEnclosingMethod().getMemberView().hasDeclarationLineNumberInfo(); -// if (b) { -// lineNumber = shadow.getEnclosingMethod().getMemberView().getDeclarationLineNumber(); -// } else { // If it wasn't, the best we can do is the line number of the first instruction in the method - lineNumber = shadow.getEnclosingMethod().getMemberView().getLineNumberOfFirstInstruction(); -// } - if (lineNumber>0) il.getStart().addTargeter(new LineNumberTag(lineNumber)); - } - - - return il; + // we test to see if we have the right kind of thing... + // after throwing does this just by the exception mechanism. + if (hasExtraParameter() && getKind() == AdviceKind.AfterReturning) { + UnresolvedType extraParameterType = getExtraParameterType(); + if (!extraParameterType.equals(UnresolvedType.OBJECT) && !extraParameterType.isPrimitiveType()) { + il.append(BcelRenderer.renderTest(fact, world, Test.makeInstanceof(extraArgVar, getExtraParameterType().resolve( + world)), null, ifNoAdvice, null)); + } + } + il.append(getAdviceArgSetup(shadow, extraArgVar, null)); + il.append(getNonTestAdviceInstructions(shadow)); + + InstructionHandle ifYesAdvice = il.getStart(); + il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice)); + + // If inserting instructions at the start of a method, we need a nice line number for this entry + // in the stack trace + if (shadow.getKind() == Shadow.MethodExecution && getKind() == AdviceKind.Before) { + int lineNumber = 0; + // Uncomment this code if you think we should use the method decl line number when it exists... + // // If the advised join point is in a class built by AspectJ, we can use the declaration line number + // boolean b = shadow.getEnclosingMethod().getMemberView().hasDeclarationLineNumberInfo(); + // if (b) { + // lineNumber = shadow.getEnclosingMethod().getMemberView().getDeclarationLineNumber(); + // } else { // If it wasn't, the best we can do is the line number of the first instruction in the method + lineNumber = shadow.getEnclosingMethod().getMemberView().getLineNumberOfFirstInstruction(); + // } + if (lineNumber > 0) + il.getStart().addTargeter(new LineNumberTag(lineNumber)); + } + + return il; } - public InstructionList getAdviceArgSetup( - BcelShadow shadow, - BcelVar extraVar, - InstructionList closureInstantiation) - { - InstructionFactory fact = shadow.getFactory(); - BcelWorld world = shadow.getWorld(); - InstructionList il = new InstructionList(); - -// if (targetAspectField != null) { -// il.append(fact.createFieldAccess( -// targetAspectField.getDeclaringType().getName(), -// targetAspectField.getName(), -// BcelWorld.makeBcelType(targetAspectField.getType()), -// Constants.GETSTATIC)); -// } -// - //System.err.println("BcelAdvice: " + exposedState); + public InstructionList getAdviceArgSetup(BcelShadow shadow, BcelVar extraVar, InstructionList closureInstantiation) { + InstructionFactory fact = shadow.getFactory(); + BcelWorld world = shadow.getWorld(); + InstructionList il = new InstructionList(); + // if (targetAspectField != null) { + // il.append(fact.createFieldAccess( + // targetAspectField.getDeclaringType().getName(), + // targetAspectField.getName(), + // BcelWorld.makeBcelType(targetAspectField.getType()), + // Constants.GETSTATIC)); + // } + // + // System.err.println("BcelAdvice: " + exposedState); if (exposedState.getAspectInstance() != null) { il.append(BcelRenderer.renderExpr(fact, world, exposedState.getAspectInstance())); } // pr121385 boolean x = this.getDeclaringAspect().resolve(world).isAnnotationStyleAspect(); - final boolean isAnnotationStyleAspect = getConcreteAspect()!=null && getConcreteAspect().isAnnotationStyleAspect() && x; - boolean previousIsClosure = false; - for (int i = 0, len = exposedState.size(); i < len; i++) { - if (exposedState.isErroneousVar(i)) continue; // Erroneous vars have already had error msgs reported! - BcelVar v = (BcelVar) exposedState.get(i); - - if (v == null) { - // if not @AJ aspect, go on with the regular binding handling - if (!isAnnotationStyleAspect) { - - } else { - // ATAJ: for @AJ aspects, handle implicit binding of xxJoinPoint - //if (getKind() == AdviceKind.Around) { - // previousIsClosure = true; - // il.append(closureInstantiation); - if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) { - //make sure we are in an around, since we deal with the closure, not the arg here - if (getKind() != AdviceKind.Around) { - previousIsClosure = false; - getConcreteAspect().getWorld().getMessageHandler().handleMessage( - new Message( - "use of ProceedingJoinPoint is allowed only on around advice (" - + "arg " + i + " in " + toString() + ")", - this.getSourceLocation(), - true - ) - ); - // try to avoid verify error and pass in null - il.append(InstructionConstants.ACONST_NULL); - } else { - if (previousIsClosure) { - il.append(InstructionConstants.DUP); - } else { - previousIsClosure = true; - il.append(closureInstantiation.copy()); - } - } - } else if ("Lorg/aspectj/lang/JoinPoint$StaticPart;".equals(getSignature().getParameterTypes()[i].getSignature())) { - previousIsClosure = false; - if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { - shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact); - } - } else if ("Lorg/aspectj/lang/JoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) { - previousIsClosure = false; - if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - il.append(shadow.loadThisJoinPoint()); - } - } else if ("Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;".equals(getSignature().getParameterTypes()[i].getSignature())) { - previousIsClosure = false; - if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { - shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact); - } - } else if (hasExtraParameter()) { - previousIsClosure = false; - extraVar.appendLoadAndConvert( - il, - fact, - getExtraParameterType().resolve(world)); - } else { - previousIsClosure = false; - getConcreteAspect().getWorld().getMessageHandler().handleMessage( - new Message( - "use of ProceedingJoinPoint is allowed only on around advice (" - + "arg " + i + " in " + toString() + ")", - this.getSourceLocation(), - true - ) - ); - // try to avoid verify error and pass in null - il.append(InstructionConstants.ACONST_NULL); - } - } - } else { - UnresolvedType desiredTy = getBindingParameterTypes()[i]; - v.appendLoadAndConvert(il, fact, desiredTy.resolve(world)); - } - } - - - // ATAJ: for code style aspect, handles the extraFlag as usual ie not - // in the middle of the formal bindings but at the end, in a rock solid ordering - if (!isAnnotationStyleAspect) { - if (getKind() == AdviceKind.Around) { - il.append(closureInstantiation); - } else if (hasExtraParameter()) { - extraVar.appendLoadAndConvert( - il, - fact, - getExtraParameterType().resolve(world)); - } - - // handle thisJoinPoint parameters - // these need to be in that same order as parameters in - // org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration - if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { - shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact); - } - - if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - il.append(shadow.loadThisJoinPoint()); - } - - if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { - shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact); - } - } - - - return il; - } - - public InstructionList getNonTestAdviceInstructions(BcelShadow shadow) { - return new InstructionList( - Utility.createInvoke(shadow.getFactory(), shadow.getWorld(), getOriginalSignature())); - } - - public Member getOriginalSignature() { - Member sig = getSignature(); - if (sig instanceof ResolvedMember) { - ResolvedMember rsig = (ResolvedMember)sig; - if (rsig.hasBackingGenericMember()) return rsig.getBackingGenericMember(); - } - return sig; - } - - public InstructionList getTestInstructions( - BcelShadow shadow, - InstructionHandle sk, - InstructionHandle fk, - InstructionHandle next) - { - //System.err.println("test: " + pointcutTest); - return BcelRenderer.renderTest( - shadow.getFactory(), - shadow.getWorld(), - pointcutTest, - sk, - fk, - next); + final boolean isAnnotationStyleAspect = getConcreteAspect() != null && getConcreteAspect().isAnnotationStyleAspect() && x; + boolean previousIsClosure = false; + for (int i = 0, len = exposedState.size(); i < len; i++) { + if (exposedState.isErroneousVar(i)) + continue; // Erroneous vars have already had error msgs reported! + BcelVar v = (BcelVar) exposedState.get(i); + + if (v == null) { + // if not @AJ aspect, go on with the regular binding handling + if (!isAnnotationStyleAspect) { + + } else { + // ATAJ: for @AJ aspects, handle implicit binding of xxJoinPoint + // if (getKind() == AdviceKind.Around) { + // previousIsClosure = true; + // il.append(closureInstantiation); + if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) { + // make sure we are in an around, since we deal with the closure, not the arg here + if (getKind() != AdviceKind.Around) { + previousIsClosure = false; + getConcreteAspect().getWorld().getMessageHandler().handleMessage( + new Message("use of ProceedingJoinPoint is allowed only on around advice (" + "arg " + i + + " in " + toString() + ")", this.getSourceLocation(), true)); + // try to avoid verify error and pass in null + il.append(InstructionConstants.ACONST_NULL); + } else { + if (previousIsClosure) { + il.append(InstructionConstants.DUP); + } else { + previousIsClosure = true; + il.append(closureInstantiation.copy()); + } + } + } else if ("Lorg/aspectj/lang/JoinPoint$StaticPart;".equals(getSignature().getParameterTypes()[i] + .getSignature())) { + previousIsClosure = false; + if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { + shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact); + } + } else if ("Lorg/aspectj/lang/JoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) { + previousIsClosure = false; + if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { + il.append(shadow.loadThisJoinPoint()); + } + } else if ("Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;".equals(getSignature().getParameterTypes()[i] + .getSignature())) { + previousIsClosure = false; + if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { + shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact); + } + } else if (hasExtraParameter()) { + previousIsClosure = false; + extraVar.appendLoadAndConvert(il, fact, getExtraParameterType().resolve(world)); + } else { + previousIsClosure = false; + getConcreteAspect().getWorld().getMessageHandler().handleMessage( + new Message("use of ProceedingJoinPoint is allowed only on around advice (" + "arg " + i + " in " + + toString() + ")", this.getSourceLocation(), true)); + // try to avoid verify error and pass in null + il.append(InstructionConstants.ACONST_NULL); + } + } + } else { + UnresolvedType desiredTy = getBindingParameterTypes()[i]; + v.appendLoadAndConvert(il, fact, desiredTy.resolve(world)); + } + } + + // ATAJ: for code style aspect, handles the extraFlag as usual ie not + // in the middle of the formal bindings but at the end, in a rock solid ordering + if (!isAnnotationStyleAspect) { + if (getKind() == AdviceKind.Around) { + il.append(closureInstantiation); + } else if (hasExtraParameter()) { + extraVar.appendLoadAndConvert(il, fact, getExtraParameterType().resolve(world)); + } + + // handle thisJoinPoint parameters + // these need to be in that same order as parameters in + // org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration + if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) { + shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact); + } + + if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { + il.append(shadow.loadThisJoinPoint()); + } + + if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { + shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact); + } + } + + return il; + } + + public InstructionList getNonTestAdviceInstructions(BcelShadow shadow) { + return new InstructionList(Utility.createInvoke(shadow.getFactory(), shadow.getWorld(), getOriginalSignature())); + } + + public Member getOriginalSignature() { + Member sig = getSignature(); + if (sig instanceof ResolvedMember) { + ResolvedMember rsig = (ResolvedMember) sig; + if (rsig.hasBackingGenericMember()) + return rsig.getBackingGenericMember(); + } + return sig; + } + + public InstructionList getTestInstructions(BcelShadow shadow, InstructionHandle sk, InstructionHandle fk, InstructionHandle next) { + // System.err.println("test: " + pointcutTest); + return BcelRenderer.renderTest(shadow.getFactory(), shadow.getWorld(), pointcutTest, sk, fk, next); } public int compareTo(Object other) { - if (!(other instanceof BcelAdvice)) return 0; - BcelAdvice o = (BcelAdvice)other; - - //System.err.println("compareTo: " + this + ", " + o); + if (!(other instanceof BcelAdvice)) + return 0; + BcelAdvice o = (BcelAdvice) other; + + // System.err.println("compareTo: " + this + ", " + o); if (kind.getPrecedence() != o.kind.getPrecedence()) { - if (kind.getPrecedence() > o.kind.getPrecedence()) return +1; - else return -1; + if (kind.getPrecedence() > o.kind.getPrecedence()) + return +1; + else + return -1; } - + if (kind.isCflow()) { -// System.err.println("sort: " + this + " innerCflowEntries " + innerCflowEntries); -// System.err.println(" " + o + " innerCflowEntries " + o.innerCflowEntries); + // System.err.println("sort: " + this + " innerCflowEntries " + innerCflowEntries); + // System.err.println(" " + o + " innerCflowEntries " + o.innerCflowEntries); boolean isBelow = (kind == AdviceKind.CflowBelowEntry); - if (this.innerCflowEntries.contains(o)) return isBelow ? +1 : -1; - else if (o.innerCflowEntries.contains(this)) return isBelow ? -1 : +1; - else return 0; + if (this.innerCflowEntries.contains(o)) + return isBelow ? +1 : -1; + else if (o.innerCflowEntries.contains(this)) + return isBelow ? -1 : +1; + else + return 0; } - - + if (kind.isPerEntry() || kind == AdviceKind.Softener) { return 0; } - - //System.out.println("compare: " + this + " with " + other); + + // System.out.println("compare: " + this + " with " + other); World world = concreteAspect.getWorld(); - - int ret = - concreteAspect.getWorld().compareByPrecedence( - concreteAspect, - o.concreteAspect); - if (ret != 0) return ret; - - + + int ret = concreteAspect.getWorld().compareByPrecedence(concreteAspect, o.concreteAspect); + if (ret != 0) + return ret; + ResolvedType declaringAspect = getDeclaringAspect().resolve(world); ResolvedType o_declaringAspect = o.getDeclaringAspect().resolve(world); - - + if (declaringAspect == o_declaringAspect) { - if (kind.isAfter() || o.kind.isAfter()) { - return this.getStart() < o.getStart() ? -1: +1; - } else { - return this.getStart()< o.getStart() ? +1: -1; - } + if (kind.isAfter() || o.kind.isAfter()) { + return this.getStart() < o.getStart() ? -1 : +1; + } else { + return this.getStart() < o.getStart() ? +1 : -1; + } } else if (declaringAspect.isAssignableFrom(o_declaringAspect)) { return -1; } else if (o_declaringAspect.isAssignableFrom(declaringAspect)) { @@ -688,44 +629,37 @@ public class BcelAdvice extends Advice { } public BcelVar[] getExposedStateAsBcelVars(boolean isAround) { - // ATAJ aspect - if (isAround) { - // the closure instantiation has the same mapping as the extracted method from wich it is called - if (getConcreteAspect()!= null && getConcreteAspect().isAnnotationStyleAspect()) { - return BcelVar.NONE; - } - } - - //System.out.println("vars: " + Arrays.asList(exposedState.vars)); - if (exposedState == null) return BcelVar.NONE; + // ATAJ aspect + if (isAround) { + // the closure instantiation has the same mapping as the extracted method from wich it is called + if (getConcreteAspect() != null && getConcreteAspect().isAnnotationStyleAspect()) { + return BcelVar.NONE; + } + } + + // System.out.println("vars: " + Arrays.asList(exposedState.vars)); + if (exposedState == null) + return BcelVar.NONE; int len = exposedState.vars.length; BcelVar[] ret = new BcelVar[len]; - for (int i=0; i < len; i++) { - ret[i] = (BcelVar)exposedState.vars[i]; + for (int i = 0; i < len; i++) { + ret[i] = (BcelVar) exposedState.vars[i]; } - return ret; //(BcelVar[]) exposedState.vars; - } - - public boolean hasMatchedSomething() { - return hasMatchedAtLeastOnce; + return ret; // (BcelVar[]) exposedState.vars; } - public void setHasMatchedSomething(boolean hasMatchedSomething) { - hasMatchedAtLeastOnce = hasMatchedSomething; - } - protected void suppressLintWarnings(World inWorld) { if (suppressedLintKinds == null) { - if (signature instanceof BcelMethod) { - this.suppressedLintKinds = Utility.getSuppressedWarnings(signature.getAnnotations(), inWorld.getLint()); - } else { - this.suppressedLintKinds = Collections.EMPTY_LIST; - } - } - inWorld.getLint().suppressKinds(suppressedLintKinds); + if (signature instanceof BcelMethod) { + this.suppressedLintKinds = Utility.getSuppressedWarnings(signature.getAnnotations(), inWorld.getLint()); + } else { + this.suppressedLintKinds = Collections.EMPTY_LIST; + } + } + inWorld.getLint().suppressKinds(suppressedLintKinds); } - - protected void clearLintSuppressions(World inWorld,Collection toClear) { + + protected void clearLintSuppressions(World inWorld, Collection toClear) { inWorld.getLint().clearSuppressions(toClear); } }
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAttributes.java b/weaver/src/org/aspectj/weaver/bcel/BcelAttributes.java deleted file mode 100644 index fbd07ff71..000000000 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAttributes.java +++ /dev/null @@ -1,111 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.weaver.bcel; - -import java.util.ArrayList; -import java.util.List; - -import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Unknown; -import org.aspectj.weaver.AjAttribute; -import org.aspectj.weaver.BCException; -import org.aspectj.weaver.ISourceContext; -import org.aspectj.weaver.World; -import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; - - -// this is a class o' static methods for reading attributes. It's pretty much a bridge from -// bcel to AjAttribute. -// OPTIMIZE move the contents of this class to bcel Utility -class BcelAttributes { - - /** - * Process an array of Bcel attributes - looking for those with the name prefix org.aspectj.weaver. The returned - * list contains the AspectJ attributes identified and unpacked to 'AjAttribute' objects. - */ -// public static List readAjAttributes(String classname,List as, ISourceContext context, -// World w, AjAttribute.WeaverVersionInfo version) { -// List l = new ArrayList(); -// -// // first pass, look for version -// List forSecondPass = new ArrayList(); -// for (int i = as.size() - 1; i >= 0; i--) { -// Attribute a = (Attribute)as.get(i); -// if (a instanceof Unknown) { -// Unknown u = (Unknown) a; -// String name = u.getName(); -// if (name.charAt(0)=='o') { // 'o'rg.aspectj -// if (name.startsWith(AjAttribute.AttributePrefix)) { -// if (name.endsWith(WeaverVersionInfo.AttributeName)) { -// version = (AjAttribute.WeaverVersionInfo)AjAttribute.read(version,name,u.getBytes(),context,w); -// if (version.getMajorVersion() > WeaverVersionInfo.getCurrentWeaverMajorVersion()) { -// throw new BCException("Unable to continue, this version of AspectJ supports classes built with weaver version "+ -// WeaverVersionInfo.toCurrentVersionString()+" but the class "+classname+" is version "+version.toString()); -// } -// } -// forSecondPass.add(a); -// } -// } -// } -// } - -// for (int i = forSecondPass.size()-1; i >= 0; i--) { -// Unknown a = (Unknown)forSecondPass.get(i); -// String name = a.getName(); -// AjAttribute attr = AjAttribute.read(version,name,a.getBytes(),context,w); -// if (attr!=null) l.add(attr); -// } -// return l; -// } - public static List readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version) { - List l = new ArrayList(); - - // first pass, look for version - List forSecondPass = new ArrayList(); - for (int i = as.length - 1; i >= 0; i--) { - Attribute a = as[i]; - if (a instanceof Unknown) { - Unknown u = (Unknown) a; - String name = u.getName(); - if (name.charAt(0) == 'o') { // 'o'rg.aspectj - if (name.startsWith(AjAttribute.AttributePrefix)) { - if (name.endsWith(WeaverVersionInfo.AttributeName)) { - version = (AjAttribute.WeaverVersionInfo) AjAttribute.read(version, name, u.getBytes(), context, w); - if (version.getMajorVersion() > WeaverVersionInfo - .getCurrentWeaverMajorVersion()) { - throw new BCException( - "Unable to continue, this version of AspectJ supports classes built with weaver version " - + WeaverVersionInfo - .toCurrentVersionString() - + " but the class " - + classname - + " is version " - + version.toString()); - } - } - forSecondPass.add(a); - } - } - } - } - - for (int i = forSecondPass.size() - 1; i >= 0; i--) { - Unknown a = (Unknown) forSecondPass.get(i); - String name = a.getName(); - AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w); - if (attr != null) l.add(attr); - } - return l; - } -}
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelCflowAccessVar.java b/weaver/src/org/aspectj/weaver/bcel/BcelCflowAccessVar.java index 1d0fa70b5..2640edd95 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelCflowAccessVar.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelCflowAccessVar.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import org.aspectj.apache.bcel.Constants; @@ -23,14 +22,12 @@ import org.aspectj.weaver.NameMangler; import org.aspectj.weaver.ResolvedType; /** - * XXX Erik and I need to discuss this hierarchy. Having FieldRef - * extend Var is convenient, but hopefully there's a better design. + * XXX Erik and I need to discuss this hierarchy. Having FieldRef extend Var is convenient, but hopefully there's a better design. * * This is always a static reference. */ public class BcelCflowAccessVar extends BcelVar { - private Member stackField; private int index; @@ -49,17 +46,18 @@ public class BcelCflowAccessVar extends BcelVar { return "BcelCflowAccessVar(" + getType() + " " + stackField + "." + index + ")"; } - public Instruction createLoad(InstructionFactory fact) { + public Instruction createLoad(InstructionFactory fact) { + throw new RuntimeException("unimplemented"); + } + + public Instruction createStore(InstructionFactory fact) { throw new RuntimeException("unimplemented"); - } - public Instruction createStore(InstructionFactory fact) { - throw new RuntimeException("unimplemented"); - } - - public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) { - throw new RuntimeException("unimplemented"); - } - + } + + public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) { + throw new RuntimeException("unimplemented"); + } + public void appendLoad(InstructionList il, InstructionFactory fact) { il.append(createLoadInstructions(getType(), fact)); } @@ -69,22 +67,16 @@ public class BcelCflowAccessVar extends BcelVar { il.append(Utility.createGet(fact, stackField)); il.append(Utility.createConstant(fact, index)); - il.append( - fact.createInvoke( - NameMangler.CFLOW_STACK_TYPE, "get", - Type.OBJECT, new Type[] { Type.INT }, + il.append(fact.createInvoke(NameMangler.CFLOW_STACK_TYPE, "get", Type.OBJECT, new Type[] { Type.INT }, Constants.INVOKEVIRTUAL)); il.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(toType))); return il; - + } - public void appendLoadAndConvert( - InstructionList il, - InstructionFactory fact, - ResolvedType toType) { - il.append(createLoadInstructions(toType, fact)); + public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedType toType) { + il.append(createLoadInstructions(toType, fact)); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelField.java b/weaver/src/org/aspectj/weaver/bcel/BcelField.java index 0bc231c7b..4383161bd 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelField.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelField.java @@ -18,8 +18,8 @@ import java.util.Iterator; import java.util.List; import org.aspectj.apache.bcel.classfile.Attribute; -import org.aspectj.apache.bcel.classfile.Field; import org.aspectj.apache.bcel.classfile.ConstantPool; +import org.aspectj.apache.bcel.classfile.Field; import org.aspectj.apache.bcel.classfile.GenericSignatureParser; import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.classfile.Synthetic; @@ -38,7 +38,7 @@ import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSigna final class BcelField extends ResolvedMemberImpl { private static int AccSynthetic = 0x1000; - + private Field field; private boolean isAjSynthetic; private boolean isSynthetic = false; @@ -48,29 +48,22 @@ final class BcelField extends ResolvedMemberImpl { private UnresolvedType genericFieldType = null; private boolean unpackedGenericSignature = false; private boolean annotationsAdded = false; - BcelField(BcelObjectType declaringType, Field field) { - super( - FIELD, - declaringType.getResolvedTypeX(), - field.getModifiers(), - field.getName(), - field.getSignature()); + super(FIELD, declaringType.getResolvedTypeX(), field.getModifiers(), field.getName(), field.getSignature()); this.field = field; this.world = declaringType.getResolvedTypeX().getWorld(); this.bcelObjectType = declaringType; unpackAttributes(world); checkedExceptions = UnresolvedType.NONE; } - + /** - * Constructs an instance that wrappers a Field object, but where we do not (yet) have - * a BcelObjectType - usually because the containing type (and this field) are being - * constructed at runtime (so there is no .class file to retrieve). + * Constructs an instance that wrappers a Field object, but where we do not (yet) have a BcelObjectType - usually because the + * containing type (and this field) are being constructed at runtime (so there is no .class file to retrieve). */ - BcelField(String declaringTypeName, Field field,World world) { - super(FIELD,UnresolvedType.forName(declaringTypeName),field.getModifiers(),field.getName(),field.getSignature()); + BcelField(String declaringTypeName, Field field, World world) { + super(FIELD, UnresolvedType.forName(declaringTypeName), field.getModifiers(), field.getName(), field.getSignature()); this.field = field; this.world = world; this.bcelObjectType = null; @@ -79,18 +72,15 @@ final class BcelField extends ResolvedMemberImpl { } // ---- - + private void unpackAttributes(World world) { Attribute[] attrs = field.getAttributes(); - if (attrs!=null && attrs.length>0) { - List as = BcelAttributes.readAjAttributes( - getDeclaringType().getClassName(), - attrs, - getSourceContext(world), - world, - (bcelObjectType!=null?bcelObjectType.getWeaverVersionAttribute():WeaverVersionInfo.CURRENT)); - as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler())); - + if (attrs != null && attrs.length > 0) { + List as = Utility.readAjAttributes(getDeclaringType().getClassName(), attrs, getSourceContext(world), world, + (bcelObjectType != null ? bcelObjectType.getWeaverVersionAttribute() : WeaverVersionInfo.CURRENT)); + as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), + getSourceContext(world), world.getMessageHandler())); + for (Iterator iter = as.iterator(); iter.hasNext();) { AjAttribute a = (AjAttribute) iter.next(); if (a instanceof AjAttribute.AjSynthetic) { @@ -101,131 +91,138 @@ final class BcelField extends ResolvedMemberImpl { } } isAjSynthetic = false; - - + for (int i = attrs.length - 1; i >= 0; i--) { - if (attrs[i] instanceof Synthetic) isSynthetic = true; + if (attrs[i] instanceof Synthetic) + isSynthetic = true; } - + // in 1.5, synthetic is a modifier, not an attribute if ((field.getModifiers() & AccSynthetic) != 0) { isSynthetic = true; } - + } - - public boolean isAjSynthetic() { return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX); } - + public boolean isSynthetic() { return isSynthetic; } - + public boolean hasAnnotation(UnresolvedType ofType) { ensureAnnotationTypesRetrieved(); for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) { ResolvedType aType = (ResolvedType) iter.next(); - if (aType.equals(ofType)) return true; + if (aType.equals(ofType)) + return true; } return false; } - + public ResolvedType[] getAnnotationTypes() { ensureAnnotationTypesRetrieved(); - ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; - annotationTypes.toArray(ret); - return ret; - } - + ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; + annotationTypes.toArray(ret); + return ret; + } + public AnnotationX[] getAnnotations() { ensureAnnotationTypesRetrieved(); return annotations; } - + public AnnotationX getAnnotationOfType(UnresolvedType ofType) { - ensureAnnotationTypesRetrieved(); - for (int i=0; i<annotations.length; i++) { - if (annotations[i].getTypeName().equals(ofType.getName())) return annotations[i]; - } - return null; - } - + ensureAnnotationTypesRetrieved(); + for (int i = 0; i < annotations.length; i++) { + if (annotations[i].getTypeName().equals(ofType.getName())) + return annotations[i]; + } + return null; + } + private void ensureAnnotationTypesRetrieved() { if (annotationTypes == null) { - AnnotationGen annos[] = field.getAnnotations(); - if (annos==null || annos.length==0) { - annotationTypes = Collections.EMPTY_SET; - annotations = AnnotationX.NONE; - } else { - annotationTypes = new HashSet(); - annotations = new AnnotationX[annos.length]; - for (int i = 0; i < annos.length; i++) { + AnnotationGen annos[] = field.getAnnotations(); + if (annos == null || annos.length == 0) { + annotationTypes = Collections.EMPTY_SET; + annotations = AnnotationX.NONE; + } else { + annotationTypes = new HashSet(); + annotations = new AnnotationX[annos.length]; + for (int i = 0; i < annos.length; i++) { AnnotationGen annotation = annos[i]; annotationTypes.add(world.resolve(UnresolvedType.forSignature(annotation.getTypeSignature()))); - annotations[i] = new AnnotationX(annotation,world); + annotations[i] = new AnnotationX(annotation, world); } - } - } + } + } } - - public void addAnnotation(AnnotationX annotation) { - ensureAnnotationTypesRetrieved(); + + public void addAnnotation(AnnotationX annotation) { + ensureAnnotationTypesRetrieved(); // Add it to the set of annotations int len = annotations.length; - AnnotationX[] ret = new AnnotationX[len+1]; + AnnotationX[] ret = new AnnotationX[len + 1]; System.arraycopy(annotations, 0, ret, 0, len); ret[len] = annotation; annotations = ret; - - if (annotationTypes==Collections.EMPTY_SET) { + + if (annotationTypes == Collections.EMPTY_SET) { annotationTypes = new HashSet(); } // Add it to the set of annotation types String typename = annotation.getTypeSignature(); annotationTypes.add(UnresolvedType.forSignature(typename).resolve(world)); - annotationsAdded=true; + annotationsAdded = true; } - + /** - * Unpack the generic signature attribute if there is one and we haven't already - * done so, then find the true field type of this field (eg. List<String>). + * Unpack the generic signature attribute if there is one and we haven't already done so, then find the true field type of this + * field (eg. List<String>). */ public UnresolvedType getGenericReturnType() { unpackGenericSignature(); return genericFieldType; } - - public Field getFieldAsIs() { return field; } - + + public Field getFieldAsIs() { + return field; + } + // FIXME asc badly performing code ftw ! - public Field getField(ConstantPool cpg) { - if (!annotationsAdded) return field; - FieldGen fg = new FieldGen(field,cpg); + public Field getField(ConstantPool cpg) { + if (!annotationsAdded) + return field; + FieldGen fg = new FieldGen(field, cpg); AnnotationGen[] alreadyHas = fg.getAnnotations(); - if (annotations!=null) { + if (annotations != null) { for (int i = 0; i < annotations.length; i++) { AnnotationX array_element = annotations[i]; boolean alreadyHasIt = false; for (int j = 0; j < alreadyHas.length; j++) { AnnotationGen gen = alreadyHas[j]; - if (gen.getTypeName().equals(array_element.getTypeName())) alreadyHasIt = true; + if (gen.getTypeName().equals(array_element.getTypeName())) + alreadyHasIt = true; } - if (!alreadyHasIt) fg.addAnnotation(new AnnotationGen(array_element.getBcelAnnotation(),cpg,true)); + if (!alreadyHasIt) + fg.addAnnotation(new AnnotationGen(array_element.getBcelAnnotation(), cpg, true)); } - } - field = fg.getField(); - annotationsAdded = false; // we are now correct again - return field; + } + field = fg.getField(); + annotationsAdded = false; // we are now correct again + return field; } - + private void unpackGenericSignature() { - if (unpackedGenericSignature) { return; } + if (unpackedGenericSignature) { + return; + } if (!world.isInJava5Mode()) { this.genericFieldType = getReturnType(); - return; + return; } unpackedGenericSignature = true; String gSig = field.getGenericSignature(); @@ -235,38 +232,33 @@ final class BcelField extends ResolvedMemberImpl { Signature.ClassSignature genericTypeSig = bcelObjectType.getGenericClassTypeSignature(); Signature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); - Signature.FormalTypeParameter[] typeVars = - ((genericTypeSig == null) ? new Signature.FormalTypeParameter[0] : genericTypeSig.formalTypeParameters); - Signature.FormalTypeParameter[] formals = - new Signature.FormalTypeParameter[parentFormals.length + typeVars.length]; + Signature.FormalTypeParameter[] typeVars = ((genericTypeSig == null) ? new Signature.FormalTypeParameter[0] + : genericTypeSig.formalTypeParameters); + Signature.FormalTypeParameter[] formals = new Signature.FormalTypeParameter[parentFormals.length + typeVars.length]; // put method formal in front of type formals for overriding in // lookup System.arraycopy(typeVars, 0, formals, 0, typeVars.length); - System.arraycopy(parentFormals, 0, formals, typeVars.length,parentFormals.length); + System.arraycopy(parentFormals, 0, formals, typeVars.length, parentFormals.length); try { - genericFieldType = BcelGenericSignatureToTypeXConverter - .fieldTypeSignature2TypeX(fts, formals, world); + genericFieldType = BcelGenericSignatureToTypeXConverter.fieldTypeSignature2TypeX(fts, formals, world); } catch (GenericSignatureFormatException e) { // development bug, fail fast with good info - throw new IllegalStateException( - "While determing the generic field type of " - + this.toString() + " with generic signature " - + gSig + " the following error was detected: " - + e.getMessage()); + throw new IllegalStateException("While determing the generic field type of " + this.toString() + + " with generic signature " + gSig + " the following error was detected: " + e.getMessage()); } } else { genericFieldType = getReturnType(); } } - - public void evictWeavingState() { - if (field != null) { - unpackGenericSignature(); - unpackAttributes(world); - ensureAnnotationTypesRetrieved(); -// this.sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT; - field = null; - } - } + + public void evictWeavingState() { + if (field != null) { + unpackGenericSignature(); + unpackAttributes(world); + ensureAnnotationTypesRetrieved(); + // this.sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT; + field = null; + } + } }
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index 25951ac7c..f443a7361 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; @@ -57,41 +56,33 @@ public final class BcelMethod extends ResolvedMemberImpl { // these fields are not set for many BcelMethods... private ShadowMunger associatedShadowMunger; - private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice + private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice private AjAttribute.EffectiveSignatureAttribute effectiveSignature; - - - private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber; - private AnnotationX[] annotations = null; - private AnnotationX[][] parameterAnnotations = null; + + private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber; + private AnnotationX[] annotations = null; + private AnnotationX[][] parameterAnnotations = null; private BcelObjectType bcelObjectType; - + private int bitflags; - private static final int KNOW_IF_SYNTHETIC = 0x0001; + private static final int KNOW_IF_SYNTHETIC = 0x0001; private static final int PARAMETER_NAMES_INITIALIZED = 0x0002; - private static final int CAN_BE_PARAMETERIZED = 0x0004; - private static final int UNPACKED_GENERIC_SIGNATURE = 0x0008; - private static final int IS_AJ_SYNTHETIC = 0x0040; - private static final int IS_SYNTHETIC = 0x0080; - private static final int IS_SYNTHETIC_INVERSE = 0x7f7f; // all bits but IS_SYNTHETIC (and topmost bit) - private static final int HAS_ANNOTATIONS = 0x0400; + private static final int CAN_BE_PARAMETERIZED = 0x0004; + private static final int UNPACKED_GENERIC_SIGNATURE = 0x0008; + private static final int IS_AJ_SYNTHETIC = 0x0040; + private static final int IS_SYNTHETIC = 0x0080; + private static final int IS_SYNTHETIC_INVERSE = 0x7f7f; // all bits but IS_SYNTHETIC (and topmost bit) + private static final int HAS_ANNOTATIONS = 0x0400; private static final int HAVE_DETERMINED_ANNOTATIONS = 0x0800; - - // genericized version of return and parameter types - private UnresolvedType genericReturnType = null; - private UnresolvedType[] genericParameterTypes = null; + // genericized version of return and parameter types + private UnresolvedType genericReturnType = null; + private UnresolvedType[] genericParameterTypes = null; BcelMethod(BcelObjectType declaringType, Method method) { - super( - method.getName().equals("<init>") ? CONSTRUCTOR : - (method.getName().equals("<clinit>") ? STATIC_INITIALIZATION : METHOD), - declaringType.getResolvedTypeX(), - declaringType.isInterface() - ? method.getModifiers() | Modifier.INTERFACE - : method.getModifiers(), - method.getName(), - method.getSignature()); + super(method.getName().equals("<init>") ? CONSTRUCTOR : (method.getName().equals("<clinit>") ? STATIC_INITIALIZATION + : METHOD), declaringType.getResolvedTypeX(), declaringType.isInterface() ? method.getModifiers() + | Modifier.INTERFACE : method.getModifiers(), method.getName(), method.getSignature()); this.method = method; this.sourceContext = declaringType.getResolvedTypeX().getSourceContext(); this.bcelObjectType = declaringType; @@ -103,66 +94,67 @@ public final class BcelMethod extends ResolvedMemberImpl { private void unpackJavaAttributes() { ExceptionTable exnTable = method.getExceptionTable(); - checkedExceptions = (exnTable == null) - ? UnresolvedType.NONE - : UnresolvedType.forNames(exnTable.getExceptionNames()); - + checkedExceptions = (exnTable == null) ? UnresolvedType.NONE : UnresolvedType.forNames(exnTable.getExceptionNames()); + } - + public String[] getParameterNames() { determineParameterNames(); return super.getParameterNames(); } - public int getLineNumberOfFirstInstruction() { - LineNumberTable lnt = method.getLineNumberTable(); - if (lnt==null) return -1; - LineNumber[] lns = lnt.getLineNumberTable(); - if (lns==null || lns.length==0) return -1; - return lns[0].getLineNumber(); - } - + public int getLineNumberOfFirstInstruction() { + LineNumberTable lnt = method.getLineNumberTable(); + if (lnt == null) + return -1; + LineNumber[] lns = lnt.getLineNumberTable(); + if (lns == null || lns.length == 0) + return -1; + return lns[0].getLineNumber(); + } + public void determineParameterNames() { - if ((bitflags&PARAMETER_NAMES_INITIALIZED)!=0) { return; } - bitflags|=PARAMETER_NAMES_INITIALIZED; + if ((bitflags & PARAMETER_NAMES_INITIALIZED) != 0) { + return; + } + bitflags |= PARAMETER_NAMES_INITIALIZED; LocalVariableTable varTable = method.getLocalVariableTable(); int len = getArity(); if (varTable == null) { // do we have an annotation with the argNames value specified... if (hasAnnotations()) { AnnotationX[] axs = getAnnotations(); - for (int i = 0; i < axs.length; i++) { + for (int i = 0; i < axs.length; i++) { AnnotationX annotationX = axs[i]; String typename = annotationX.getTypeName(); - if (typename.equals("org.aspectj.lang.annotation.Pointcut") || - typename.equals("org.aspectj.lang.annotation.Before") || - typename.equals("org.aspectj.lang.annotation.Around") || - typename.startsWith("org.aspectj.lang.annotation.After")) { + if (typename.equals("org.aspectj.lang.annotation.Pointcut") + || typename.equals("org.aspectj.lang.annotation.Before") + || typename.equals("org.aspectj.lang.annotation.Around") + || typename.startsWith("org.aspectj.lang.annotation.After")) { AnnotationGen a = annotationX.getBcelAnnotation(); - if (a!=null) { + if (a != null) { List values = a.getValues(); - for (Iterator iterator = values.iterator(); iterator - .hasNext();) { + for (Iterator iterator = values.iterator(); iterator.hasNext();) { ElementNameValuePairGen nvPair = (ElementNameValuePairGen) iterator.next(); if (nvPair.getNameString().equals("argNames")) { String argNames = nvPair.getValue().stringifyValue(); - StringTokenizer argNameTokenizer = new StringTokenizer(argNames," ,"); + StringTokenizer argNameTokenizer = new StringTokenizer(argNames, " ,"); List argsList = new ArrayList(); while (argNameTokenizer.hasMoreTokens()) { argsList.add(argNameTokenizer.nextToken()); } int requiredCount = getParameterTypes().length; - while (argsList.size()<requiredCount) { - argsList.add("arg"+argsList.size()); + while (argsList.size() < requiredCount) { + argsList.add("arg" + argsList.size()); } - setParameterNames((String[])argsList.toArray(new String[]{})); + setParameterNames((String[]) argsList.toArray(new String[] {})); return; } } } } } - } + } setParameterNames(Utility.makeArgNames(len)); } else { UnresolvedType[] paramTypes = getParameterTypes(); @@ -183,91 +175,95 @@ public final class BcelMethod extends ResolvedMemberImpl { private void unpackAjAttributes(World world) { associatedShadowMunger = null; - List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute()); + List as = Utility.readAjAttributes(getDeclaringType().getClassName(), method.getAttributes(), getSourceContext(world), + world, bcelObjectType.getWeaverVersionAttribute()); + processAttributes(world, as); + as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut, + getSourceContext(world), world.getMessageHandler()); processAttributes(world, as); - as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler()); - processAttributes(world,as); } private void processAttributes(World world, List as) { for (Iterator iter = as.iterator(); iter.hasNext();) { AjAttribute a = (AjAttribute) iter.next(); if (a instanceof AjAttribute.MethodDeclarationLineNumberAttribute) { - declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a; + declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute) a; } else if (a instanceof AjAttribute.AdviceAttribute) { - associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world); + associatedShadowMunger = ((AjAttribute.AdviceAttribute) a).reify(this, world); // return; } else if (a instanceof AjAttribute.AjSynthetic) { - bitflags|=IS_AJ_SYNTHETIC; -// isAjSynthetic = true; + bitflags |= IS_AJ_SYNTHETIC; + // isAjSynthetic = true; } else if (a instanceof AjAttribute.EffectiveSignatureAttribute) { - //System.out.println("found effective: " + this); - effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a; + // System.out.println("found effective: " + this); + effectiveSignature = (AjAttribute.EffectiveSignatureAttribute) a; } else if (a instanceof AjAttribute.PointcutDeclarationAttribute) { // this is an @AspectJ annotated advice method, with pointcut pre-resolved by ajc - preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify(); + preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute) a).reify(); } else { throw new BCException("weird method attribute " + a); } } } - - // for testing - if we have this attribute, return it - will return null if it doesnt know anything + + // for testing - if we have this attribute, return it - will return null if it doesnt know anything public AjAttribute[] getAttributes(String name) { List results = new ArrayList(); - List l = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(bcelObjectType.getWorld()),bcelObjectType.getWorld(),bcelObjectType.getWeaverVersionAttribute()); + List l = Utility.readAjAttributes(getDeclaringType().getClassName(), method.getAttributes(), + getSourceContext(bcelObjectType.getWorld()), bcelObjectType.getWorld(), bcelObjectType.getWeaverVersionAttribute()); for (Iterator iter = l.iterator(); iter.hasNext();) { - AjAttribute element = (AjAttribute) iter.next(); - if (element.getNameString().equals(name)) results.add(element); + AjAttribute element = (AjAttribute) iter.next(); + if (element.getNameString().equals(name)) + results.add(element); } - if (results.size()>0) { - return (AjAttribute[])results.toArray(new AjAttribute[]{}); + if (results.size() > 0) { + return (AjAttribute[]) results.toArray(new AjAttribute[] {}); } return null; } - + public String getAnnotationDefaultValue() { Attribute[] attrs = method.getAttributes(); for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + Attribute attribute = attrs[i]; if (attribute.getName().equals("AnnotationDefault")) { - AnnotationDefault def = (AnnotationDefault)attribute; + AnnotationDefault def = (AnnotationDefault) attribute; return def.getElementValue().stringifyValue(); } } return null; } - + // for testing - use with the method above public String[] getAttributeNames(boolean onlyIncludeAjOnes) { Attribute[] as = method.getAttributes(); List names = new ArrayList(); -// String[] strs = new String[as.length]; + // String[] strs = new String[as.length]; for (int j = 0; j < as.length; j++) { if (!onlyIncludeAjOnes || as[j].getName().startsWith(AjAttribute.AttributePrefix)) - names.add(as[j].getName()); + names.add(as[j].getName()); } - return (String[])names.toArray(new String[]{}); + return (String[]) names.toArray(new String[] {}); } public boolean isAjSynthetic() { - return (bitflags&IS_AJ_SYNTHETIC)!=0;//isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX); + return (bitflags & IS_AJ_SYNTHETIC) != 0;// isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX); } - - //FIXME ??? needs an isSynthetic method - + + // FIXME ??? needs an isSynthetic method + public ShadowMunger getAssociatedShadowMunger() { return associatedShadowMunger; } - + public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() { return effectiveSignature; } - + public boolean hasDeclarationLineNumberInfo() { return declarationLineNumber != null; } - + public int getDeclarationLineNumber() { if (declarationLineNumber != null) { return declarationLineNumber.getLineNumber(); @@ -276,25 +272,27 @@ public final class BcelMethod extends ResolvedMemberImpl { } } - public int getDeclarationOffset() { - if (declarationLineNumber != null) { - return declarationLineNumber.getOffset(); - } else { - return -1; - } - } - - public ISourceLocation getSourceLocation() { - ISourceLocation ret = super.getSourceLocation(); - if ((ret == null || ret.getLine()==0) && hasDeclarationLineNumberInfo()) { - // lets see if we can do better - ISourceContext isc = getSourceContext(); - if (isc !=null) ret = isc.makeSourceLocation(getDeclarationLineNumber(), getDeclarationOffset()); - else ret = new SourceLocation(null,getDeclarationLineNumber()); - } - return ret; - } - + public int getDeclarationOffset() { + if (declarationLineNumber != null) { + return declarationLineNumber.getOffset(); + } else { + return -1; + } + } + + public ISourceLocation getSourceLocation() { + ISourceLocation ret = super.getSourceLocation(); + if ((ret == null || ret.getLine() == 0) && hasDeclarationLineNumberInfo()) { + // lets see if we can do better + ISourceContext isc = getSourceContext(); + if (isc != null) + ret = isc.makeSourceLocation(getDeclarationLineNumber(), getDeclarationOffset()); + else + ret = new SourceLocation(null, getDeclarationLineNumber()); + } + return ret; + } + public MemberKind getKind() { if (associatedShadowMunger != null) { return ADVICE; @@ -302,280 +300,282 @@ public final class BcelMethod extends ResolvedMemberImpl { return super.getKind(); } } - + public boolean hasAnnotation(UnresolvedType ofType) { ensureAnnotationsRetrieved(); for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) { ResolvedType aType = (ResolvedType) iter.next(); - if (aType.equals(ofType)) return true; + if (aType.equals(ofType)) + return true; } return false; } - + public AnnotationX[] getAnnotations() { ensureAnnotationsRetrieved(); - if ((bitflags&HAS_ANNOTATIONS)!=0) { + if ((bitflags & HAS_ANNOTATIONS) != 0) { return annotations; } else { return AnnotationX.NONE; } } - - public ResolvedType[] getAnnotationTypes() { - ensureAnnotationsRetrieved(); - ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; - annotationTypes.toArray(ret); - return ret; - } - - - public AnnotationX getAnnotationOfType(UnresolvedType ofType) { - ensureAnnotationsRetrieved(); - if ((bitflags&HAS_ANNOTATIONS)==0) return null; - for (int i=0; i<annotations.length; i++) { - if (annotations[i].getTypeName().equals(ofType.getName())) return annotations[i]; - } - return null; - } - - public void addAnnotation(AnnotationX annotation) { - ensureAnnotationsRetrieved(); - if ((bitflags&HAS_ANNOTATIONS)==0) { + + public ResolvedType[] getAnnotationTypes() { + ensureAnnotationsRetrieved(); + ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; + annotationTypes.toArray(ret); + return ret; + } + + public AnnotationX getAnnotationOfType(UnresolvedType ofType) { + ensureAnnotationsRetrieved(); + if ((bitflags & HAS_ANNOTATIONS) == 0) + return null; + for (int i = 0; i < annotations.length; i++) { + if (annotations[i].getTypeName().equals(ofType.getName())) + return annotations[i]; + } + return null; + } + + public void addAnnotation(AnnotationX annotation) { + ensureAnnotationsRetrieved(); + if ((bitflags & HAS_ANNOTATIONS) == 0) { annotations = new AnnotationX[1]; - annotations[0]=annotation; - } else { + annotations[0] = annotation; + } else { // Add it to the set of annotations int len = annotations.length; - AnnotationX[] ret = new AnnotationX[len+1]; + AnnotationX[] ret = new AnnotationX[len + 1]; System.arraycopy(annotations, 0, ret, 0, len); ret[len] = annotation; annotations = ret; } - bitflags|=HAS_ANNOTATIONS; - + bitflags |= HAS_ANNOTATIONS; + // Add it to the set of annotation types - if (annotationTypes==Collections.EMPTY_SET) annotationTypes = new HashSet(); + if (annotationTypes == Collections.EMPTY_SET) + annotationTypes = new HashSet(); annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(bcelObjectType.getWorld())); // FIXME asc looks like we are managing two 'bunches' of annotations, one // here and one in the real 'method' - should we reduce it to one layer? -// method.addAnnotation(annotation.getBcelAnnotation()); - } - - private void ensureAnnotationsRetrieved() { - if (method == null) return; // must be ok, we have evicted it - if ((bitflags&HAVE_DETERMINED_ANNOTATIONS)!=0) return; - bitflags|=HAVE_DETERMINED_ANNOTATIONS; - - AnnotationGen annos[] = method.getAnnotations(); - if (annos.length!=0) { - annotationTypes = new HashSet(); - annotations = new AnnotationX[annos.length]; - for (int i = 0; i < annos.length; i++) { - AnnotationGen annotation = annos[i]; - annotationTypes.add(bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annotation.getTypeSignature()))); - annotations[i] = new AnnotationX(annotation,bcelObjectType.getWorld()); - } - bitflags|=HAS_ANNOTATIONS; - } else { - annotationTypes=Collections.EMPTY_SET; - } - } - + // method.addAnnotation(annotation.getBcelAnnotation()); + } + + private void ensureAnnotationsRetrieved() { + if (method == null) + return; // must be ok, we have evicted it + if ((bitflags & HAVE_DETERMINED_ANNOTATIONS) != 0) + return; + bitflags |= HAVE_DETERMINED_ANNOTATIONS; + + AnnotationGen annos[] = method.getAnnotations(); + if (annos.length != 0) { + annotationTypes = new HashSet(); + annotations = new AnnotationX[annos.length]; + for (int i = 0; i < annos.length; i++) { + AnnotationGen annotation = annos[i]; + annotationTypes.add(bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annotation.getTypeSignature()))); + annotations[i] = new AnnotationX(annotation, bcelObjectType.getWorld()); + } + bitflags |= HAS_ANNOTATIONS; + } else { + annotationTypes = Collections.EMPTY_SET; + } + } + private void ensureParameterAnnotationsRetrieved() { - if (method == null) return; // must be ok, we have evicted it + if (method == null) + return; // must be ok, we have evicted it AnnotationGen[][] pAnns = method.getParameterAnnotations(); - if (parameterAnnotationTypes==null || pAnns.length!=parameterAnnotationTypes.length) { + if (parameterAnnotationTypes == null || pAnns.length != parameterAnnotationTypes.length) { if (pAnns == Method.NO_PARAMETER_ANNOTATIONS) { parameterAnnotationTypes = BcelMethod.NO_PARAMETER_ANNOTATION_TYPES; - parameterAnnotations = BcelMethod.NO_PARAMETER_ANNOTATIONXS; + parameterAnnotations = BcelMethod.NO_PARAMETER_ANNOTATIONXS; } else { AnnotationGen annos[][] = method.getParameterAnnotations(); parameterAnnotations = new AnnotationX[annos.length][]; parameterAnnotationTypes = new ResolvedType[annos.length][]; - for (int i=0;i<annos.length;i++) { + for (int i = 0; i < annos.length; i++) { parameterAnnotations[i] = new AnnotationX[annos[i].length]; parameterAnnotationTypes[i] = new ResolvedType[annos[i].length]; - for (int j=0;j<annos[i].length;j++) { - parameterAnnotations[i][j] = new AnnotationX(annos[i][j],bcelObjectType.getWorld()); - parameterAnnotationTypes[i][j] = bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annos[i][j].getTypeSignature())); + for (int j = 0; j < annos[i].length; j++) { + parameterAnnotations[i][j] = new AnnotationX(annos[i][j], bcelObjectType.getWorld()); + parameterAnnotationTypes[i][j] = bcelObjectType.getWorld().resolve( + UnresolvedType.forSignature(annos[i][j].getTypeSignature())); } } } } } - public AnnotationX[][] getParameterAnnotations() { + public AnnotationX[][] getParameterAnnotations() { ensureParameterAnnotationsRetrieved(); return parameterAnnotations; } - - public ResolvedType[][] getParameterAnnotationTypes() { + + public ResolvedType[][] getParameterAnnotationTypes() { ensureParameterAnnotationsRetrieved(); return parameterAnnotationTypes; } - - - /** - * A method can be parameterized if it has one or more generic - * parameters. A generic parameter (type variable parameter) is - * identified by the prefix "T" - */ - public boolean canBeParameterized() { - unpackGenericSignature(); - return (bitflags & CAN_BE_PARAMETERIZED)!=0; - } - - - public UnresolvedType[] getGenericParameterTypes() { - unpackGenericSignature(); - return genericParameterTypes; - } - - /** - * Return the parameterized/generic return type or the normal return type if the method is not generic. - */ - public UnresolvedType getGenericReturnType() { - unpackGenericSignature(); - return genericReturnType; - } - - /** For testing only */ - public Method getMethod() { return method; } - - private void unpackGenericSignature() { - if ((bitflags&UNPACKED_GENERIC_SIGNATURE)!=0) { return; } - bitflags|=UNPACKED_GENERIC_SIGNATURE; - if (!bcelObjectType.getWorld().isInJava5Mode()) { - this.genericReturnType = getReturnType(); - this.genericParameterTypes = getParameterTypes(); - return; - } - String gSig = method.getGenericSignature(); - if (gSig != null) { - Signature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);//method.getGenericSignature()); - if (mSig.formalTypeParameters.length > 0) { + + /** + * A method can be parameterized if it has one or more generic parameters. A generic parameter (type variable parameter) is + * identified by the prefix "T" + */ + public boolean canBeParameterized() { + unpackGenericSignature(); + return (bitflags & CAN_BE_PARAMETERIZED) != 0; + } + + public UnresolvedType[] getGenericParameterTypes() { + unpackGenericSignature(); + return genericParameterTypes; + } + + /** + * Return the parameterized/generic return type or the normal return type if the method is not generic. + */ + public UnresolvedType getGenericReturnType() { + unpackGenericSignature(); + return genericReturnType; + } + + /** For testing only */ + public Method getMethod() { + return method; + } + + private void unpackGenericSignature() { + if ((bitflags & UNPACKED_GENERIC_SIGNATURE) != 0) { + return; + } + bitflags |= UNPACKED_GENERIC_SIGNATURE; + if (!bcelObjectType.getWorld().isInJava5Mode()) { + this.genericReturnType = getReturnType(); + this.genericParameterTypes = getParameterTypes(); + return; + } + String gSig = method.getGenericSignature(); + if (gSig != null) { + Signature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);// method. + // getGenericSignature + // ()); + if (mSig.formalTypeParameters.length > 0) { // generic method declaration - bitflags|=CAN_BE_PARAMETERIZED; - } - - typeVariables = new TypeVariable[mSig.formalTypeParameters.length]; - for (int i = 0; i < typeVariables.length; i++) { + bitflags |= CAN_BE_PARAMETERIZED; + } + + typeVariables = new TypeVariable[mSig.formalTypeParameters.length]; + for (int i = 0; i < typeVariables.length; i++) { Signature.FormalTypeParameter methodFtp = mSig.formalTypeParameters[i]; try { - typeVariables[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable( - methodFtp, - mSig.formalTypeParameters, - bcelObjectType.getWorld()); + typeVariables[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(methodFtp, + mSig.formalTypeParameters, bcelObjectType.getWorld()); } catch (GenericSignatureFormatException e) { // this is a development bug, so fail fast with good info - throw new IllegalStateException( - "While getting the type variables for method " + this.toString() - + " with generic signature " + mSig + - " the following error condition was detected: " + e.getMessage()); + throw new IllegalStateException("While getting the type variables for method " + this.toString() + + " with generic signature " + mSig + " the following error condition was detected: " + e.getMessage()); } - } - - Signature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); - Signature.FormalTypeParameter[] formals = new - Signature.FormalTypeParameter[parentFormals.length + mSig.formalTypeParameters.length]; - // put method formal in front of type formals for overriding in lookup - System.arraycopy(mSig.formalTypeParameters,0,formals,0,mSig.formalTypeParameters.length); - System.arraycopy(parentFormals,0,formals,mSig.formalTypeParameters.length,parentFormals.length); - Signature.TypeSignature returnTypeSignature = mSig.returnType; - try { - genericReturnType = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX( - returnTypeSignature, formals, - bcelObjectType.getWorld()); + } + + Signature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); + Signature.FormalTypeParameter[] formals = new Signature.FormalTypeParameter[parentFormals.length + + mSig.formalTypeParameters.length]; + // put method formal in front of type formals for overriding in lookup + System.arraycopy(mSig.formalTypeParameters, 0, formals, 0, mSig.formalTypeParameters.length); + System.arraycopy(parentFormals, 0, formals, mSig.formalTypeParameters.length, parentFormals.length); + Signature.TypeSignature returnTypeSignature = mSig.returnType; + try { + genericReturnType = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(returnTypeSignature, formals, + bcelObjectType.getWorld()); } catch (GenericSignatureFormatException e) { -// development bug, fail fast with good info - throw new IllegalStateException( - "While determing the generic return type of " + this.toString() - + " with generic signature " + gSig + " the following error was detected: " - + e.getMessage()); + // development bug, fail fast with good info + throw new IllegalStateException("While determing the generic return type of " + this.toString() + + " with generic signature " + gSig + " the following error was detected: " + e.getMessage()); } - Signature.TypeSignature[] paramTypeSigs = mSig.parameters; - genericParameterTypes = new UnresolvedType[paramTypeSigs.length]; - for (int i = 0; i < paramTypeSigs.length; i++) { + Signature.TypeSignature[] paramTypeSigs = mSig.parameters; + genericParameterTypes = new UnresolvedType[paramTypeSigs.length]; + for (int i = 0; i < paramTypeSigs.length; i++) { try { - genericParameterTypes[i] = - BcelGenericSignatureToTypeXConverter.typeSignature2TypeX( - paramTypeSigs[i],formals,bcelObjectType.getWorld()); + genericParameterTypes[i] = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(paramTypeSigs[i], formals, + bcelObjectType.getWorld()); } catch (GenericSignatureFormatException e) { -// development bug, fail fast with good info - throw new IllegalStateException( - "While determining the generic parameter types of " + this.toString() - + " with generic signature " + gSig + " the following error was detected: " - + e.getMessage()); + // development bug, fail fast with good info + throw new IllegalStateException("While determining the generic parameter types of " + this.toString() + + " with generic signature " + gSig + " the following error was detected: " + e.getMessage()); } if (paramTypeSigs[i] instanceof TypeVariableSignature) { - bitflags|=CAN_BE_PARAMETERIZED; + bitflags |= CAN_BE_PARAMETERIZED; } - } - } else { - genericReturnType = getReturnType(); - genericParameterTypes = getParameterTypes(); - } - } - - public void evictWeavingState() { - if (method != null) { - unpackGenericSignature(); - unpackJavaAttributes(); - ensureAnnotationsRetrieved(); - ensureParameterAnnotationsRetrieved(); - determineParameterNames(); -// this.sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT; - method = null; - } - } + } + } else { + genericReturnType = getReturnType(); + genericParameterTypes = getParameterTypes(); + } + } + + public void evictWeavingState() { + if (method != null) { + unpackGenericSignature(); + unpackJavaAttributes(); + ensureAnnotationsRetrieved(); + ensureParameterAnnotationsRetrieved(); + determineParameterNames(); + // this.sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT; + method = null; + } + } public boolean isSynthetic() { - if ((bitflags&KNOW_IF_SYNTHETIC)==0) { + if ((bitflags & KNOW_IF_SYNTHETIC) == 0) { workOutIfSynthetic(); } - return (bitflags&IS_SYNTHETIC)!=0;//isSynthetic; + return (bitflags & IS_SYNTHETIC) != 0;// isSynthetic; } // Pre Java5 synthetic is an attribute 'Synthetic', post Java5 it is a modifier (4096 or 0x1000) private void workOutIfSynthetic() { - if ((bitflags&KNOW_IF_SYNTHETIC)!=0) return; - bitflags|=KNOW_IF_SYNTHETIC; + if ((bitflags & KNOW_IF_SYNTHETIC) != 0) + return; + bitflags |= KNOW_IF_SYNTHETIC; JavaClass jc = bcelObjectType.getJavaClass(); - bitflags&=IS_SYNTHETIC_INVERSE; // unset the bit - if (jc==null) return; // what the hell has gone wrong? - if (jc.getMajor()<49/*Java5*/) { + bitflags &= IS_SYNTHETIC_INVERSE; // unset the bit + if (jc == null) + return; // what the hell has gone wrong? + if (jc.getMajor() < 49/* Java5 */) { // synthetic is an attribute - String[] synthetics = getAttributeNames(false); - if (synthetics!=null) { + String[] synthetics = getAttributeNames(false); + if (synthetics != null) { for (int i = 0; i < synthetics.length; i++) { if (synthetics[i].equals("Synthetic")) { - bitflags|=IS_SYNTHETIC; - break;} + bitflags |= IS_SYNTHETIC; + break; + } } } } else { // synthetic is a modifier (4096) - if ((modifiers&4096)!=0) { - bitflags|=IS_SYNTHETIC; + if ((modifiers & 4096) != 0) { + bitflags |= IS_SYNTHETIC; } } } /** - * Returns whether or not the given object is equivalent to the - * current one. Returns true if getMethod().getCode().getCodeString() - * are equal. Allows for different line number tables. + * Returns whether or not the given object is equivalent to the current one. Returns true if + * getMethod().getCode().getCodeString() are equal. Allows for different line number tables. */ // bug 154054: is similar to equals(Object) however // doesn't require implementing equals in Method and Code - // which proved expensive. Currently used within + // which proved expensive. Currently used within // CrosscuttingMembers.replaceWith() to decide if we need // to do a full build - public boolean isEquivalentTo(Object other) { - if(! (other instanceof BcelMethod)) return false; - BcelMethod o = (BcelMethod)other; - return getMethod().getCode().getCodeString().equals( - o.getMethod().getCode().getCodeString()); + public boolean isEquivalentTo(Object other) { + if (!(other instanceof BcelMethod)) + return false; + BcelMethod o = (BcelMethod) other; + return getMethod().getCode().getCodeString().equals(o.getMethod().getCode().getCodeString()); } }
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 1392a80d7..4fbab9af4 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -338,7 +338,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { bitflag |= UNPACKED_AJATTRIBUTES; IMessageHandler msgHandler = getResolvedTypeX().getWorld().getMessageHandler(); // Pass in empty list that can store things for readAj5 to process - List l = BcelAttributes.readAjAttributes(className, javaClass.getAttributes(), getResolvedTypeX().getSourceContext(), + List l = Utility.readAjAttributes(className, javaClass.getAttributes(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld(), AjAttribute.WeaverVersionInfo.UNKNOWN); List pointcuts = new ArrayList(); typeMungers = new ArrayList(); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index da844cbff..c753f7472 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -113,7 +113,7 @@ import org.aspectj.weaver.patterns.ThisOrTargetPointcut; * supposedly don't have a target (according to AspectJ), but they clearly * do have a target of sorts, just one that needs to be pushed on the stack, * dupped, and not touched otherwise until the constructor runs. - * + * * @author Jim Hugunin * @author Erik Hilsdale * diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index c3623b896..fd073f079 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -514,8 +514,8 @@ public final class LazyMethodGen implements Traceable { if (enclosingClass != null && enclosingClass.getType() != null) { context = enclosingClass.getType().getSourceContext(); } - List as = BcelAttributes.readAjAttributes(getClassName(), (Attribute[]) attributes.toArray(new Attribute[] {}), context, - null, weaverVersion); + List as = Utility.readAjAttributes(getClassName(), (Attribute[]) attributes.toArray(new Attribute[] {}), context, null, + weaverVersion); if (!as.isEmpty()) { out.println(" " + as.get(0)); // XXX assuming exactly one attribute, munger... } diff --git a/weaver/src/org/aspectj/weaver/bcel/Utility.java b/weaver/src/org/aspectj/weaver/bcel/Utility.java index 9eb24e9b8..901168efb 100644 --- a/weaver/src/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/org/aspectj/weaver/bcel/Utility.java @@ -56,13 +56,54 @@ import org.aspectj.bridge.ISourceLocation; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AnnotationX; import org.aspectj.weaver.BCException; +import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.Lint; import org.aspectj.weaver.Member; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; public class Utility { + public static List readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, + AjAttribute.WeaverVersionInfo version) { + List l = new ArrayList(); + + // first pass, look for version + List forSecondPass = new ArrayList(); + for (int i = as.length - 1; i >= 0; i--) { + Attribute a = as[i]; + if (a instanceof Unknown) { + Unknown u = (Unknown) a; + String name = u.getName(); + if (name.charAt(0) == 'o') { // 'o'rg.aspectj + if (name.startsWith(AjAttribute.AttributePrefix)) { + if (name.endsWith(WeaverVersionInfo.AttributeName)) { + version = (AjAttribute.WeaverVersionInfo) AjAttribute.read(version, name, u.getBytes(), context, w); + if (version.getMajorVersion() > WeaverVersionInfo.getCurrentWeaverMajorVersion()) { + throw new BCException( + "Unable to continue, this version of AspectJ supports classes built with weaver version " + + WeaverVersionInfo.toCurrentVersionString() + " but the class " + classname + + " is version " + version.toString()); + } + } + forSecondPass.add(a); + } + } + } + } + + for (int i = forSecondPass.size() - 1; i >= 0; i--) { + Unknown a = (Unknown) forSecondPass.get(i); + String name = a.getName(); + AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w); + if (attr != null) + l.add(attr); + } + return l; + } + /* * Ensure we report a nice source location - particular in the case where the source info is missing (binary weave). */ diff --git a/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java index 5b58c3fe0..028fbc776 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java @@ -39,20 +39,28 @@ import org.aspectj.weaver.World; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; import org.aspectj.weaver.ast.Var; -import org.aspectj.weaver.bcel.AnnotationAccessFieldVar; import org.aspectj.weaver.bcel.AnnotationAccessVar; import org.aspectj.weaver.bcel.BcelTypeMunger; /** - * @annotation(@Foo) or @annotation(foo) + * (at)Annotation((at)Foo) or (at)Annotation(foo)<br> + * <p> + * Matches any join point where the subject of the join point has an annotation matching the annotationTypePattern: * - * Matches any join point where the subject of the join point has an annotation matching the - * annotationTypePattern: - * - * Join Point Kind Subject ================================ method call the target method method execution the - * method constructor call the constructor constructor execution the constructor get the target field set the - * target field adviceexecution the advice initialization the constructor preinitialization the constructor - * staticinitialization the type being initialized handler the declared type of the handled exception + * <br> + * Join Point Kind - Subject <br> + * ================================ <br> + * method call - the target method <br> + * method execution - the method <br> + * constructor call - the constructor <br> + * constructor execution - the constructor <br> + * get - the target field <br> + * set - the target field <br> + * adviceexecution - the advice <br> + * initialization - the constructor <br> + * preinitialization - the constructor <br> + * staticinitialization - the type being initialized <br> + * handler - the declared type of the handled exception <br> */ public class AnnotationPointcut extends NameBindingPointcut { @@ -205,7 +213,7 @@ public class AnnotationPointcut extends NameBindingPointcut { if (var == null) { throw new BCException("Unexpected problem locating annotation at join point '" + shadow + "'"); } - state.set(btp.getFormalIndex(), new AnnotationAccessFieldVar(var, (ResolvedType) formalType)); + state.set(btp.getFormalIndex(), var.getAccessorForValue(formalType)); } else if (annotationTypePattern instanceof BindingAnnotationTypePattern) { BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern) annotationTypePattern; UnresolvedType annotationType = btp.getAnnotationType(); diff --git a/weaver/testsrc/org/aspectj/weaver/TestUtils.java b/weaver/testsrc/org/aspectj/weaver/TestUtils.java index 9be8f50bb..456cd2bfc 100644 --- a/weaver/testsrc/org/aspectj/weaver/TestUtils.java +++ b/weaver/testsrc/org/aspectj/weaver/TestUtils.java @@ -15,11 +15,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; -import org.aspectj.weaver.bcel.BcelAdvice; -import org.aspectj.weaver.patterns.FormalBinding; -import org.aspectj.weaver.patterns.Pointcut; -import org.aspectj.weaver.patterns.SimpleScope; - public class TestUtils { private static final String[] ZERO_STRINGS = new String[0]; @@ -289,7 +284,7 @@ public class TestUtils { return MemberImpl.method(declaringTy, mods, returnTy, name, UnresolvedType.forNames(paramTypeNames)); } - private static String[] parseIds(String str) { + public static String[] parseIds(String str) { if (str.length() == 0) return ZERO_STRINGS; List l = new ArrayList(); @@ -306,44 +301,4 @@ public class TestUtils { return (String[]) l.toArray(new String[l.size()]); } - /** - * Moved from BcelWorld to here - * - * Parse a string into advice. - * - * <blockquote> - * - * <pre> - * Kind ( Id , ... ) : Pointcut -> MethodSignature - * </pre> - * - * </blockquote> - */ - public static Advice shadowMunger(World w, String str, int extraFlag) { - str = str.trim(); - int start = 0; - int i = str.indexOf('('); - AdviceKind kind = AdviceKind.stringToKind(str.substring(start, i)); - start = ++i; - i = str.indexOf(')', i); - String[] ids = parseIds(str.substring(start, i).trim()); - // start = ++i; - - i = str.indexOf(':', i); - start = ++i; - i = str.indexOf("->", i); - Pointcut pointcut = Pointcut.fromString(str.substring(start, i).trim()); - Member m = TestUtils.methodFromString(str.substring(i + 2, str.length()).trim()); - - // now, we resolve - UnresolvedType[] types = m.getParameterTypes(); - FormalBinding[] bindings = new FormalBinding[ids.length]; - for (int j = 0, len = ids.length; j < len; j++) { - bindings[j] = new FormalBinding(types[j], ids[j], j, 0, 0); - } - - Pointcut p = pointcut.resolve(new SimpleScope(w, bindings)); - - return new BcelAdvice(kind, p, m, extraFlag, 0, 0, null, null); - } } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java index 8e2a54042..b0c3f04ce 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java @@ -10,12 +10,13 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.io.IOException; -import org.aspectj.weaver.*; +import org.aspectj.weaver.Advice; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ShadowMunger; public class AfterThrowingWeaveTestCase extends WeaveTestCase { { @@ -25,19 +26,20 @@ public class AfterThrowingWeaveTestCase extends WeaveTestCase { public AfterThrowingWeaveTestCase(String name) { super(name); } - + public void testAfterThrowing() throws IOException { weaveTest(getStandardTargets(), "AfterThrowing", makeAdviceAll("afterThrowing")); } - public void testAfterThrowingParam() throws IOException { - BcelWorld world = new BcelWorld(); - - ShadowMunger myMunger = - TestUtils.shadowMunger(world,"afterThrowing(): get(* *.out) -> static void Aspect.ajc_afterThrowing_field_get(java.lang.Throwable)", - Advice.ExtraArgument); - ShadowMunger cm = myMunger.concretize(ResolvedType.MISSING, world, null); - - weaveTest(getStandardTargets(), "AfterThrowingParam", cm); - } + + public void testAfterThrowingParam() throws IOException { + BcelWorld world = new BcelWorld(); + + ShadowMunger myMunger = BcelTestUtils.shadowMunger(world, + "afterThrowing(): get(* *.out) -> static void Aspect.ajc_afterThrowing_field_get(java.lang.Throwable)", + Advice.ExtraArgument); + ShadowMunger cm = myMunger.concretize(ResolvedType.MISSING, world, null); + + weaveTest(getStandardTargets(), "AfterThrowingParam", cm); + } } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java b/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java new file mode 100644 index 000000000..bc9f47a85 --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 2008 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.weaver.bcel; + +import org.aspectj.weaver.Advice; +import org.aspectj.weaver.AdviceKind; +import org.aspectj.weaver.Member; +import org.aspectj.weaver.TestUtils; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.patterns.FormalBinding; +import org.aspectj.weaver.patterns.Pointcut; +import org.aspectj.weaver.patterns.SimpleScope; + +public class BcelTestUtils { + /** + * Moved from BcelWorld to here + * + * Parse a string into advice. + * + * <blockquote> + * + * <pre> + * Kind ( Id , ... ) : Pointcut -> MethodSignature + * </pre> + * + * </blockquote> + */ + public static Advice shadowMunger(World w, String str, int extraFlag) { + str = str.trim(); + int start = 0; + int i = str.indexOf('('); + AdviceKind kind = AdviceKind.stringToKind(str.substring(start, i)); + start = ++i; + i = str.indexOf(')', i); + String[] ids = TestUtils.parseIds(str.substring(start, i).trim()); + // start = ++i; + + i = str.indexOf(':', i); + start = ++i; + i = str.indexOf("->", i); + Pointcut pointcut = Pointcut.fromString(str.substring(start, i).trim()); + Member m = TestUtils.methodFromString(str.substring(i + 2, str.length()).trim()); + + // now, we resolve + UnresolvedType[] types = m.getParameterTypes(); + FormalBinding[] bindings = new FormalBinding[ids.length]; + for (int j = 0, len = ids.length; j < len; j++) { + bindings[j] = new FormalBinding(types[j], ids[j], j, 0, 0); + } + + Pointcut p = pointcut.resolve(new SimpleScope(w, bindings)); + + return new BcelAdvice(kind, p, m, extraFlag, 0, 0, null, null); + } +} diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java index 05ff1257e..656020656 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java @@ -10,19 +10,32 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; -import java.io.*; -import java.util.*; -import junit.framework.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; import org.aspectj.apache.bcel.Constants; -import org.aspectj.apache.bcel.generic.*; -import org.aspectj.weaver.*; -import org.aspectj.weaver.patterns.*; +import org.aspectj.apache.bcel.generic.InstructionFactory; +import org.aspectj.apache.bcel.generic.InstructionList; +import org.aspectj.apache.bcel.generic.InvokeInstruction; +import org.aspectj.apache.bcel.generic.Type; import org.aspectj.testing.util.TestUtil; import org.aspectj.util.FileUtil; +import org.aspectj.weaver.Advice; +import org.aspectj.weaver.BcweaverTests; +import org.aspectj.weaver.ShadowMunger; +import org.aspectj.weaver.patterns.FormalBinding; +import org.aspectj.weaver.patterns.PerClause; +import org.aspectj.weaver.patterns.Pointcut; +import org.aspectj.weaver.patterns.SimpleScope; public abstract class WeaveTestCase extends TestCase { @@ -30,92 +43,82 @@ public abstract class WeaveTestCase extends TestCase { public boolean runTests = true; public boolean behave15 = false; - File outDir; - String outDirPath; - + File outDir; + String outDirPath; + public BcelWorld world = new BcelWorld(); - { - world.addPath(classDir); - // Some of the tests in here rely on comparing output from dumping the delegates - if - // we are using ASM delegates we don't know the names of parameters (they are irrelevant...) - // and are missing from the dumping of asm delegates. This switch ensures we - // continue to use BCEL for these tests. -// world.setFastDelegateSupport(false); - } - - public WeaveTestCase(String name) { - super(name); - } - - public void setUp() { - outDir = BcweaverTests.getOutdir(); - outDirPath = outDir.getAbsolutePath(); - } - public void tearDown() throws Exception { - super.tearDown(); - BcweaverTests.removeOutDir(); - outDir = null; - outDirPath = null; - } + { + world.addPath(classDir); + // Some of the tests in here rely on comparing output from dumping the delegates - if + // we are using ASM delegates we don't know the names of parameters (they are irrelevant...) + // and are missing from the dumping of asm delegates. This switch ensures we + // continue to use BCEL for these tests. + // world.setFastDelegateSupport(false); + } + + public WeaveTestCase(String name) { + super(name); + } + + public void setUp() { + outDir = BcweaverTests.getOutdir(); + outDirPath = outDir.getAbsolutePath(); + } + + public void tearDown() throws Exception { + super.tearDown(); + BcweaverTests.removeOutDir(); + outDir = null; + outDirPath = null; + } public static InstructionList getAdviceTag(BcelShadow shadow, String where) { - String methodName = - "ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier(); + String methodName = "ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier(); InstructionFactory fact = shadow.getFactory(); - InvokeInstruction il = - fact.createInvoke("Aspect", methodName, Type.VOID, new Type[] { - }, Constants.INVOKESTATIC); - return new InstructionList(il); + InvokeInstruction il = fact.createInvoke("Aspect", methodName, Type.VOID, new Type[] {}, Constants.INVOKESTATIC); + return new InstructionList(il); } - + public void weaveTest(String name, String outName, ShadowMunger planner) throws IOException { - List l = new ArrayList(1); - l.add(planner); - weaveTest(name, outName, l); - } - - //static String classDir = "../weaver/bin"; + List l = new ArrayList(1); + l.add(planner); + weaveTest(name, outName, l); + } + + // static String classDir = "../weaver/bin"; static String classDir = BcweaverTests.TESTDATA_PATH + File.separator + "bin"; - - + public void weaveTest(String name, String outName, List planners) throws IOException { - BcelWeaver weaver = new BcelWeaver(world); - try { - if (behave15) world.setBehaveInJava5Way(true); - - UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath); - - weaver.addClassFile(classFile); - weaver.setShadowMungers(planners); - weaveTestInner(weaver, classFile, name, outName); - } finally { - if (behave15) world.setBehaveInJava5Way(false); - } + BcelWeaver weaver = new BcelWeaver(world); + try { + if (behave15) + world.setBehaveInJava5Way(true); + + UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath); + + weaver.addClassFile(classFile); + weaver.setShadowMungers(planners); + weaveTestInner(weaver, classFile, name, outName); + } finally { + if (behave15) + world.setBehaveInJava5Way(false); + } } - - - protected void weaveTestInner( - BcelWeaver weaver, - UnwovenClassFile classFile, - String name, - String outName) - throws IOException - { - //int preErrors = currentResult.errorCount(); - BcelObjectType classType = - BcelWorld.getBcelObjectType(world.resolve(classFile.getClassName())); + + protected void weaveTestInner(BcelWeaver weaver, UnwovenClassFile classFile, String name, String outName) throws IOException { + // int preErrors = currentResult.errorCount(); + BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(classFile.getClassName())); LazyClassGen gen = weaver.weave(classFile, classType); if (gen == null) { // we didn't do any weaving, but let's make a gen anyway - gen = classType.getLazyClassGen(); //new LazyClassGen(classType); + gen = classType.getLazyClassGen(); // new LazyClassGen(classType); } try { checkClass(gen, outDirPath, outName + ".txt"); if (runTests) { - System.out.println( - "*******RUNNING: " + outName + " " + name + " *******"); - TestUtil.runMain(makeClassPath(outDirPath), name); + System.out.println("*******RUNNING: " + outName + " " + name + " *******"); + TestUtil.runMain(makeClassPath(outDirPath), name); } } catch (Error e) { System.err.println("Comparing to " + outName + ".txt"); @@ -126,148 +129,111 @@ public abstract class WeaveTestCase extends TestCase { throw e; } } - - public String makeClassPath(String outDir) { - return outDir - + File.pathSeparator - + getTraceJar() - + File.pathSeparator - + classDir - + File.pathSeparator - + System.getProperty("java.class.path"); - } - - - /** '/' in the name indicates the location of the class + + public String makeClassPath(String outDir) { + return outDir + File.pathSeparator + getTraceJar() + File.pathSeparator + classDir + File.pathSeparator + + System.getProperty("java.class.path"); + } + + /** + * '/' in the name indicates the location of the class */ - public static UnwovenClassFile makeUnwovenClassFile( - String classDir, - String name, - String outDir) throws IOException { - File outFile = new File(outDir, name+".class"); + public static UnwovenClassFile makeUnwovenClassFile(String classDir, String name, String outDir) throws IOException { + File outFile = new File(outDir, name + ".class"); if (classDir.endsWith(".jar")) { - String fname = name+".class"; - UnwovenClassFile ret = - new UnwovenClassFile(outFile.getAbsolutePath(), - FileUtil.readAsByteArray(FileUtil.getStreamFromZip(classDir, fname))); - return ret; + String fname = name + ".class"; + UnwovenClassFile ret = new UnwovenClassFile(outFile.getAbsolutePath(), FileUtil.readAsByteArray(FileUtil + .getStreamFromZip(classDir, fname))); + return ret; } else { - File inFile = new File(classDir, name+".class"); + File inFile = new File(classDir, name + ".class"); return new UnwovenClassFile(outFile.getAbsolutePath(), FileUtil.readAsByteArray(inFile)); } } - public void checkClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { - if (regenerate) genClass(gen, outDir, expectedFile); - else realCheckClass(gen, outDir, expectedFile); - } - static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH); - void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { - //ClassGen b = getJavaClass(outDir, className); - FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile)); - PrintStream ps = new PrintStream(out); - gen.print(ps); - ps.flush(); - - } - - void realCheckClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { - TestUtil.assertMultiLineStringEquals(expectedFile/*"classes"*/, - FileUtil.readAsString(new File(TESTDATA_DIR, expectedFile)), - gen.toLongString()); - } + public void checkClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { + if (regenerate) + genClass(gen, outDir, expectedFile); + else + realCheckClass(gen, outDir, expectedFile); + } + + static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH); + + void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { + // ClassGen b = getJavaClass(outDir, className); + FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile)); + PrintStream ps = new PrintStream(out); + gen.print(ps); + ps.flush(); + } + + void realCheckClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { + TestUtil.assertMultiLineStringEquals(expectedFile/* "classes" */, FileUtil + .readAsString(new File(TESTDATA_DIR, expectedFile)), gen.toLongString()); + } // ---- - public ShadowMunger makeConcreteAdvice(String mungerString) { - return makeConcreteAdvice(mungerString, 0, null); - } + public ShadowMunger makeConcreteAdvice(String mungerString) { + return makeConcreteAdvice(mungerString, 0, null); + } - public ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag) { + public ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag) { return makeConcreteAdvice(mungerString, extraArgFlag, null); - } - - protected ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag, PerClause perClause) { - Advice myMunger = - TestUtils.shadowMunger(world,mungerString, extraArgFlag); - -// PerSingleton s = new PerSingleton(); -// s.concretize(world.resolve("Aspect")); - //System.err.println(((KindedPointcut)myMunger.getPointcut().getPointcut()).getKind()); - Advice cm = (Advice) myMunger.concretize(myMunger.getDeclaringAspect().resolve(world), - world, perClause); - return cm; - } - - public ShadowMunger makeAdviceField(String kind, String extraArgType) { - return makeConcreteAdvice( - kind - + "(): get(* *.*) -> static void Aspect.ajc_" - + kind - + "_field_get(" - + extraArgType - + ")", - 1); - } - - public List makeAdviceAll(String kind, boolean matchOnlyPrintln) { - List ret = new ArrayList(); - if (matchOnlyPrintln) { - ret.add( - makeConcreteAdvice( - kind - + "(): call(* *.println(..)) -> static void Aspect.ajc_" - + kind - + "_method_execution()")); - } else { - ret.add( - makeConcreteAdvice( - kind - + "(): call(* *.*(..)) -> static void Aspect.ajc_" - + kind - + "_method_call()")); - ret.add( - makeConcreteAdvice( - kind - + "(): call(*.new(..)) -> static void Aspect.ajc_" - + kind - + "_constructor_call()")); - ret.add( - makeConcreteAdvice( - kind - + "(): execution(* *.*(..)) -> static void Aspect.ajc_" - + kind - + "_method_execution()")); - ret.add( - makeConcreteAdvice( - kind - + "(): execution(*.new(..)) -> static void Aspect.ajc_" - + kind - + "_constructor_execution()")); -// ret.add( -// makeConcreteMunger( -// kind -// + "(): staticinitialization(*) -> static void Aspect.ajc_" -// + kind -// + "_staticinitialization()")); - ret.add( - makeConcreteAdvice( - kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get()")); -// ret.add( -// makeConcreteMunger( -// kind + "(): set(* *.*) -> static void Aspect.ajc_" + kind + "_field_set()")); + } + + protected ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag, PerClause perClause) { + Advice myMunger = BcelTestUtils.shadowMunger(world, mungerString, extraArgFlag); + + // PerSingleton s = new PerSingleton(); + // s.concretize(world.resolve("Aspect")); + // System.err.println(((KindedPointcut)myMunger.getPointcut().getPointcut()).getKind()); + Advice cm = (Advice) myMunger.concretize(myMunger.getDeclaringAspect().resolve(world), world, perClause); + return cm; + } + + public ShadowMunger makeAdviceField(String kind, String extraArgType) { + return makeConcreteAdvice(kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get(" + extraArgType + ")", 1); + } + + public List makeAdviceAll(String kind, boolean matchOnlyPrintln) { + List ret = new ArrayList(); + if (matchOnlyPrintln) { + ret + .add(makeConcreteAdvice(kind + "(): call(* *.println(..)) -> static void Aspect.ajc_" + kind + + "_method_execution()")); + } else { + ret.add(makeConcreteAdvice(kind + "(): call(* *.*(..)) -> static void Aspect.ajc_" + kind + "_method_call()")); + ret.add(makeConcreteAdvice(kind + "(): call(*.new(..)) -> static void Aspect.ajc_" + kind + "_constructor_call()")); + ret + .add(makeConcreteAdvice(kind + "(): execution(* *.*(..)) -> static void Aspect.ajc_" + kind + + "_method_execution()")); + ret.add(makeConcreteAdvice(kind + "(): execution(*.new(..)) -> static void Aspect.ajc_" + kind + + "_constructor_execution()")); + // ret.add( + // makeConcreteMunger( + // kind + // + "(): staticinitialization(*) -> static void Aspect.ajc_" + // + kind + // + "_staticinitialization()")); + ret.add(makeConcreteAdvice(kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get()")); + // ret.add( + // makeConcreteMunger( + // kind + "(): set(* *.*) -> static void Aspect.ajc_" + kind + "_field_set()")); // XXX no test for advice execution, staticInitialization or (god help us) preInitialization - } - return ret; - } - - public List makeAdviceAll(final String kind) { - return makeAdviceAll(kind, false); - } + } + return ret; + } + + public List makeAdviceAll(final String kind) { + return makeAdviceAll(kind, false); + } public Pointcut makePointcutAll() { return makeConcretePointcut("get(* *.*) || call(* *.*(..)) || execution(* *.*(..)) || call(*.new(..)) || execution(*.new(..))"); } + public Pointcut makePointcutNoZeroArg() { return makeConcretePointcut("call(* *.*(*, ..)) || execution(* *.*(*, ..)) || call(*.new(*, ..)) || execution(*.new(*, ..))"); } @@ -275,22 +241,20 @@ public abstract class WeaveTestCase extends TestCase { public Pointcut makePointcutPrintln() { return makeConcretePointcut("call(* *.println(..))"); } - - + public Pointcut makeConcretePointcut(String s) { return makeResolvedPointcut(s).concretize(null, null, 0); } - + public Pointcut makeResolvedPointcut(String s) { Pointcut pointcut0 = Pointcut.fromString(s); return pointcut0.resolve(new SimpleScope(world, FormalBinding.NONE)); } - // ---- public String[] getStandardTargets() { - return new String[] {"HelloWorld", "FancyHelloWorld"}; + return new String[] { "HelloWorld", "FancyHelloWorld" }; } public String getTraceJar() { @@ -299,55 +263,44 @@ public abstract class WeaveTestCase extends TestCase { // ---- - protected void weaveTest( - String[] inClassNames, - String outKind, - ShadowMunger patternMunger) throws IOException { + protected void weaveTest(String[] inClassNames, String outKind, ShadowMunger patternMunger) throws IOException { for (int i = 0; i < inClassNames.length; i++) { String inFileName = inClassNames[i]; weaveTest(inFileName, outKind + inFileName, patternMunger); } } - protected void weaveTest( - String[] inClassNames, - String outKind, - List patternMungers) throws IOException { - for (int i = 0; i < inClassNames.length; i++) { - String inFileName = inClassNames[i]; - weaveTest(inFileName, outKind + inFileName, patternMungers); - } - } + + protected void weaveTest(String[] inClassNames, String outKind, List patternMungers) throws IOException { + for (int i = 0; i < inClassNames.length; i++) { + String inFileName = inClassNames[i]; + weaveTest(inFileName, outKind + inFileName, patternMungers); + } + } protected List addLexicalOrder(List l) { int i = 10; for (Iterator iter = l.iterator(); iter.hasNext();) { Advice element = (Advice) iter.next(); - element.setLexicalPosition(i+=10); + element.setLexicalPosition(i += 10); } return l; } - //XXX cut-and-paster from IdWeaveTestCase - public void checkShadowSet(List l, String[] ss) { - outer: - for (int i = 0, len = ss.length; i < len; i++) { - //inner: - for (Iterator j = l.iterator(); j.hasNext(); ) { - BcelShadow shadow = (BcelShadow) j.next(); - String shadowString = shadow.toString(); - if (shadowString.equals(ss[i])) { - j.remove(); - continue outer; - } - } - assertTrue("didn't find " + ss[i] + " in " + l, false); - } - assertTrue("too many things in " + l, l.size() == 0); - } - - - - + // XXX cut-and-paster from IdWeaveTestCase + public void checkShadowSet(List l, String[] ss) { + outer: for (int i = 0, len = ss.length; i < len; i++) { + // inner: + for (Iterator j = l.iterator(); j.hasNext();) { + BcelShadow shadow = (BcelShadow) j.next(); + String shadowString = shadow.toString(); + if (shadowString.equals(ss[i])) { + j.remove(); + continue outer; + } + } + assertTrue("didn't find " + ss[i] + " in " + l, false); + } + assertTrue("too many things in " + l, l.size() == 0); + } } - diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java index ccfcee954..926cc2d00 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java @@ -10,131 +10,135 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; -import org.aspectj.weaver.*; +import org.aspectj.weaver.AbstractWorldTestCase; +import org.aspectj.weaver.Advice; +import org.aspectj.weaver.BcweaverTests; +import org.aspectj.weaver.Member; +import org.aspectj.weaver.MemberImpl; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ShadowMunger; +import org.aspectj.weaver.TestUtils; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; /** * This is a test case for the nameType parts of worlds. */ public class WorldTestCase extends AbstractWorldTestCase { - public WorldTestCase(String name) { - super(name); - } - - private final BcelWorld world - = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar"); + public WorldTestCase(String name) { + super(name); + } + + private final BcelWorld world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar"); protected World getWorld() { return world; } // XXX fix the various XXXs before expecting this test to work - public void xtestTraceJar() { - ResolvedType trace = world.resolve(UnresolvedType.forName("Trace"),true); - assertTrue("Couldnt find type Trace",!trace.isMissing()); - fieldsTest(trace, Member.NONE); - /*Member constr = */TestUtils.methodFromString("void Trace.<init>()"); - //XXX need attribute fix - - //methodsTest(trace, new Member[] { constr }); - - interfacesTest(trace, ResolvedType.NONE); - superclassTest(trace, UnresolvedType.OBJECT); - isInterfaceTest(trace, false); - isClassTest(trace, false); - isAspectTest(trace, true); - - pointcutsTest(trace, - new Member[] { - MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), - }); - - modifiersTest(trace.findPointcut("traced"), - Modifier.PUBLIC | Modifier.ABSTRACT); - - mungersTest(trace, - new ShadowMunger[] { - TestUtils.shadowMunger(world,"before(foo): traced(foo) -> void Trace.ajc_before_4(java.lang.Object))", - 0), - TestUtils.shadowMunger(world,"afterReturning(foo): traced(foo) -> void Trace.ajc_afterreturning_3(java.lang.Object, java.lang.Object))", - Advice.ExtraArgument), - TestUtils.shadowMunger(world,"around(): execution(* doit(..)) -> java.lang.Object Trace.ajc_around_2(org.aspectj.runtime.internal.AroundClosure))", - Advice.ExtraArgument), - TestUtils.shadowMunger(world,"around(foo): traced(foo) -> java.lang.Object Trace.ajc_around_1(java.lang.Object, org.aspectj.runtime.internal.AroundClosure))", - Advice.ExtraArgument), - }); - - ResolvedType myTrace = world.resolve(UnresolvedType.forName("MyTrace"),true); - assertTrue("Couldnt find type MyTrace",!myTrace.isMissing()); - - interfacesTest(myTrace, ResolvedType.NONE); - superclassTest(myTrace, trace); - isInterfaceTest(myTrace, false); - isClassTest(myTrace, false); - isAspectTest(myTrace, true); - - //XXX need attribute fix - - //fieldsTest(myTrace, Member.NONE); - - - pointcutsTest(trace, - new Member[] { - MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), - }); - - modifiersTest(myTrace.findPointcut("traced"), - Modifier.PUBLIC); - - // this tests for declared mungers - mungersTest(myTrace, ShadowMunger.NONE); - - } - - public void testIterator() { - int abstractPublic = Modifier.ABSTRACT | Modifier.PUBLIC; - ResolvedType iter = world.getCoreType(UnresolvedType.forRawTypeName("java.util.Iterator")); - - modifiersTest(iter, abstractPublic | Modifier.INTERFACE); - fieldsTest(iter, ResolvedMember.NONE); - methodsTest(iter, - new Member[] { - MemberImpl.method(iter, 0, "hasNext", "()Z"), - MemberImpl.method(iter, 0, "remove", "()V"), - MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), - }); - ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V")); - assertNotNull("iterator doesn't have remove" , remove); - modifiersTest(remove, abstractPublic | Modifier.INTERFACE); - exceptionsTest(remove, UnresolvedType.NONE); - - ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;")); - assertNotNull("iterator doesn't have clone" , clone); - //AV: JRockit Object.clone() is not native.. corrupted test here: - //modifiersTest(clone, Modifier.PROTECTED | Modifier.NATIVE); - assertTrue("should be protected" + clone.toString(), clone.isProtected()); - exceptionsTest(clone, UnresolvedType.forNames(new String[] {"java.lang.CloneNotSupportedException"})); - - interfacesTest(iter, ResolvedType.NONE); - superclassTest(iter, UnresolvedType.OBJECT); - pointcutsTest(iter, ResolvedMember.NONE); - mungersTest(iter, ShadowMunger.NONE); - isInterfaceTest(iter, true); - isClassTest(iter, false); - isAspectTest(iter, false); - } + public void xtestTraceJar() { + ResolvedType trace = world.resolve(UnresolvedType.forName("Trace"), true); + assertTrue("Couldnt find type Trace", !trace.isMissing()); + fieldsTest(trace, Member.NONE); + /* Member constr = */TestUtils.methodFromString("void Trace.<init>()"); + // XXX need attribute fix - + // methodsTest(trace, new Member[] { constr }); + + interfacesTest(trace, ResolvedType.NONE); + superclassTest(trace, UnresolvedType.OBJECT); + isInterfaceTest(trace, false); + isClassTest(trace, false); + isAspectTest(trace, true); + + pointcutsTest(trace, new Member[] { MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), }); + + modifiersTest(trace.findPointcut("traced"), Modifier.PUBLIC | Modifier.ABSTRACT); + + mungersTest( + trace, + new ShadowMunger[] { + BcelTestUtils.shadowMunger(world, "before(foo): traced(foo) -> void Trace.ajc_before_4(java.lang.Object))", + 0), + BcelTestUtils + .shadowMunger( + world, + "afterReturning(foo): traced(foo) -> void Trace.ajc_afterreturning_3(java.lang.Object, java.lang.Object))", + Advice.ExtraArgument), + BcelTestUtils + .shadowMunger( + world, + "around(): execution(* doit(..)) -> java.lang.Object Trace.ajc_around_2(org.aspectj.runtime.internal.AroundClosure))", + Advice.ExtraArgument), + BcelTestUtils + .shadowMunger( + world, + "around(foo): traced(foo) -> java.lang.Object Trace.ajc_around_1(java.lang.Object, org.aspectj.runtime.internal.AroundClosure))", + Advice.ExtraArgument), }); + + ResolvedType myTrace = world.resolve(UnresolvedType.forName("MyTrace"), true); + assertTrue("Couldnt find type MyTrace", !myTrace.isMissing()); + + interfacesTest(myTrace, ResolvedType.NONE); + superclassTest(myTrace, trace); + isInterfaceTest(myTrace, false); + isClassTest(myTrace, false); + isAspectTest(myTrace, true); + + // XXX need attribute fix - + // fieldsTest(myTrace, Member.NONE); + + pointcutsTest(trace, new Member[] { MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), }); + + modifiersTest(myTrace.findPointcut("traced"), Modifier.PUBLIC); + + // this tests for declared mungers + mungersTest(myTrace, ShadowMunger.NONE); + + } + + public void testIterator() { + int abstractPublic = Modifier.ABSTRACT | Modifier.PUBLIC; + ResolvedType iter = world.getCoreType(UnresolvedType.forRawTypeName("java.util.Iterator")); + + modifiersTest(iter, abstractPublic | Modifier.INTERFACE); + fieldsTest(iter, ResolvedMember.NONE); + methodsTest(iter, new Member[] { MemberImpl.method(iter, 0, "hasNext", "()Z"), MemberImpl.method(iter, 0, "remove", "()V"), + MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), }); + ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V")); + assertNotNull("iterator doesn't have remove", remove); + modifiersTest(remove, abstractPublic | Modifier.INTERFACE); + exceptionsTest(remove, UnresolvedType.NONE); + + ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;")); + assertNotNull("iterator doesn't have clone", clone); + // AV: JRockit Object.clone() is not native.. corrupted test here: + // modifiersTest(clone, Modifier.PROTECTED | Modifier.NATIVE); + assertTrue("should be protected" + clone.toString(), clone.isProtected()); + exceptionsTest(clone, UnresolvedType.forNames(new String[] { "java.lang.CloneNotSupportedException" })); + + interfacesTest(iter, ResolvedType.NONE); + superclassTest(iter, UnresolvedType.OBJECT); + pointcutsTest(iter, ResolvedMember.NONE); + mungersTest(iter, ShadowMunger.NONE); + isInterfaceTest(iter, true); + isClassTest(iter, false); + isAspectTest(iter, false); + } public void testObjectCoersion() { assertCouldBeCoercibleFrom("java.lang.Object", "java.lang.String"); assertCouldBeCoercibleFrom("java.lang.Integer", "java.lang.Object"); - assertCouldBeCoercibleFrom("java.io.Serializable", "java.lang.Runnable"); - assertCouldBeCoercibleFrom("java.util.Stack", "java.lang.Runnable"); - assertCouldNotBeCoercibleFrom("java.lang.Runnable", "java.lang.Integer"); - assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.String"); - assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.Runnable"); + assertCouldBeCoercibleFrom("java.io.Serializable", "java.lang.Runnable"); + assertCouldBeCoercibleFrom("java.util.Stack", "java.lang.Runnable"); + assertCouldNotBeCoercibleFrom("java.lang.Runnable", "java.lang.Integer"); + assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.String"); + assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.Runnable"); } // ---- @@ -145,7 +149,6 @@ public class WorldTestCase extends AbstractWorldTestCase { private void assertCouldNotBeCoercibleFrom(String a, String b) { isCoerceableFromTest(world.resolve(a), world.resolve(b), false); - } - + } } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java index d6592da54..917fe816b 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.patterns; import java.util.ArrayList; @@ -26,42 +25,35 @@ import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; -import org.aspectj.weaver.bcel.BcelShadow; import org.aspectj.weaver.bcel.BcelWorld; /** * @author hugunin - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. + * + * To change this generated comment edit the template variable "typecomment": Window>Preferences>Java>Templates. To enable + * and disable the creation of type comments go to Window>Preferences>Java>Code Generation. */ public class ParserTestCase extends TestCase { public ParserTestCase(String arg0) { super(arg0); } - + World world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); - + public void testNamePatterns() { - - -// checkNoMatch("abc *", "abcd"); -// checkNoMatch("* d", "abcd"); - } - - - + + // checkNoMatch("abc *", "abcd"); + // checkNoMatch("* d", "abcd"); + } + public void testParse() { PatternParser parser = new PatternParser("execution(void Hello.*(..))"); KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - //System.out.println(p); - assertEquals(p.kind, BcelShadow.MethodExecution); + // System.out.println(p); + assertEquals(p.kind, Shadow.MethodExecution); assertTrue(p.getSignature().getName().matches("foobar")); - - + try { new PatternParser("initialization(void foo())").parsePointcut(); fail("should have been a parse error"); @@ -69,336 +61,336 @@ public class ParserTestCase extends TestCase { // good } } - + public void testParseExecutionWithAnnotation() { PatternParser parser = new PatternParser("execution(@SimpleAnnotation void Hello.*(..))"); KindedPointcut p = (KindedPointcut) parser.parsePointcut(); // XXX - needs finishing... - p.resolveBindings(makeSimpleScope(),new Bindings(3)); - assertEquals("execution(@p.SimpleAnnotation void Hello.*(..))",p.toString()); + p.resolveBindings(makeSimpleScope(), new Bindings(3)); + assertEquals("execution(@p.SimpleAnnotation void Hello.*(..))", p.toString()); assertEquals(p.kind, Shadow.MethodExecution); assertTrue(p.getSignature().getName().matches("foobar")); } - + // note... toString on a pointcut is a very quick and easy way to test a successful parse public void testParseExecutionWithMultipleAnnotations() { - PatternParser parser = new PatternParser("execution(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))"); - KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - assertEquals("execution(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString()); + PatternParser parser = new PatternParser("execution(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + assertEquals("execution(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))", p.toString()); } - + public void testParseCallWithMultipleAnnotations() { - PatternParser parser = new PatternParser("call(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))"); - KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - assertEquals("call(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString()); + PatternParser parser = new PatternParser("call(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + assertEquals("call(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))", p.toString()); } - + public void testParseGetWithAnnotations() { - PatternParser parser = new PatternParser("get(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)"); - KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - assertEquals("get(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString()); + PatternParser parser = new PatternParser("get(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + assertEquals("get(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)", p.toString()); } - + public void testParseBadGetWithAnnotations() { - PatternParser parser = new PatternParser("get(@Foo (@Foo @Goo Hello).*)"); - try { -// KindedPointcut p = (KindedPointcut) - parser.parsePointcut(); - fail("Expected parser exception"); - } catch (ParserException pEx) { - assertEquals("name pattern",pEx.getMessage()); - } - } - + PatternParser parser = new PatternParser("get(@Foo (@Foo @Goo Hello).*)"); + try { + // KindedPointcut p = (KindedPointcut) + parser.parsePointcut(); + fail("Expected parser exception"); + } catch (ParserException pEx) { + assertEquals("name pattern", pEx.getMessage()); + } + } + public void testParseGetWithAndAggregationAnnotations() { - PatternParser parser = new PatternParser("get(@Foo @SimpleAnnotation ReturnType (@Foo @Goo Hello).*)"); - KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - assertEquals("get(@(Foo) @(SimpleAnnotation) ReturnType (@(Foo) @(Goo) Hello).*)",p.toString()); + PatternParser parser = new PatternParser("get(@Foo @SimpleAnnotation ReturnType (@Foo @Goo Hello).*)"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + assertEquals("get(@(Foo) @(SimpleAnnotation) ReturnType (@(Foo) @(Goo) Hello).*)", p.toString()); } - - + public void testParseSetWithAnnotations() { - PatternParser parser = new PatternParser("set(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)"); - KindedPointcut p = (KindedPointcut) parser.parsePointcut(); - assertEquals("set(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString()); + PatternParser parser = new PatternParser("set(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + assertEquals("set(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)", p.toString()); } - + public void testParseHandlerWithAnnotations() { - PatternParser parser = new PatternParser("handler(@Critical Exception+)"); - Pointcut p = parser.parsePointcut(); - assertEquals("handler((@(Critical) Exception+))",p.toString()); + PatternParser parser = new PatternParser("handler(@Critical Exception+)"); + Pointcut p = parser.parsePointcut(); + assertEquals("handler((@(Critical) Exception+))", p.toString()); } public void testParseInitializationWithAnnotations() { - PatternParser parser = new PatternParser("initialization(@Foo (@Goo Hello).new(@Foo Integer))"); - Pointcut p = parser.parsePointcut(); - assertEquals("initialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString()); - + PatternParser parser = new PatternParser("initialization(@Foo (@Goo Hello).new(@Foo Integer))"); + Pointcut p = parser.parsePointcut(); + assertEquals("initialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))", p.toString()); + } - + public void testParsePreInitializationWithAnnotations() { - PatternParser parser = new PatternParser("preinitialization(@Foo (@Goo Hello).new(@Foo Integer))"); - Pointcut p = parser.parsePointcut(); - assertEquals("preinitialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString()); + PatternParser parser = new PatternParser("preinitialization(@Foo (@Goo Hello).new(@Foo Integer))"); + Pointcut p = parser.parsePointcut(); + assertEquals("preinitialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))", p.toString()); } - + public void testStaticInitializationWithAnnotations() { - PatternParser parser = new PatternParser("staticinitialization(@Foo @Boo @Goo Moo)"); - Pointcut p = parser.parsePointcut(); - assertEquals("staticinitialization((@(Foo) @(Boo) @(Goo) Moo).<clinit>())",p.toString()); + PatternParser parser = new PatternParser("staticinitialization(@Foo @Boo @Goo Moo)"); + Pointcut p = parser.parsePointcut(); + assertEquals("staticinitialization((@(Foo) @(Boo) @(Goo) Moo).<clinit>())", p.toString()); } - + public void testWithinWithAnnotations() { - PatternParser parser = new PatternParser("within(@Foo *)"); - Pointcut p = parser.parsePointcut(); - assertEquals("within((@(Foo) *))",p.toString()); + PatternParser parser = new PatternParser("within(@Foo *)"); + Pointcut p = parser.parsePointcut(); + assertEquals("within((@(Foo) *))", p.toString()); } - + public void testWithinCodeWithAnnotations() { - PatternParser parser = new PatternParser("withincode(@Foo * *.*(..))"); - Pointcut p = parser.parsePointcut(); - assertEquals("withincode(@(Foo) * *.*(..))",p.toString()); + PatternParser parser = new PatternParser("withincode(@Foo * *.*(..))"); + Pointcut p = parser.parsePointcut(); + assertEquals("withincode(@(Foo) * *.*(..))", p.toString()); } - + public void testAtAnnotation() { - PatternParser parser = new PatternParser("@annotation(Foo)"); - AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut(); - assertEquals("@annotation(Foo)",p.toString()); + PatternParser parser = new PatternParser("@annotation(Foo)"); + AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut(); + assertEquals("@annotation(Foo)", p.toString()); } - + public void testBadAtAnnotation() { - PatternParser parser = new PatternParser("@annotation(!Foo)"); - try { -// Pointcut p = - parser.parsePointcut(); - fail("Expected parser exception"); - } catch (ParserException pEx) { - assertEquals("identifier",pEx.getMessage()); - } - } - + PatternParser parser = new PatternParser("@annotation(!Foo)"); + try { + // Pointcut p = + parser.parsePointcut(); + fail("Expected parser exception"); + } catch (ParserException pEx) { + assertEquals("identifier", pEx.getMessage()); + } + } + public void testAtAnnotationWithBinding() { - PatternParser parser = new PatternParser("@annotation(foo)"); - AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut(); - assertEquals("@annotation(foo)",p.toString()); + PatternParser parser = new PatternParser("@annotation(foo)"); + AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut(); + assertEquals("@annotation(foo)", p.toString()); } - + public void testDoubleAtAnnotation() { - PatternParser parser = new PatternParser("@annotation(Foo Goo)"); - try { -// Pointcut p = - parser.parsePointcut(); - fail("Expected parser exception"); - } catch (ParserException pEx) { - assertEquals(")",pEx.getMessage()); - } - } - + PatternParser parser = new PatternParser("@annotation(Foo Goo)"); + try { + // Pointcut p = + parser.parsePointcut(); + fail("Expected parser exception"); + } catch (ParserException pEx) { + assertEquals(")", pEx.getMessage()); + } + } + public void testAtWithin() { - PatternParser parser = new PatternParser("@within(foo)"); - WithinAnnotationPointcut p = (WithinAnnotationPointcut) parser.parsePointcut(); - assertEquals("@within(foo)",p.toString()); - parser = new PatternParser("@within(Foo))"); - p = (WithinAnnotationPointcut) parser.parsePointcut(); - assertEquals("@within(Foo)",p.toString()); - } - + PatternParser parser = new PatternParser("@within(foo)"); + WithinAnnotationPointcut p = (WithinAnnotationPointcut) parser.parsePointcut(); + assertEquals("@within(foo)", p.toString()); + parser = new PatternParser("@within(Foo))"); + p = (WithinAnnotationPointcut) parser.parsePointcut(); + assertEquals("@within(Foo)", p.toString()); + } + public void testAtWithinCode() { - PatternParser parser = new PatternParser("@withincode(foo)"); - WithinCodeAnnotationPointcut p = (WithinCodeAnnotationPointcut) parser.parsePointcut(); - assertEquals("@withincode(foo)",p.toString()); - parser = new PatternParser("@withincode(Foo))"); - p = (WithinCodeAnnotationPointcut) parser.parsePointcut(); - assertEquals("@withincode(Foo)",p.toString()); - } - + PatternParser parser = new PatternParser("@withincode(foo)"); + WithinCodeAnnotationPointcut p = (WithinCodeAnnotationPointcut) parser.parsePointcut(); + assertEquals("@withincode(foo)", p.toString()); + parser = new PatternParser("@withincode(Foo))"); + p = (WithinCodeAnnotationPointcut) parser.parsePointcut(); + assertEquals("@withincode(Foo)", p.toString()); + } + public void testAtThis() { - PatternParser parser = new PatternParser("@this(foo)"); - ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); - assertEquals("@this(foo)",p.toString()); - assertTrue("isThis",p.isThis()); - parser = new PatternParser("@this(Foo))"); - p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); - assertTrue("isThis",p.isThis()); - assertEquals("@this(Foo)",p.toString()); + PatternParser parser = new PatternParser("@this(foo)"); + ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); + assertEquals("@this(foo)", p.toString()); + assertTrue("isThis", p.isThis()); + parser = new PatternParser("@this(Foo))"); + p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); + assertTrue("isThis", p.isThis()); + assertEquals("@this(Foo)", p.toString()); } public void testAtTarget() { - PatternParser parser = new PatternParser("@target(foo)"); - ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); - assertEquals("@target(foo)",p.toString()); - assertTrue("isTarget",!p.isThis()); - parser = new PatternParser("@target(Foo))"); - p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); - assertTrue("isTarget",!p.isThis()); - assertEquals("@target(Foo)",p.toString()); - } - + PatternParser parser = new PatternParser("@target(foo)"); + ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); + assertEquals("@target(foo)", p.toString()); + assertTrue("isTarget", !p.isThis()); + parser = new PatternParser("@target(Foo))"); + p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut(); + assertTrue("isTarget", !p.isThis()); + assertEquals("@target(Foo)", p.toString()); + } + public void testAtArgs() { - PatternParser parser = new PatternParser("@args(Foo,Goo,*,..,Moo)"); - Pointcut p = parser.parsePointcut(); - assertEquals("@args(Foo, Goo, ANY, .., Moo)",p.toString()); + PatternParser parser = new PatternParser("@args(Foo,Goo,*,..,Moo)"); + Pointcut p = parser.parsePointcut(); + assertEquals("@args(Foo, Goo, ANY, .., Moo)", p.toString()); } - + public void testParseSimpleTypeVariable() { PatternParser parser = new PatternParser("T"); TypeVariablePattern tv = parser.parseTypeVariable(); TypeVariablePattern expected = new TypeVariablePattern("T"); - assertEquals("Expected simple type variable T",expected,tv); + assertEquals("Expected simple type variable T", expected, tv); } - + public void testParseExtendingTypeVariable() { PatternParser parser = new PatternParser("T extends Number"); TypeVariablePattern tv = parser.parseTypeVariable(); - TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern()); - assertEquals("Expected type variable T extends Number",expected,tv); + TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern()); + assertEquals("Expected type variable T extends Number", expected, tv); } - + public void testParseExtendingTypeVariableWithPattern() { PatternParser parser = new PatternParser("T extends Number+"); TypeVariablePattern tv = parser.parseTypeVariable(); - TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number+").parseTypePattern()); - assertEquals("Expected type variable T extends Number+",expected,tv); + TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number+").parseTypePattern()); + assertEquals("Expected type variable T extends Number+", expected, tv); } - + public void testParseExtendingTypeVariableWithInterface() { PatternParser parser = new PatternParser("T extends Number & Comparable"); TypeVariablePattern tv = parser.parseTypeVariable(); - TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern(), - new TypePattern[] {new PatternParser("Comparable").parseTypePattern()},null); - assertEquals("Expected type variable T extends Number",expected,tv); + TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern(), + new TypePattern[] { new PatternParser("Comparable").parseTypePattern() }, null); + assertEquals("Expected type variable T extends Number", expected, tv); } - + public void testParseExtendingTypeVariableWithInterfaceList() { PatternParser parser = new PatternParser("T extends Number & Comparable & Cloneable"); TypeVariablePattern tv = parser.parseTypeVariable(); - TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern(), - new TypePattern[] {new PatternParser("Comparable").parseTypePattern(), - new PatternParser("Cloneable").parseTypePattern()},null); - assertEquals("Expected type variable T extends Number",expected,tv); + TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern(), + new TypePattern[] { new PatternParser("Comparable").parseTypePattern(), + new PatternParser("Cloneable").parseTypePattern() }, null); + assertEquals("Expected type variable T extends Number", expected, tv); } - + public void testParseTypeParameterList() { PatternParser parser = new PatternParser("<T>"); TypeVariablePatternList list = parser.maybeParseTypeVariableList(); TypeVariablePattern[] patterns = list.getTypeVariablePatterns(); TypeVariablePattern expected = new TypeVariablePattern("T"); - assertEquals("Expected simple type variable T",expected,patterns[0]); - assertEquals("One pattern in list",1,patterns.length); + assertEquals("Expected simple type variable T", expected, patterns[0]); + assertEquals("One pattern in list", 1, patterns.length); } - + public void testParseTypeParameterListWithSeveralTypeParameters() { PatternParser parser = new PatternParser("<T,S extends Number, R>"); TypeVariablePatternList list = parser.maybeParseTypeVariableList(); TypeVariablePattern[] patterns = list.getTypeVariablePatterns(); TypeVariablePattern expected0 = new TypeVariablePattern("T"); - assertEquals("Expected simple type variable T",expected0,patterns[0]); - TypeVariablePattern expected1 = new TypeVariablePattern("S",new PatternParser("Number").parseTypePattern()); - assertEquals("Expected type variable S extends Number",expected1,patterns[1]); + assertEquals("Expected simple type variable T", expected0, patterns[0]); + TypeVariablePattern expected1 = new TypeVariablePattern("S", new PatternParser("Number").parseTypePattern()); + assertEquals("Expected type variable S extends Number", expected1, patterns[1]); TypeVariablePattern expected2 = new TypeVariablePattern("R"); - assertEquals("Expected simple type variable R",expected2,patterns[2]); - - assertEquals("3 patterns in list",3,patterns.length); + assertEquals("Expected simple type variable R", expected2, patterns[2]); + + assertEquals("3 patterns in list", 3, patterns.length); } - - + public void testParseAllowedSuperInTypeVariable() { PatternParser parser = new PatternParser("T super Number+"); TypeVariablePattern tv = parser.parseTypeVariable(); - TypeVariablePattern expected = new TypeVariablePattern("T",new ExactTypePattern(UnresolvedType.OBJECT,false,false),null,new PatternParser("Number+").parseTypePattern()); - assertEquals("Expected type variable T super Number+",expected,tv); + TypeVariablePattern expected = new TypeVariablePattern("T", new ExactTypePattern(UnresolvedType.OBJECT, false, false), + null, new PatternParser("Number+").parseTypePattern()); + assertEquals("Expected type variable T super Number+", expected, tv); } - + public void testParseAnythingTypeVariable() { PatternParser parser = new PatternParser("?"); - WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); - assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false); + assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName()); } public void testParseAnythingExtendsTypeVariable() { PatternParser parser = new PatternParser("? extends Number"); - WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); - assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); - assertEquals("upper Bound of Number",new PatternParser("Number").parseTypePattern(),tp.getUpperBound()); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false); + assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName()); + assertEquals("upper Bound of Number", new PatternParser("Number").parseTypePattern(), tp.getUpperBound()); } - + public void testParseAnythingSuperTypeVariable() { PatternParser parser = new PatternParser("? super Number+"); - WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false); - assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName()); - assertEquals("lower Bound of Number+",new PatternParser("Number+").parseTypePattern(),tp.getLowerBound()); + WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false); + assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName()); + assertEquals("lower Bound of Number+", new PatternParser("Number+").parseTypePattern(), tp.getLowerBound()); } - + public void testParseDeclareParentsWithTypeParameterList() { try { PatternParser parser = new PatternParser("declare parents<T> : Foo<T> implements IveGoneMad"); - //DeclareParents decp = (DeclareParents) - parser.parseDeclare(); -// String[] tvp = decp.getTypeParameterNames(); -// assertEquals("one type parameter",1,tvp.length); -// assertEquals("expecting T","T",tvp[0]); + // DeclareParents decp = (DeclareParents) + parser.parseDeclare(); + // String[] tvp = decp.getTypeParameterNames(); + // assertEquals("one type parameter",1,tvp.length); + // assertEquals("expecting T","T",tvp[0]); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals(":",pEx.getMessage()); + assertEquals(":", pEx.getMessage()); } } - + public void testParameterizedTypePatternsAny() { try { PatternParser parser = new PatternParser("*<T,S extends Number>"); -// WildTypePattern wtp = (WildTypePattern) - parser.parseTypePattern(false,false); - // TypePatternList tvs = wtp.getTypeParameters(); - // assertEquals("2 type parameters",2,tvs.getTypePatterns().length); - // assertEquals("T",new PatternParser("T").parseTypePattern(),tvs.getTypePatterns()[0]); - // assertEquals("S extends Number",new PatternParser("S extends Number").parseTypePattern(false),tvs.getTypePatterns()[1]); + // WildTypePattern wtp = (WildTypePattern) + parser.parseTypePattern(false, false); + // TypePatternList tvs = wtp.getTypeParameters(); + // assertEquals("2 type parameters",2,tvs.getTypePatterns().length); + // assertEquals("T",new PatternParser("T").parseTypePattern(),tvs.getTypePatterns()[0]); + // assertEquals("S extends Number",new + // PatternParser("S extends Number").parseTypePattern(false),tvs.getTypePatterns()[1]); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals(">",pEx.getMessage()); + assertEquals(">", pEx.getMessage()); } } - + public void testParameterizedTypePatternsSimple() { PatternParser parser = new PatternParser("List<String>"); WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern(); TypePatternList tvs = wtp.getTypeParameters(); - assertEquals("1 type parameter",1,tvs.getTypePatterns().length); - assertEquals("String",new PatternParser("String").parseTypePattern(),tvs.getTypePatterns()[0]); - assertEquals("List",wtp.getNamePatterns()[0].toString()); + assertEquals("1 type parameter", 1, tvs.getTypePatterns().length); + assertEquals("String", new PatternParser("String").parseTypePattern(), tvs.getTypePatterns()[0]); + assertEquals("List", wtp.getNamePatterns()[0].toString()); } - + public void testNestedParameterizedTypePatterns() { PatternParser parser = new PatternParser("List<List<List<String>>>"); WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern(); TypePatternList typeParameters = wtp.getTypeParameters(); WildTypePattern expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; - assertEquals("expecting a List", "List",expected.maybeGetSimpleName()); + assertEquals("expecting a List", "List", expected.maybeGetSimpleName()); typeParameters = expected.getTypeParameters(); expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; - assertEquals("expecting a List", "List",expected.maybeGetSimpleName()); + assertEquals("expecting a List", "List", expected.maybeGetSimpleName()); typeParameters = expected.getTypeParameters(); expected = (WildTypePattern) typeParameters.getTypePatterns()[0]; - assertEquals("expecting a String", "String",expected.maybeGetSimpleName()); + assertEquals("expecting a String", "String", expected.maybeGetSimpleName()); } public void testSimpleTypeVariableList() { PatternParser parser = new PatternParser("<T,S,V>"); String[] tl = parser.maybeParseSimpleTypeVariableList(); - assertEquals("3 patterns",3,tl.length); - assertEquals("T",tl[0]); - assertEquals("S",tl[1]); - assertEquals("V",tl[2]); + assertEquals("3 patterns", 3, tl.length); + assertEquals("T", tl[0]); + assertEquals("S", tl[1]); + assertEquals("V", tl[2]); } - + public void testSimpleTypeVariableListError() { PatternParser parser = new PatternParser("<T extends Number>"); try { -// String[] tl = - parser.maybeParseSimpleTypeVariableList(); + // String[] tl = + parser.maybeParseSimpleTypeVariableList(); fail(); } catch (ParserException ex) { - assertEquals("Expecting ',' or '>'","',' or '>'",ex.getMessage()); - } + assertEquals("Expecting ',' or '>'", "',' or '>'", ex.getMessage()); + } } // test cases for pointcuts involving type variable specification. @@ -406,53 +398,53 @@ public class ParserTestCase extends TestCase { PatternParser parser = new PatternParser("call<T>(* Foo<T>.*(T))"); try { parser.parsePointcut(); -// String[] tvps = pc.getTypeVariablesInScope(); -// assertEquals("1 type variable",1,tvps.length); -// assertEquals("T",tvps[0]); + // String[] tvps = pc.getTypeVariablesInScope(); + // assertEquals("1 type variable",1,tvps.length); + // assertEquals("T",tvps[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } - + public void testParseCallPCDWithIllegalBounds() { PatternParser parser = new PatternParser("call<T extends Number>(* Foo<T>.*(T))"); try { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } - + public void testNoTypeVarsForHandler() { PatternParser parser = new PatternParser("handler<T>(Exception<T>)"); try { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } - + public void testNoTypeVarsForThis() { PatternParser parser = new PatternParser("this<T>(Exception<T>)"); try { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } - + public void testNoTypeVarsForTarget() { PatternParser parser = new PatternParser("target<T>(Exception<T>)"); try { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForArgs() { @@ -461,8 +453,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForIf() { @@ -471,8 +463,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForCflow() { @@ -481,8 +473,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForCflowbelow() { @@ -491,8 +483,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForAtWithin() { @@ -501,8 +493,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForAtAnnotation() { @@ -511,8 +503,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForAtWithinCode() { @@ -521,8 +513,8 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForAtThis() { @@ -531,18 +523,18 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } - + public void testNoTypeVarsForAtTarget() { PatternParser parser = new PatternParser("@target<T>(Exception<T>)"); try { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testNoTypeVarsForAtArgs() { @@ -551,49 +543,49 @@ public class ParserTestCase extends TestCase { parser.parsePointcut(); fail("Expecting parse exception"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } - + public void testExecutionWithTypeVariables() { PatternParser parser = new PatternParser("execution<T>(T Bar<T>.doSomething())"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } - + public void testInitializationWithTypeVariables() { PatternParser parser = new PatternParser("initialization<T>(Bar<T>.new())"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } public void testPreInitializationWithTypeVariables() { PatternParser parser = new PatternParser("preinitialization<T>(Bar<T>.new())"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } @@ -601,112 +593,114 @@ public class ParserTestCase extends TestCase { PatternParser parser = new PatternParser("staticinitialization<T>(Bar<T>)"); try { parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } - + public void testWithinWithTypeVariables() { PatternParser parser = new PatternParser("within<T>(Bar<T>)"); try { parser.parsePointcut(); - // String[] tvs = pc.getTypeVariablesInScope(); - // assertEquals("1 type pattern",1,tvs.length); - // assertEquals("T",tvs[0]); - fail("should have been a parse error"); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); + fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); + assertEquals("(", pEx.getMessage()); } } public void testTypeParamList() { PatternParser parser = new PatternParser("Bar<T,S extends T, R extends S>"); try { - parser.parseTypePattern(false,false); -// TypePattern[] tps = tp.getTypeParameters().getTypePatterns(); -// assertEquals("3 type patterns",3,tps.length); -// assertEquals("T",tps[0].toString()); -// assertEquals("S",tps[1].toString()); -// assertEquals("R",tps[2].toString()); + parser.parseTypePattern(false, false); + // TypePattern[] tps = tp.getTypeParameters().getTypePatterns(); + // assertEquals("3 type patterns",3,tps.length); + // assertEquals("T",tps[0].toString()); + // assertEquals("S",tps[1].toString()); + // assertEquals("R",tps[2].toString()); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals(">",pEx.getMessage()); + assertEquals(">", pEx.getMessage()); } } - + public void testWithinCodeWithTypeVariables() { PatternParser parser = new PatternParser("withincode<T,S,R>(Bar<T,S extends T, R extends S>.new())"); try { parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("3 type patterns",3,tvs.length); -// assertEquals("T",tvs[0]); -// assertEquals("S",tvs[1]); -// assertEquals("R",tvs[2]); - fail("should have been a parse error"); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("3 type patterns",3,tvs.length); + // assertEquals("T",tvs[0]); + // assertEquals("S",tvs[1]); + // assertEquals("R",tvs[2]); + fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testCallWithTypeVariables() { PatternParser parser = new PatternParser("call<T>(* Bar<T>.*(..))"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testGetWithTypeVariables() { PatternParser parser = new PatternParser("get<T>(* Bar<T>.*)"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } public void testSetWithTypeVariables() { PatternParser parser = new PatternParser("set<T>(* Bar<T>.*)"); try { -// Pointcut pc = - parser.parsePointcut(); -// String[] tvs = pc.getTypeVariablesInScope(); -// assertEquals("1 type pattern",1,tvs.length); -// assertEquals("T",tvs[0]); + // Pointcut pc = + parser.parsePointcut(); + // String[] tvs = pc.getTypeVariablesInScope(); + // assertEquals("1 type pattern",1,tvs.length); + // assertEquals("T",tvs[0]); fail("should have been a parse error"); } catch (ParserException pEx) { - assertEquals("(",pEx.getMessage()); - } + assertEquals("(", pEx.getMessage()); + } } - + public void testIntAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(ival=5) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","ival=5",getValueString(pc)); + assertEquals("Expected annotation value not found", "ival=5", getValueString(pc)); } - + private String getValueString(Pointcut pc) { - if (!(pc instanceof KindedPointcut)) fail("Expected KindedPointcut but was "+pc.getClass()); - KindedPointcut kpc = (KindedPointcut)pc; + if (!(pc instanceof KindedPointcut)) + fail("Expected KindedPointcut but was " + pc.getClass()); + KindedPointcut kpc = (KindedPointcut) pc; AnnotationTypePattern atp = kpc.getSignature().getAnnotationPattern(); - if (!(atp instanceof WildAnnotationTypePattern)) fail("Expected WildAnnotationTypePattern but was "+atp.getClass()); - WildAnnotationTypePattern watp = (WildAnnotationTypePattern)atp; + if (!(atp instanceof WildAnnotationTypePattern)) + fail("Expected WildAnnotationTypePattern but was " + atp.getClass()); + WildAnnotationTypePattern watp = (WildAnnotationTypePattern) atp; Map m = watp.annotationValues; Set keys = m.keySet(); List orderedKeys = new ArrayList(); @@ -716,7 +710,8 @@ public class ParserTestCase extends TestCase { for (Iterator iterator = orderedKeys.iterator(); iterator.hasNext();) { String object = (String) iterator.next(); sb.append(object).append("=").append(m.get(object)); - if (iterator.hasNext()) sb.append(","); + if (iterator.hasNext()) + sb.append(","); } return sb.toString(); } @@ -724,78 +719,72 @@ public class ParserTestCase extends TestCase { public void testByteAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(bval=5) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","bval=5",getValueString(pc)); + assertEquals("Expected annotation value not found", "bval=5", getValueString(pc)); } public void testCharAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(cval='5') * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","cval='5'",getValueString(pc)); + assertEquals("Expected annotation value not found", "cval='5'", getValueString(pc)); } - + public void testLongAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(jval=123123) * *(..))"); - Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","jval=123123",getValueString(pc)); + Pointcut pc = parser.parsePointcut(); + assertEquals("Expected annotation value not found", "jval=123123", getValueString(pc)); } public void testDoubleAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(dval=123.3) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","dval=123.3",getValueString(pc)); + assertEquals("Expected annotation value not found", "dval=123.3", getValueString(pc)); } public void testBooleanAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(zval=true) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","zval=true",getValueString(pc)); + assertEquals("Expected annotation value not found", "zval=true", getValueString(pc)); } public void testShortAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(sval=43) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","sval=43",getValueString(pc)); + assertEquals("Expected annotation value not found", "sval=43", getValueString(pc)); } - + public void testEnumAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(enumval=Color.GREEN) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","enumval=Color.GREEN",getValueString(pc)); + assertEquals("Expected annotation value not found", "enumval=Color.GREEN", getValueString(pc)); } public void testStringAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(strval=\"abc\") * *(..))"); Pointcut pc = parser.parsePointcut(); // notice quotes stripped... - assertEquals("Expected annotation value not found","strval=abc",getValueString(pc)); + assertEquals("Expected annotation value not found", "strval=abc", getValueString(pc)); } public void testClassAnnotationVal() { PatternParser parser = new PatternParser("execution(@ComplexAnnotation(classval=String.class) * *(..))"); Pointcut pc = parser.parsePointcut(); - assertEquals("Expected annotation value not found","classval=String.class",getValueString(pc)); + assertEquals("Expected annotation value not found", "classval=String.class", getValueString(pc)); } // failing as {1 is treated as a single token and so we don't realise the , is within the curlies -// public void testArrayAnnotationVal() { -// PatternParser parser = new PatternParser("execution(@ComplexAnnotation(arrayval={1,2,3}) * *(..))"); -// Pointcut pc = parser.parsePointcut(); -// assertEquals("Expected annotation value not found","arrayval={1,2,3}",getValueString(pc)); -// } - - - - + // public void testArrayAnnotationVal() { + // PatternParser parser = new PatternParser("execution(@ComplexAnnotation(arrayval={1,2,3}) * *(..))"); + // Pointcut pc = parser.parsePointcut(); + // assertEquals("Expected annotation value not found","arrayval={1,2,3}",getValueString(pc)); + // } + // --- - public TestScope makeSimpleScope() { world.setBehaveInJava5Way(true); - TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world); - s.setImportedPrefixes(new String[]{"p."}); + TestScope s = new TestScope(new String[] { "int", "java.lang.String" }, new String[] { "a", "b" }, world); + s.setImportedPrefixes(new String[] { "p." }); return s; } } - - |