From: aclement Date: Mon, 26 Apr 2010 23:41:17 +0000 (+0000) Subject: improved annotation handling on ResolvedMemberImpl X-Git-Tag: V1_6_9M2~32 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9a5f971f17179173889a0dc0be533a7d2180234;p=aspectj.git improved annotation handling on ResolvedMemberImpl --- diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index 1ac89a520..231851586 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -468,11 +468,11 @@ public class AtAjAttributes { * @param msgHandler * @return list of AjAttributes, always empty for now */ - public static List readAj5FieldAttributes(Field field, BcelField bField, ResolvedType type, ISourceContext context, - IMessageHandler msgHandler) { + public static List readAj5FieldAttributes(Field field, BcelField bField, ResolvedType type, + ISourceContext context, IMessageHandler msgHandler) { // Note: field annotation are for ITD and DEOW - processed at class // level directly - return Collections.EMPTY_LIST; + return Collections.emptyList(); } /** diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelField.java b/weaver/src/org/aspectj/weaver/bcel/BcelField.java index 146aeb855..be53852f9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelField.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelField.java @@ -12,8 +12,6 @@ package org.aspectj.weaver.bcel; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import org.aspectj.apache.bcel.classfile.Attribute; @@ -27,6 +25,7 @@ import org.aspectj.util.GenericSignatureParser; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AnnotationAJ; import org.aspectj.weaver.BCException; +import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; @@ -75,10 +74,11 @@ final class BcelField extends ResolvedMemberImpl { private void unpackAttributes(World world) { Attribute[] attrs = field.getAttributes(); 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())); + ISourceContext sourceContext = getSourceContext(world); + List as = Utility.readAjAttributes(getDeclaringType().getClassName(), attrs, sourceContext, world, + (bcelObjectType != null ? bcelObjectType.getWeaverVersionAttribute() : WeaverVersionInfo.CURRENT)); + as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), sourceContext, world + .getMessageHandler())); for (AjAttribute a : as) { if (a instanceof AjAttribute.AjSynthetic) { @@ -91,8 +91,9 @@ final class BcelField extends ResolvedMemberImpl { isAjSynthetic = false; for (int i = attrs.length - 1; i >= 0; i--) { - if (attrs[i] instanceof Synthetic) + if (attrs[i] instanceof Synthetic) { isSynthetic = true; + } } // in 1.5, synthetic is a modifier, not an attribute @@ -126,9 +127,7 @@ final class BcelField extends ResolvedMemberImpl { @Override public ResolvedType[] getAnnotationTypes() { ensureAnnotationTypesRetrieved(); - ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; - annotationTypes.toArray(ret); - return ret; + return annotationTypes; } @Override @@ -141,8 +140,9 @@ final class BcelField extends ResolvedMemberImpl { public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) { ensureAnnotationTypesRetrieved(); for (int i = 0; i < annotations.length; i++) { - if (annotations[i].getTypeName().equals(ofType.getName())) + if (annotations[i].getTypeName().equals(ofType.getName())) { return annotations[i]; + } } return null; } @@ -150,16 +150,17 @@ final class BcelField extends ResolvedMemberImpl { private void ensureAnnotationTypesRetrieved() { if (annotationTypes == null) { AnnotationGen annos[] = field.getAnnotations(); - if (annos == null || annos.length == 0) { - annotationTypes = Collections.emptySet(); + if (annos.length == 0) { + annotationTypes = ResolvedType.EMPTY_ARRAY; annotations = AnnotationAJ.EMPTY_ARRAY; } else { - annotationTypes = new HashSet(); - annotations = new AnnotationAJ[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 BcelAnnotation(annotation, world); + int annosCount = annos.length; + annotationTypes = new ResolvedType[annosCount]; + annotations = new AnnotationAJ[annosCount]; + for (int i = 0; i < annosCount; i++) { + AnnotationGen anno = annos[i]; + annotations[i] = new BcelAnnotation(anno, world); + annotationTypes[i] = annotations[i].getType(); } } } @@ -168,19 +169,18 @@ final class BcelField extends ResolvedMemberImpl { @Override public void addAnnotation(AnnotationAJ annotation) { ensureAnnotationTypesRetrieved(); - // Add it to the set of annotations + int len = annotations.length; AnnotationAJ[] ret = new AnnotationAJ[len + 1]; System.arraycopy(annotations, 0, ret, 0, len); ret[len] = annotation; annotations = ret; - 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)); + ResolvedType[] newAnnotationTypes = new ResolvedType[len + 1]; + System.arraycopy(annotationTypes, 0, newAnnotationTypes, 0, len); + newAnnotationTypes[len] = annotation.getType(); + annotationTypes = newAnnotationTypes; + annotationsAdded = true; } @@ -200,8 +200,9 @@ final class BcelField extends ResolvedMemberImpl { // FIXME asc badly performing code ftw ! public Field getField(ConstantPool cpg) { - if (!annotationsAdded) + if (!annotationsAdded) { return field; + } FieldGen fg = new FieldGen(field, cpg); List alreadyHas = fg.getAnnotations(); if (annotations != null) { @@ -214,8 +215,9 @@ final class BcelField extends ResolvedMemberImpl { break; } } - if (!alreadyHasIt) + if (!alreadyHasIt) { fg.addAnnotation(new AnnotationGen(((BcelAnnotation) array_element).getBcelAnnotation(), cpg, true)); + } } } field = fg.getField(); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index b13faf71a..07400d546 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -14,8 +14,6 @@ package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.StringTokenizer; @@ -63,8 +61,6 @@ class BcelMethod extends ResolvedMemberImpl { private AjAttribute.EffectiveSignatureAttribute effectiveSignature; private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber; - private AnnotationAJ[] annotations = null; - private AnnotationAJ[][] parameterAnnotations = null; private final BcelObjectType bcelObjectType; private int bitflags; @@ -342,9 +338,7 @@ class BcelMethod extends ResolvedMemberImpl { @Override public ResolvedType[] getAnnotationTypes() { ensureAnnotationsRetrieved(); - ResolvedType[] ret = new ResolvedType[annotationTypes.size()]; - annotationTypes.toArray(ret); - return ret; + return annotationTypes; } @Override @@ -367,6 +361,8 @@ class BcelMethod extends ResolvedMemberImpl { if ((bitflags & HAS_ANNOTATIONS) == 0) { annotations = new AnnotationAJ[1]; annotations[0] = annotation; + annotationTypes = new ResolvedType[1]; + annotationTypes[0] = annotation.getType(); } else { // Add it to the set of annotations int len = annotations.length; @@ -374,18 +370,12 @@ class BcelMethod extends ResolvedMemberImpl { System.arraycopy(annotations, 0, ret, 0, len); ret[len] = annotation; annotations = ret; + ResolvedType[] newAnnotationTypes = new ResolvedType[len + 1]; + System.arraycopy(annotationTypes, 0, newAnnotationTypes, 0, len); + newAnnotationTypes[len] = annotation.getType(); + annotationTypes = newAnnotationTypes; } bitflags |= HAS_ANNOTATIONS; - - // Add it to the set of annotation types - 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()); } public static final AnnotationAJ[] NO_PARAMETER_ANNOTATIONS = new AnnotationAJ[] {}; @@ -420,19 +410,20 @@ class BcelMethod extends ResolvedMemberImpl { return; } bitflags |= HAVE_DETERMINED_ANNOTATIONS; - AnnotationGen annos[] = method.getAnnotations(); - if (annos.length != 0) { - annotationTypes = new HashSet(); - annotations = new AnnotationAJ[annos.length]; - for (int i = 0; i < annos.length; i++) { + if (annos.length == 0) { + annotationTypes = ResolvedType.NONE; + annotations = AnnotationAJ.EMPTY_ARRAY; + } else { + int annoCount = annos.length; + annotationTypes = new ResolvedType[annoCount]; + annotations = new AnnotationAJ[annoCount]; + for (int i = 0; i < annoCount; i++) { AnnotationGen annotation = annos[i]; - annotationTypes.add(bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annotation.getTypeSignature()))); annotations[i] = new BcelAnnotation(annotation, bcelObjectType.getWorld()); + annotationTypes[i] = annotations[i].getType(); } bitflags |= HAS_ANNOTATIONS; - } else { - annotationTypes = Collections.emptySet(); } }