From 66b847129d16ab0d7ab1b77f81e3397cbcfb623f Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 10 Mar 2005 17:56:52 +0000 Subject: [PATCH] Declare annotation: Does weaving of @field, @method, @ctor - copes with recursive application. --- .../aspectj/weaver/bcel/BcelClassWeaver.java | 168 +++++++++++++++++- 1 file changed, 164 insertions(+), 4 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index e7b6b93c2..2eff51612 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.Field; import org.aspectj.apache.bcel.generic.BranchInstruction; import org.aspectj.apache.bcel.generic.CPInstruction; import org.aspectj.apache.bcel.generic.ConstantPoolGen; @@ -48,16 +49,17 @@ import org.aspectj.apache.bcel.generic.ReturnInstruction; import org.aspectj.apache.bcel.generic.Select; import org.aspectj.apache.bcel.generic.Type; import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; import org.aspectj.util.FuzzyBoolean; import org.aspectj.util.PartialOrder; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AjcMemberMaker; +import org.aspectj.weaver.AsmRelationshipProvider; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ConcreteTypeMunger; import org.aspectj.weaver.IClassWeaver; import org.aspectj.weaver.IntMap; import org.aspectj.weaver.Member; -import org.aspectj.weaver.WeaverMetrics; import org.aspectj.weaver.NameMangler; import org.aspectj.weaver.NewFieldTypeMunger; import org.aspectj.weaver.ResolvedMember; @@ -65,8 +67,10 @@ import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.WeaverMessages; +import org.aspectj.weaver.WeaverMetrics; import org.aspectj.weaver.WeaverStateInfo; import org.aspectj.weaver.Shadow.Kind; +import org.aspectj.weaver.patterns.DeclareAnnotation; import org.aspectj.weaver.patterns.FastMatchInfo; class BcelClassWeaver implements IClassWeaver { @@ -301,7 +305,6 @@ class BcelClassWeaver implements IClassWeaver { // ---- public boolean weave() { - if (clazz.isWoven() && !clazz.isReweavable()) { world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ALREADY_WOVEN,clazz.getType().getName()), @@ -332,6 +335,10 @@ class BcelClassWeaver implements IClassWeaver { if (inReweavableMode) aspectsAffectingType.add(munger.getAspectType().getName()); } } + + // Weave special half type/half shadow mungers... + isChanged = weaveDeclareAtMethodCtor(clazz) || isChanged; + isChanged = weaveDeclareAtField(clazz) || isChanged; // XXX do major sort of stuff // sort according to: Major: type hierarchy @@ -365,7 +372,6 @@ class BcelClassWeaver implements IClassWeaver { } if (! isChanged) return false; - // now we weave all but the initialization shadows for (Iterator i = methodGens.iterator(); i.hasNext();) { LazyMethodGen mg = (LazyMethodGen)i.next(); @@ -387,7 +393,7 @@ class BcelClassWeaver implements IClassWeaver { // finally, if we changed, we add in the introduced methods. if (isChanged) { clazz.getOrCreateWeaverStateInfo(); - weaveInAddedMethods(); + weaveInAddedMethods(); // FIXME asc are these potentially affected by declare annotation? } if (inReweavableMode) { @@ -402,6 +408,160 @@ class BcelClassWeaver implements IClassWeaver { return isChanged; } + + + + /** + * Weave any declare @method/@ctor statements into the members of the supplied class + */ + private boolean weaveDeclareAtMethodCtor(LazyClassGen clazz) { + + boolean isChanged = false; + List decaMs = getMatchingSubset(world.getDeclareAnnotationOnMethods(),clazz.getType()); + List members = clazz.getMethodGens(); + if (!members.isEmpty() && !decaMs.isEmpty()) { + // go through all the fields + for (int memberCounter = 0;memberCounter