From 2c2d5aceb5e4b8284dc6fd61fe4deefb80e0b7d6 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 18 Jun 2010 22:51:31 +0000 Subject: [PATCH] 287613/315820: declare annotation compound patterns and infrastructure for declare annotation with multiple annotations --- .../aspectj/weaver/bcel/BcelClassWeaver.java | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index ed58f1242..0bc63ff0a 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -482,12 +482,11 @@ class BcelClassWeaver implements IClassWeaver { } // now we weave all but the initialization shadows - for (Iterator i = methodGens.iterator(); i.hasNext();) { - LazyMethodGen mg = (LazyMethodGen) i.next(); - if (!mg.hasBody()) { + for (LazyMethodGen methodGen : methodGens) { + if (!methodGen.hasBody()) { continue; } - implement(mg); + implement(methodGen); } // if we matched any initialization shadows, we inline and weave @@ -885,7 +884,7 @@ class BcelClassWeaver implements IClassWeaver { * Weave any declare @method/@ctor statements into the members of the supplied class */ private boolean weaveDeclareAtMethodCtor(LazyClassGen clazz) { - List reportedProblems = new ArrayList(); + List reportedProblems = new ArrayList(); List allDecams = world.getDeclareAnnotationOnMethods(); if (allDecams.isEmpty()) { @@ -1004,7 +1003,7 @@ class BcelClassWeaver implements IClassWeaver { } } - checkUnusedDeclareAtTypes(unusedDecams, false); + checkUnusedDeclareAts(unusedDecams, false); } return isChanged; } @@ -1122,16 +1121,16 @@ class BcelClassWeaver implements IClassWeaver { * will iterate over the fields repeatedly until everything has been applied. * */ - private boolean weaveAtFieldRepeatedly(List decaFs, List itdFields, List reportedErrors) { + private boolean weaveAtFieldRepeatedly(List decaFs, List itdFields, List reportedErrors) { boolean isChanged = false; for (Iterator iter = itdFields.iterator(); iter.hasNext();) { BcelTypeMunger fieldMunger = (BcelTypeMunger) iter.next(); ResolvedMember itdIsActually = fieldMunger.getSignature(); - List worthRetrying = new ArrayList(); + List worthRetrying = new ArrayList(); boolean modificationOccured = false; - for (Iterator iter2 = decaFs.iterator(); iter2.hasNext();) { - DeclareAnnotation decaF = (DeclareAnnotation) iter2.next(); + for (Iterator iter2 = decaFs.iterator(); iter2.hasNext();) { + DeclareAnnotation decaF = iter2.next(); if (decaF.matches(itdIsActually, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger); @@ -1155,9 +1154,9 @@ class BcelClassWeaver implements IClassWeaver { while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; - List forRemoval = new ArrayList(); - for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { - DeclareAnnotation decaF = (DeclareAnnotation) iter2.next(); + List forRemoval = new ArrayList(); + for (Iterator iter2 = worthRetrying.iterator(); iter2.hasNext();) { + DeclareAnnotation decaF = iter2.next(); if (decaF.matches(itdIsActually, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger); if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors)) { @@ -1182,7 +1181,7 @@ class BcelClassWeaver implements IClassWeaver { * (List. It will iterate over the fields repeatedly until everything has been applied. */ private boolean weaveAtMethodOnITDSRepeatedly(List decaMCs, - List itdsForMethodAndConstructor, List reportedErrors) { + List itdsForMethodAndConstructor, List reportedErrors) { boolean isChanged = false; AsmManager asmManager = world.getModelAsAsmManager(); for (ConcreteTypeMunger methodctorMunger : itdsForMethodAndConstructor) { @@ -1270,7 +1269,7 @@ class BcelClassWeaver implements IClassWeaver { // decafs and check that to see if an error needs to be reported - this // would be expensive so lets skip it for now - List reportedProblems = new ArrayList(); + List reportedProblems = new ArrayList(); List allDecafs = world.getDeclareAnnotationOnFields(); if (allDecafs.isEmpty()) { @@ -1372,9 +1371,9 @@ class BcelClassWeaver implements IClassWeaver { while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; // lets have another go - List forRemoval = new ArrayList(); - for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) { - DeclareAnnotation decaF = (DeclareAnnotation) iter.next(); + List forRemoval = new ArrayList(); + for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) { + DeclareAnnotation decaF = iter.next(); if (decaF.matches(aBcelField, world)) { // below code is for recursive things if (doesAlreadyHaveAnnotation(aBcelField, decaF, reportedProblems)) { @@ -1399,7 +1398,7 @@ class BcelClassWeaver implements IClassWeaver { } } } - checkUnusedDeclareAtTypes(unusedDecafs, true); + checkUnusedDeclareAts(unusedDecafs, true); } return isChanged; } @@ -1410,35 +1409,47 @@ class BcelClassWeaver implements IClassWeaver { * This method is passed some set of declare statements that didn't match and a flag indicating whether the set contains declare @field * or declare @method/ctor entries. */ - private void checkUnusedDeclareAtTypes(Set unusedDecaTs, boolean isDeclareAtField) { - for (Iterator iter = unusedDecaTs.iterator(); iter.hasNext();) { - DeclareAnnotation declA = (DeclareAnnotation) iter.next(); + private void checkUnusedDeclareAts(Set unusedDecaTs, boolean isDeclareAtField) { + for (DeclareAnnotation declA : unusedDecaTs) { // Error if an exact type pattern was specified - boolean shouldCheck = declA.isExactPattern() - || declA.getSignaturePattern().getDeclaringType() instanceof ExactTypePattern; + boolean shouldCheck = declA.isExactPattern() || declA.getSignaturePattern().getExactDeclaringTypes().size() != 0;// != + // null;// + // instanceof + // ExactTypePattern; + if (shouldCheck && declA.getKind() != DeclareAnnotation.AT_CONSTRUCTOR) { - ExactTypePattern declaringTypePattern = (ExactTypePattern) declA.getSignaturePattern().getDeclaringType(); - if (declA.getSignaturePattern().getName().isAny() || declaringTypePattern.isIncludeSubtypes()) { + if (declA.getSignaturePattern().isMatchOnAnyName()/* getName().isAny() */) { shouldCheck = false; + } else { + List declaringTypePatterns = declA.getSignaturePattern().getExactDeclaringTypes(); + if (declaringTypePatterns.size() == 0) { + shouldCheck = false; + } else { + for (ExactTypePattern exactTypePattern : declaringTypePatterns) { + if (exactTypePattern.isIncludeSubtypes()) { + shouldCheck = false; + break; + } + } + } } } if (shouldCheck) { - // Quickly check if an ITD supplies the 'missing' member boolean itdMatch = false; - List lst = clazz.getType().getInterTypeMungers(); - for (Iterator iterator = lst.iterator(); iterator.hasNext() && !itdMatch;) { - ConcreteTypeMunger element = (ConcreteTypeMunger) iterator.next(); + List lst = clazz.getType().getInterTypeMungers(); + for (Iterator iterator = lst.iterator(); iterator.hasNext() && !itdMatch;) { + ConcreteTypeMunger element = iterator.next(); if (element.getMunger() instanceof NewFieldTypeMunger) { NewFieldTypeMunger nftm = (NewFieldTypeMunger) element.getMunger(); - itdMatch = declA.getSignaturePattern().matches(nftm.getSignature(), world, false); + itdMatch = declA.matches(nftm.getSignature(), world); } else if (element.getMunger() instanceof NewMethodTypeMunger) { NewMethodTypeMunger nmtm = (NewMethodTypeMunger) element.getMunger(); - itdMatch = declA.getSignaturePattern().matches(nmtm.getSignature(), world, false); + itdMatch = declA.matches(nmtm.getSignature(), world); } else if (element.getMunger() instanceof NewConstructorTypeMunger) { NewConstructorTypeMunger nctm = (NewConstructorTypeMunger) element.getMunger(); - itdMatch = declA.getSignaturePattern().matches(nctm.getSignature(), world, false); + itdMatch = declA.matches(nctm.getSignature(), world); } } if (!itdMatch) { @@ -1471,7 +1482,7 @@ class BcelClassWeaver implements IClassWeaver { /** * Check if a resolved member (field/method/ctor) already has an annotation, if it does then put out a warning and return true */ - private boolean doesAlreadyHaveAnnotation(ResolvedMember rm, DeclareAnnotation deca, List reportedProblems) { + private boolean doesAlreadyHaveAnnotation(ResolvedMember rm, DeclareAnnotation deca, List reportedProblems) { if (rm.hasAnnotation(deca.getAnnotationType())) { if (world.getLint().elementAlreadyAnnotated.isEnabled()) { Integer uniqueID = new Integer(rm.hashCode() * deca.hashCode()); @@ -2824,7 +2835,8 @@ class BcelClassWeaver implements IClassWeaver { return false; } - private void matchSetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) { + private void matchSetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, + List shadowAccumulator) { FieldInstruction fi = (FieldInstruction) ih.getInstruction(); Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi); @@ -2856,7 +2868,8 @@ class BcelClassWeaver implements IClassWeaver { } } - private void matchGetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) { + private void matchGetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, + List shadowAccumulator) { FieldInstruction fi = (FieldInstruction) ih.getInstruction(); Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi); -- 2.39.5