package org.aspectj.weaver.bcel;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import org.aspectj.apache.bcel.classfile.Attribute;
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;
private void unpackAttributes(World world) {
Attribute[] attrs = field.getAttributes();
if (attrs != null && attrs.length > 0) {
- List<AjAttribute> 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<AjAttribute> 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) {
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
@Override
public ResolvedType[] getAnnotationTypes() {
ensureAnnotationTypesRetrieved();
- ResolvedType[] ret = new ResolvedType[annotationTypes.size()];
- annotationTypes.toArray(ret);
- return ret;
+ return annotationTypes;
}
@Override
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;
}
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<ResolvedType>();
- 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();
}
}
}
@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<ResolvedType>();
- }
- // 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;
}
// FIXME asc badly performing code ftw !
public Field getField(ConstantPool cpg) {
- if (!annotationsAdded)
+ if (!annotationsAdded) {
return field;
+ }
FieldGen fg = new FieldGen(field, cpg);
List<AnnotationGen> alreadyHas = fg.getAnnotations();
if (annotations != null) {
break;
}
}
- if (!alreadyHasIt)
+ if (!alreadyHasIt) {
fg.addAnnotation(new AnnotationGen(((BcelAnnotation) array_element).getBcelAnnotation(), cpg, true));
+ }
}
}
field = fg.getField();
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;
private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
- private AnnotationAJ[] annotations = null;
- private AnnotationAJ[][] parameterAnnotations = null;
private final BcelObjectType bcelObjectType;
private int bitflags;
@Override
public ResolvedType[] getAnnotationTypes() {
ensureAnnotationsRetrieved();
- ResolvedType[] ret = new ResolvedType[annotationTypes.size()];
- annotationTypes.toArray(ret);
- return ret;
+ return annotationTypes;
}
@Override
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;
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<ResolvedType>();
- }
- 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[] {};
return;
}
bitflags |= HAVE_DETERMINED_ANNOTATIONS;
-
AnnotationGen annos[] = method.getAnnotations();
- if (annos.length != 0) {
- annotationTypes = new HashSet<ResolvedType>();
- 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();
}
}