From b66fddbb4931784d27f2299a0d695f556ff2a836 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 8 Jun 2010 22:56:45 +0000 Subject: [PATCH] generics and ITD inner class updates --- .../aspectj/weaver/bcel/AtAjAttributes.java | 4 +- .../aspectj/weaver/bcel/BcelClassWeaver.java | 44 +++++++++---------- .../aspectj/weaver/bcel/BcelObjectType.java | 25 +++++------ .../aspectj/weaver/bcel/BcelTypeMunger.java | 23 ++++++++-- .../org/aspectj/weaver/bcel/BcelWeaver.java | 9 ++-- .../src/org/aspectj/weaver/bcel/Utility.java | 6 +-- 6 files changed, 63 insertions(+), 48 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index 231851586..dd95873d0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -185,8 +185,8 @@ public class AtAjAttributes { * @param msgHandler * @return list of AjAttributes */ - public static List readAj5ClassAttributes(AsmManager model, JavaClass javaClass, ReferenceType type, ISourceContext context, - IMessageHandler msgHandler, boolean isCodeStyleAspect) { + public static List readAj5ClassAttributes(AsmManager model, JavaClass javaClass, ReferenceType type, + ISourceContext context, IMessageHandler msgHandler, boolean isCodeStyleAspect) { boolean ignoreThisClass = javaClass.getClassName().charAt(0) == 'o' && javaClass.getClassName().startsWith("org.aspectj.lang.annotation"); if (ignoreThisClass) { diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index 74e6d1c25..ed58f1242 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -309,8 +309,8 @@ class BcelClassWeaver implements IClassWeaver { } private boolean alreadyDefined(LazyClassGen clazz, LazyMethodGen mg) { - for (Iterator i = clazz.getMethodGens().iterator(); i.hasNext();) { - LazyMethodGen existing = (LazyMethodGen) i.next(); + for (Iterator i = clazz.getMethodGens().iterator(); i.hasNext();) { + LazyMethodGen existing = i.next(); if (signaturesMatch(mg, existing)) { if (!mg.isAbstract() && existing.isAbstract()) { i.remove(); @@ -787,14 +787,14 @@ class BcelClassWeaver implements IClassWeaver { boolean didSomething = false; // set if we build any bridge methods // So what methods do we have right now in this class? - List /* LazyMethodGen */methods = clazz.getMethodGens(); + List methods = clazz.getMethodGens(); // Keep a set of all methods from this type - it'll help us to check if // bridge methods // have already been created, we don't want to do it twice! - Set methodsSet = new HashSet(); + Set methodsSet = new HashSet(); for (int i = 0; i < methods.size(); i++) { - LazyMethodGen aMethod = (LazyMethodGen) methods.get(i); + LazyMethodGen aMethod = methods.get(i); methodsSet.add(aMethod.getName() + aMethod.getSignature()); // e.g. // "foo(Ljava/lang/String;)V" } @@ -803,7 +803,7 @@ class BcelClassWeaver implements IClassWeaver { for (int i = 0; i < methods.size(); i++) { // This is the local method that we *might* have to bridge to - LazyMethodGen bridgeToCandidate = (LazyMethodGen) methods.get(i); + LazyMethodGen bridgeToCandidate = methods.get(i); if (bridgeToCandidate.isBridgeMethod()) { continue; // Doh! } @@ -1189,11 +1189,11 @@ class BcelClassWeaver implements IClassWeaver { // for (Iterator iter = itdsForMethodAndConstructor.iterator(); iter.hasNext();) { // BcelTypeMunger methodctorMunger = (BcelTypeMunger) iter.next(); ResolvedMember unMangledInterMethod = methodctorMunger.getSignature(); - List worthRetrying = new ArrayList(); + List worthRetrying = new ArrayList(); boolean modificationOccured = false; - for (Iterator iter2 = decaMCs.iterator(); iter2.hasNext();) { - DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next(); + for (Iterator iter2 = decaMCs.iterator(); iter2.hasNext();) { + DeclareAnnotation decaMC = iter2.next(); if (decaMC.matches(unMangledInterMethod, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForMethodCtorMunger(clazz, methodctorMunger); if (annotationHolder == null @@ -1216,9 +1216,9 @@ class BcelClassWeaver implements IClassWeaver { while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; - List forRemoval = new ArrayList(); - for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { - DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next(); + List forRemoval = new ArrayList(); + for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { + DeclareAnnotation decaMC = iter2.next(); if (decaMC.matches(unMangledInterMethod, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, methodctorMunger); if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors)) { @@ -1278,7 +1278,7 @@ class BcelClassWeaver implements IClassWeaver { } boolean isChanged = false; - List itdFields = getITDSubset(clazz, ResolvedTypeMunger.Field); + List itdFields = getITDSubset(clazz, ResolvedTypeMunger.Field); if (itdFields != null) { isChanged = weaveAtFieldRepeatedly(allDecafs, itdFields, reportedProblems); } @@ -1488,7 +1488,7 @@ class BcelClassWeaver implements IClassWeaver { } private boolean doesAlreadyHaveAnnotation(LazyMethodGen rm, ResolvedMember itdfieldsig, DeclareAnnotation deca, - List reportedProblems) { + List reportedProblems) { if (rm != null && rm.hasAnnotation(deca.getAnnotationType())) { if (world.getLint().elementAlreadyAnnotated.isEnabled()) { Integer uniqueID = new Integer(rm.hashCode() * deca.hashCode()); @@ -1690,7 +1690,7 @@ class BcelClassWeaver implements IClassWeaver { // search for 'returns' and make them jump to the // aload_,monitorexit InstructionHandle walker = body.getStart(); - List rets = new ArrayList(); + List rets = new ArrayList(); while (walker != null) { if (walker.getInstruction().isReturnInstruction()) { rets.add(walker); @@ -1702,8 +1702,8 @@ class BcelClassWeaver implements IClassWeaver { // the load instruction // (so we never jump over the monitorexit logic) - for (Iterator iter = rets.iterator(); iter.hasNext();) { - InstructionHandle element = (InstructionHandle) iter.next(); + for (Iterator iter = rets.iterator(); iter.hasNext();) { + InstructionHandle element = iter.next(); InstructionList monitorExitBlock = new InstructionList(); monitorExitBlock.append(InstructionFactory.createLoad(enclosingClassType, slotForLockObject)); monitorExitBlock.append(InstructionConstants.MONITOREXIT); @@ -2010,7 +2010,7 @@ class BcelClassWeaver implements IClassWeaver { // search for 'returns' and make them to the aload_,monitorexit InstructionHandle walker = body.getStart(); - List rets = new ArrayList(); + List rets = new ArrayList(); while (walker != null) { // !walker.equals(body.getEnd())) { if (walker.getInstruction().isReturnInstruction()) { rets.add(walker); @@ -2022,8 +2022,8 @@ class BcelClassWeaver implements IClassWeaver { // load instruction // (so we never jump over the monitorexit logic) - for (Iterator iter = rets.iterator(); iter.hasNext();) { - InstructionHandle element = (InstructionHandle) iter.next(); + for (Iterator iter = rets.iterator(); iter.hasNext();) { + InstructionHandle element = iter.next(); // System.err.println("Adding monitor exit block at "+element // ); InstructionList monitorExitBlock = new InstructionList(); @@ -2557,7 +2557,7 @@ class BcelClassWeaver implements IClassWeaver { } } - private boolean matchInit(LazyMethodGen mg, List shadowAccumulator) { + private boolean matchInit(LazyMethodGen mg, List shadowAccumulator) { BcelShadow enclosingShadow; // XXX the enclosing join point is wrong for things before ignoreMe. InstructionHandle superOrThisCall = findSuperOrThisCall(mg); @@ -3000,7 +3000,7 @@ class BcelClassWeaver implements IClassWeaver { } private void matchInvokeInstruction(LazyMethodGen mg, InstructionHandle ih, InvokeInstruction invoke, - BcelShadow enclosingShadow, List shadowAccumulator) { + BcelShadow enclosingShadow, List shadowAccumulator) { String methodName = invoke.getName(cpg); if (methodName.startsWith(NameMangler.PREFIX)) { Member jpSig = world.makeJoinPointSignatureForMethodInvocation(clazz, invoke); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 36dbaf212..8f1826c1b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -40,6 +40,7 @@ import org.aspectj.apache.bcel.classfile.annotation.NameValuePair; import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignature.FormalTypeParameter; import org.aspectj.weaver.AbstractReferenceTypeDelegate; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AjcMemberMaker; @@ -381,9 +382,9 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { } catch (RuntimeException re) { throw new RuntimeException("Problem processing attributes in " + javaClass.getFileName(), re); } - List pointcuts = new ArrayList(); - typeMungers = new ArrayList(); - declares = new ArrayList(); + List pointcuts = new ArrayList(); + typeMungers = new ArrayList(); + declares = new ArrayList(); processAttributes(l, pointcuts, false); l = AtAjAttributes.readAj5ClassAttributes(((BcelWorld) getResolvedTypeX().getWorld()).getModelAsAsmManager(), javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), msgHandler, isCodeStyleAspect); @@ -392,7 +393,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { if (pointcuts.size() == 0) { this.pointcuts = ResolvedPointcutDefinition.NO_POINTCUTS; } else { - this.pointcuts = (ResolvedPointcutDefinition[]) pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]); + this.pointcuts = pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]); } resolveAnnotationDeclares(l); @@ -452,14 +453,12 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { /** * Extra processing step needed because declares that come from annotations are not pre-resolved. We can't do the resolution * until *after* the pointcuts have been resolved. - * - * @param attributeList */ - private void resolveAnnotationDeclares(List attributeList) { + private void resolveAnnotationDeclares(List attributeList) { FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; IScope bindingScope = new BindingScope(getResolvedTypeX(), getResolvedTypeX().getSourceContext(), bindings); - for (Iterator iter = attributeList.iterator(); iter.hasNext();) { - AjAttribute a = (AjAttribute) iter.next(); + for (Iterator iter = attributeList.iterator(); iter.hasNext();) { + AjAttribute a = iter.next(); if (a instanceof AjAttribute.DeclareAttribute) { Declare decl = (((AjAttribute.DeclareAttribute) a).getDeclare()); if (decl instanceof DeclareErrorOrWarning) { @@ -628,9 +627,9 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { for (int i = annotations.length - 1; i >= 0; i--) { AnnotationAJ ax = annotations[i]; if (ax.getTypeName().equals(UnresolvedType.AT_RETENTION.getName())) { - List values = ((BcelAnnotation) ax).getBcelAnnotation().getValues(); - for (Iterator it = values.iterator(); it.hasNext();) { - NameValuePair element = (NameValuePair) it.next(); + List values = ((BcelAnnotation) ax).getBcelAnnotation().getValues(); + for (Iterator it = values.iterator(); it.hasNext();) { + NameValuePair element = it.next(); EnumElementValue v = (EnumElementValue) element.getValue(); retentionPolicy = v.getEnumValueString(); return retentionPolicy; @@ -762,7 +761,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { // proceeding with resolution. GenericSignature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass(); if (extraFormals.length > 0) { - List allFormals = new ArrayList(); + List allFormals = new ArrayList(); for (int i = 0; i < formalsForResolution.length; i++) { allFormals.add(formalsForResolution[i]); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 861082fd1..fdfe591da 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -49,6 +49,7 @@ import org.aspectj.weaver.MethodDelegateTypeMunger; import org.aspectj.weaver.NameMangler; import org.aspectj.weaver.NewConstructorTypeMunger; import org.aspectj.weaver.NewFieldTypeMunger; +import org.aspectj.weaver.NewMemberClassTypeMunger; import org.aspectj.weaver.NewMethodTypeMunger; import org.aspectj.weaver.NewParentTypeMunger; import org.aspectj.weaver.PerObjectInterfaceTypeMunger; @@ -99,6 +100,8 @@ public class BcelTypeMunger extends ConcreteTypeMunger { changed = mungeNewField(weaver, (NewFieldTypeMunger) munger); } else if (munger.getKind() == ResolvedTypeMunger.Method) { changed = mungeNewMethod(weaver, (NewMethodTypeMunger) munger); + } else if (munger.getKind() == ResolvedTypeMunger.InnerClass) { + changed = mungeNewMemberType(weaver, (NewMemberClassTypeMunger) munger); } else if (munger.getKind() == ResolvedTypeMunger.MethodDelegate2) { changed = mungeMethodDelegate(weaver, (MethodDelegateTypeMunger) munger); } else if (munger.getKind() == ResolvedTypeMunger.FieldHost) { @@ -175,12 +178,17 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // hidden } else { ResolvedMember declaredSig = munger.getSignature(); + String fromString = fName + ":'" + declaredSig + "'"; // if (declaredSig==null) declaredSig= munger.getSignature(); + String kindString = munger.getKind().toString().toLowerCase(); + if (kindString.equals("innerclass")) { + kindString = "member class"; + fromString = fName; + } weaver.getWorld().getMessageHandler().handleMessage( WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ITD, new String[] { - weaver.getLazyClassGen().getType().getName(), tName, munger.getKind().toString().toLowerCase(), - getAspectType().getName(), fName + ":'" + declaredSig + "'" }, weaver.getLazyClassGen() - .getClassName(), getAspectType().getName())); + weaver.getLazyClassGen().getType().getName(), tName, kindString, getAspectType().getName(), + fromString }, weaver.getLazyClassGen().getClassName(), getAspectType().getName())); } } @@ -763,6 +771,15 @@ public class BcelTypeMunger extends ConcreteTypeMunger { return !bcelObjectType.isInterface(); } + private boolean mungeNewMemberType(BcelClassWeaver classWeaver, NewMemberClassTypeMunger munger) { + World world = classWeaver.getWorld(); + ResolvedType onType = world.resolve(munger.getTargetType()); + if (onType.isRawType()) { + onType = onType.getGenericType(); + } + return onType.equals(classWeaver.getLazyClassGen().getType()); + } + private boolean mungeNewMethod(BcelClassWeaver classWeaver, NewMethodTypeMunger munger) { World world = classWeaver.getWorld(); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 2ae787e50..85e2a608b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -114,7 +114,7 @@ public class BcelWeaver { // These four are setup by prepareForWeave private transient List shadowMungerList = null; - private transient List typeMungerList = null; + private transient List typeMungerList = null; private transient List lateTypeMungerList = null; private transient List declareParentsList = null; @@ -568,11 +568,11 @@ public class BcelWeaver { String name = jc.getClassName(); ResolvedType type = world.resolve(name); if (type.isAspect()) { - Collection/* ShadowMunger */shadowMungers = customMungerFactory.createCustomShadowMungers(type); + Collection shadowMungers = customMungerFactory.createCustomShadowMungers(type); if (shadowMungers != null) { shadowMungerList.addAll(shadowMungers); } - Collection/* ConcreteTypeMunger */typeMungers = customMungerFactory.createCustomTypeMungers(type); + Collection typeMungers = customMungerFactory.createCustomTypeMungers(type); if (typeMungers != null) { typeMungerList.addAll(typeMungers); } @@ -1605,8 +1605,7 @@ public class BcelWeaver { if (onType.isRawType() || onType.isParameterizedType()) { onType = onType.getGenericType(); } - for (Iterator i = typeMungerList.iterator(); i.hasNext();) { - ConcreteTypeMunger m = (ConcreteTypeMunger) i.next(); + for (ConcreteTypeMunger m : typeMungerList) { if (!m.isLateMunger() && m.matches(onType)) { onType.addInterTypeMunger(m, false); } diff --git a/weaver/src/org/aspectj/weaver/bcel/Utility.java b/weaver/src/org/aspectj/weaver/bcel/Utility.java index 953638ea9..d7b77ea14 100644 --- a/weaver/src/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/org/aspectj/weaver/bcel/Utility.java @@ -67,7 +67,7 @@ public class Utility { public static List readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor) { - List l = new ArrayList(); + List attributes = new ArrayList(); // first pass, look for version List forSecondPass = new ArrayList(); @@ -100,10 +100,10 @@ public class Utility { String name = a.getName(); AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w, dataDecompressor); if (attr != null) { - l.add(attr); + attributes.add(attr); } } - return l; + return attributes; } /* -- 2.39.5