* @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();
// 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()) {
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()) {
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import org.aspectj.apache.bcel.classfile.Attribute;
}
+ @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()];
return ret;
}
+ @Override
public AnnotationAJ[] getAnnotations() {
ensureAnnotationTypesRetrieved();
return annotations;
}
+ @Override
public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
ensureAnnotationTypesRetrieved();
for (int i = 0; i < annotations.length; i++) {
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];
}
}
+ @Override
public void addAnnotation(AnnotationAJ annotation) {
ensureAnnotationTypesRetrieved();
// Add it to the set of annotations
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();
* 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;
}
}
+ @Override
public void evictWeavingState() {
if (field != null) {
unpackGenericSignature();
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
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);
}
}
}
return (bitflags & IS_AJ_SYNTHETIC) != 0;
}
- // FIXME ??? needs an isSynthetic method
-
@Override
public ShadowMunger getAssociatedShadowMunger() {
return associatedShadowMunger;
@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;
}
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
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];
}
bitflags |= HAS_ANNOTATIONS;
} else {
- annotationTypes = Collections.EMPTY_SET;
+ annotationTypes = Collections.emptySet();
}
}
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()));
// 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 {
}
}
+ 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) {