]> source.dussan.org Git - aspectj.git/commitdiff
refactoring
authoraclement <aclement>
Mon, 14 Sep 2009 17:58:52 +0000 (17:58 +0000)
committeraclement <aclement>
Mon, 14 Sep 2009 17:58:52 +0000 (17:58 +0000)
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/org/aspectj/weaver/bcel/BcelField.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index 898a5f458593bc286e59a82463bc543ef19b7bd0..1629c6f1b6aa659953ed2e3fcd592de4d5030c1f 100644 (file)
@@ -367,10 +367,10 @@ public class AtAjAttributes {
         * @param msgHandler
         * @return list of AjAttributes
         */
-       public static List readAj5MethodAttributes(Method method, BcelMethod bMethod, ResolvedType type,
+       public static List<AjAttribute> readAj5MethodAttributes(Method method, BcelMethod bMethod, ResolvedType type,
                        ResolvedPointcutDefinition preResolvedPointcut, ISourceContext context, IMessageHandler msgHandler) {
                if (method.getName().startsWith(NameMangler.PREFIX))
-                       return Collections.EMPTY_LIST; // already dealt with by ajc...
+                       return Collections.emptyList(); // already dealt with by ajc...
 
                AjAttributeMethodStruct struct = new AjAttributeMethodStruct(method, bMethod, type, context, msgHandler);
                Attribute[] attributes = method.getAttributes();
@@ -775,8 +775,7 @@ public class AtAjAttributes {
 
                                        // then iterate on field interface hierarchy (not object)
                                        boolean hasAtLeastOneMethod = false;
-                                       ResolvedMember[] methods = (ResolvedMember[]) fieldType.getMethodsWithoutIterator(true, false).toArray(
-                                                       new ResolvedMember[0]);
+                                       ResolvedMember[] methods = fieldType.getMethodsWithoutIterator(true, false).toArray(new ResolvedMember[0]);
                                        for (int i = 0; i < methods.length; i++) {
                                                ResolvedMember method = methods[i];
                                                if (method.isAbstract()) {
@@ -967,8 +966,7 @@ public class AtAjAttributes {
                        ResolvedType typeForDelegation = (ResolvedType) iterator.next();
                        // TODO check for overlapping interfaces. Eg. A implements I, I extends J - if they specify interfaces={I,J} we dont
                        // want to do any methods twice
-                       ResolvedMember[] methods = (ResolvedMember[]) typeForDelegation.getMethodsWithoutIterator(true, false).toArray(
-                                       new ResolvedMember[0]);
+                       ResolvedMember[] methods = typeForDelegation.getMethodsWithoutIterator(true, false).toArray(new ResolvedMember[0]);
                        for (int i = 0; i < methods.length; i++) {
                                ResolvedMember method = methods[i];
                                if (method.isAbstract()) {
index 73756ac31ac9fb60b3d716594070f6d7d360128e..e888154ddd378a570c9a05f2d2acf909036a9d47 100644 (file)
@@ -14,7 +14,6 @@ package org.aspectj.weaver.bcel;
 
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 
 import org.aspectj.apache.bcel.classfile.Attribute;
@@ -103,24 +102,28 @@ final class BcelField extends ResolvedMemberImpl {
 
        }
 
+       @Override
        public boolean isAjSynthetic() {
                return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
        }
 
+       @Override
        public boolean isSynthetic() {
                return isSynthetic;
        }
 
+       @Override
        public boolean hasAnnotation(UnresolvedType ofType) {
                ensureAnnotationTypesRetrieved();
-               for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) {
-                       ResolvedType aType = (ResolvedType) iter.next();
-                       if (aType.equals(ofType))
+               for (ResolvedType aType : annotationTypes) {
+                       if (aType.equals(ofType)) {
                                return true;
+                       }
                }
                return false;
        }
 
+       @Override
        public ResolvedType[] getAnnotationTypes() {
                ensureAnnotationTypesRetrieved();
                ResolvedType[] ret = new ResolvedType[annotationTypes.size()];
@@ -128,11 +131,13 @@ final class BcelField extends ResolvedMemberImpl {
                return ret;
        }
 
+       @Override
        public AnnotationAJ[] getAnnotations() {
                ensureAnnotationTypesRetrieved();
                return annotations;
        }
 
+       @Override
        public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
                ensureAnnotationTypesRetrieved();
                for (int i = 0; i < annotations.length; i++) {
@@ -146,10 +151,10 @@ final class BcelField extends ResolvedMemberImpl {
                if (annotationTypes == null) {
                        AnnotationGen annos[] = field.getAnnotations();
                        if (annos == null || annos.length == 0) {
-                               annotationTypes = Collections.EMPTY_SET;
+                               annotationTypes = Collections.emptySet();
                                annotations = AnnotationAJ.EMPTY_ARRAY;
                        } else {
-                               annotationTypes = new HashSet();
+                               annotationTypes = new HashSet<ResolvedType>();
                                annotations = new AnnotationAJ[annos.length];
                                for (int i = 0; i < annos.length; i++) {
                                        AnnotationGen annotation = annos[i];
@@ -160,6 +165,7 @@ final class BcelField extends ResolvedMemberImpl {
                }
        }
 
+       @Override
        public void addAnnotation(AnnotationAJ annotation) {
                ensureAnnotationTypesRetrieved();
                // Add it to the set of annotations
@@ -170,7 +176,7 @@ final class BcelField extends ResolvedMemberImpl {
                annotations = ret;
 
                if (annotationTypes == Collections.EMPTY_SET) {
-                       annotationTypes = new HashSet();
+                       annotationTypes = new HashSet<ResolvedType>();
                }
                // Add it to the set of annotation types
                String typename = annotation.getTypeSignature();
@@ -182,6 +188,7 @@ final class BcelField extends ResolvedMemberImpl {
         * 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>).
         */
+       @Override
        public UnresolvedType getGenericReturnType() {
                unpackGenericSignature();
                return genericFieldType;
@@ -252,6 +259,7 @@ final class BcelField extends ResolvedMemberImpl {
                }
        }
 
+       @Override
        public void evictWeavingState() {
                if (field != null) {
                        unpackGenericSignature();
index 5e66b63ea26fd4d3cced8b55dec036ece5b0e6c3..c002cedf0acbcea552ed72745e0ffa7cc5a06a0a 100644 (file)
@@ -16,7 +16,6 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -183,34 +182,29 @@ class BcelMethod extends ResolvedMemberImpl {
 
        private void unpackAjAttributes(World world) {
                associatedShadowMunger = null;
-               List as = Utility.readAjAttributes(getDeclaringType().getClassName(), method.getAttributes(), getSourceContext(world),
-                               world, bcelObjectType.getWeaverVersionAttribute());
+               List<AjAttribute> 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);
        }
 
-       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;
-                       } else if (a instanceof AjAttribute.AdviceAttribute) {
-                               associatedShadowMunger = ((AjAttribute.AdviceAttribute) a).reify(this, world);
-                               // return;
-                       } else if (a instanceof AjAttribute.AjSynthetic) {
+       private void processAttributes(World world, List<AjAttribute> as) {
+               for (AjAttribute attr : as) {
+                       if (attr instanceof AjAttribute.MethodDeclarationLineNumberAttribute) {
+                               declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute) attr;
+                       } else if (attr instanceof AjAttribute.AdviceAttribute) {
+                               associatedShadowMunger = ((AjAttribute.AdviceAttribute) attr).reify(this, world);
+                       } else if (attr instanceof AjAttribute.AjSynthetic) {
                                bitflags |= IS_AJ_SYNTHETIC;
-                               // isAjSynthetic = true;
-                       } else if (a instanceof AjAttribute.EffectiveSignatureAttribute) {
-                               // 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();
+                       } else if (attr instanceof AjAttribute.EffectiveSignatureAttribute) {
+                               effectiveSignature = (AjAttribute.EffectiveSignatureAttribute) attr;
+                       } else if (attr instanceof AjAttribute.PointcutDeclarationAttribute) {
+                               // this is an @AspectJ annotated advice method, with pointcut pre-resolved by ajc
+                               preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute) attr).reify();
                        } else {
-                               throw new BCException("weird method attribute " + a);
+                               throw new BCException("weird method attribute " + attr);
                        }
                }
        }
@@ -267,8 +261,6 @@ class BcelMethod extends ResolvedMemberImpl {
                return (bitflags & IS_AJ_SYNTHETIC) != 0;
        }
 
-       // FIXME ??? needs an isSynthetic method
-
        @Override
        public ShadowMunger getAssociatedShadowMunger() {
                return associatedShadowMunger;
@@ -325,10 +317,10 @@ class BcelMethod extends ResolvedMemberImpl {
        @Override
        public boolean hasAnnotation(UnresolvedType ofType) {
                ensureAnnotationsRetrieved();
-               for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) {
-                       ResolvedType aType = (ResolvedType) iter.next();
-                       if (aType.equals(ofType))
+               for (ResolvedType aType : annotationTypes) {
+                       if (aType.equals(ofType)) {
                                return true;
+                       }
                }
                return false;
        }
@@ -380,8 +372,9 @@ class BcelMethod extends ResolvedMemberImpl {
                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<ResolvedType>();
+               }
                annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(bcelObjectType.getWorld()));
                // FIXME asc looks like we are managing two 'bunches' of annotations,
                // one
@@ -422,7 +415,7 @@ class BcelMethod extends ResolvedMemberImpl {
 
                AnnotationGen annos[] = method.getAnnotations();
                if (annos.length != 0) {
-                       annotationTypes = new HashSet();
+                       annotationTypes = new HashSet<ResolvedType>();
                        annotations = new AnnotationAJ[annos.length];
                        for (int i = 0; i < annos.length; i++) {
                                AnnotationGen annotation = annos[i];
@@ -431,7 +424,7 @@ class BcelMethod extends ResolvedMemberImpl {
                        }
                        bitflags |= HAS_ANNOTATIONS;
                } else {
-                       annotationTypes = Collections.EMPTY_SET;
+                       annotationTypes = Collections.emptySet();
                }
        }
 
index e26fd58df9170d424a3ca24538d78c2013bc2ee5..f408d68d25d6c22a0fb6200a28f586569befb896 100644 (file)
@@ -939,8 +939,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                        annotationsOnRealMember = realMember.getAnnotations();
 
                                        if (annotationsOnRealMember != null) {
-                                               for (int i = 0; i < annotationsOnRealMember.length; i++) {
-                                                       AnnotationAJ annotationX = annotationsOnRealMember[i];
+                                               for (AnnotationAJ annotationX : annotationsOnRealMember) {
                                                        AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
                                                        AnnotationGen ag = new AnnotationGen(a, classWeaver.getLazyClassGen().getConstantPool(), true);
                                                        mg.addAnnotation(new BcelAnnotation(ag, classWeaver.getWorld()));
@@ -999,24 +998,8 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                // Work out if we need a bridge method for the new method added to the topmostimplementor.
 
                                // Check if the munger being processed is a parameterized form of the original munger
-                               if (munger.getDeclaredSignature() != null) {
-                                       boolean needsbridging = false;
-                                       ResolvedMember mungerSignature = munger.getSignature();
-                                       ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,
-                                                       mungerSignature.getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
-                                       if (!toBridgeTo.getReturnType().getErasureSignature().equals(
-                                                       mungerSignature.getReturnType().getErasureSignature()))
-                                               needsbridging = true;
-                                       UnresolvedType[] originalParams = toBridgeTo.getParameterTypes();
-                                       UnresolvedType[] newParams = mungerSignature.getParameterTypes();
-                                       for (int ii = 0; ii < originalParams.length; ii++) {
-                                               if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature()))
-                                                       needsbridging = true;
-                                       }
-                                       if (needsbridging) {
-                                               createBridge(classWeaver, unMangledInterMethod, classGen, toBridgeTo);
-                                       }
-                               }
+                               createBridgeIfNecessary(classWeaver, munger, unMangledInterMethod, classGen);
+
                                return true;
                        }
                } else {
@@ -1024,6 +1007,27 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                }
        }
 
+       private void createBridgeIfNecessary(BcelClassWeaver classWeaver, NewMethodTypeMunger munger,
+                       ResolvedMember unMangledInterMethod, LazyClassGen classGen) {
+               if (munger.getDeclaredSignature() != null) {
+                       boolean needsbridging = false;
+                       ResolvedMember mungerSignature = munger.getSignature();
+                       ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,
+                                       mungerSignature.getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
+                       if (!toBridgeTo.getReturnType().getErasureSignature().equals(mungerSignature.getReturnType().getErasureSignature()))
+                               needsbridging = true;
+                       UnresolvedType[] originalParams = toBridgeTo.getParameterTypes();
+                       UnresolvedType[] newParams = mungerSignature.getParameterTypes();
+                       for (int ii = 0; ii < originalParams.length; ii++) {
+                               if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature()))
+                                       needsbridging = true;
+                       }
+                       if (needsbridging) {
+                               createBridge(classWeaver, unMangledInterMethod, classGen, toBridgeTo);
+                       }
+               }
+       }
+
        private void copyOverParameterAnnotations(LazyMethodGen receiverMethod, ResolvedMember donorMethod) {
                AnnotationAJ[][] pAnnos = donorMethod.getParameterAnnotations();
                if (pAnnos != null) {