From: aclement Date: Mon, 20 Oct 2008 18:31:30 +0000 (+0000) Subject: 246125: promoted generic sig parsing code to util X-Git-Tag: V1_6_3rc1~178 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=83fad50ca5effa81e73b6fa8f159d175fcaab599;p=aspectj.git 246125: promoted generic sig parsing code to util --- diff --git a/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java index a4fa1139f..17bdf7f6a 100644 --- a/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java @@ -15,10 +15,10 @@ package org.aspectj.weaver; import java.util.ArrayList; import java.util.List; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; -import org.aspectj.apache.bcel.classfile.Signature; -import org.aspectj.apache.bcel.classfile.Signature.ClassSignature; import org.aspectj.bridge.ISourceLocation; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; +import org.aspectj.util.GenericSignature.ClassSignature; public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDelegate { @@ -42,8 +42,7 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele } /** - * Designed to be overriden by EclipseType to disable collection of shadow - * mungers during pre-weave compilation phase + * Designed to be overriden by EclipseType to disable collection of shadow mungers during pre-weave compilation phase */ public boolean doesNotExposeShadowMungers() { return false; @@ -88,7 +87,7 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele sourceContext = isc; } - public Signature.ClassSignature getGenericClassTypeSignature() { + public GenericSignature.ClassSignature getGenericClassTypeSignature() { if (cachedGenericClassTypeSignature == null) { String sig = getDeclaredGenericSignature(); if (sig != null) { @@ -99,25 +98,25 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele return cachedGenericClassTypeSignature; } - protected Signature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() { + protected GenericSignature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() { List typeParameters = new ArrayList(); ReferenceType outer = (ReferenceType) getOuterClass(); ReferenceTypeDelegate outerDelegate = outer.getDelegate(); AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate; if (outerObjectType.isNested()) { - Signature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass(); + GenericSignature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass(); for (int i = 0; i < parentParams.length; i++) { typeParameters.add(parentParams[i]); } } - Signature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature(); + GenericSignature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature(); if (outerSig != null) { for (int i = 0; i < outerSig.formalTypeParameters.length; i++) { typeParameters.add(outerSig.formalTypeParameters[i]); } } - Signature.FormalTypeParameter[] ret = new Signature.FormalTypeParameter[typeParameters.size()]; + GenericSignature.FormalTypeParameter[] ret = new GenericSignature.FormalTypeParameter[typeParameters.size()]; typeParameters.toArray(ret); return ret; } diff --git a/weaver/src/org/aspectj/weaver/UnresolvedType.java b/weaver/src/org/aspectj/weaver/UnresolvedType.java index 64ce965ae..0c666cac8 100644 --- a/weaver/src/org/aspectj/weaver/UnresolvedType.java +++ b/weaver/src/org/aspectj/weaver/UnresolvedType.java @@ -19,9 +19,9 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.Map; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; -import org.aspectj.apache.bcel.classfile.Signature; -import org.aspectj.apache.bcel.classfile.Signature.ClassSignature; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; +import org.aspectj.util.GenericSignature.ClassSignature; import org.aspectj.weaver.tools.Traceable; /** @@ -289,16 +289,16 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { ClassSignature csig = new GenericSignatureParser().parseAsClassSignature(declaredGenericSig); - Signature.FormalTypeParameter[] ftps = csig.formalTypeParameters; + GenericSignature.FormalTypeParameter[] ftps = csig.formalTypeParameters; ret.typeVariables = new TypeVariable[ftps.length]; for (int i = 0; i < ftps.length; i++) { - Signature.FormalTypeParameter parameter = ftps[i]; - if (parameter.classBound instanceof Signature.ClassTypeSignature) { - Signature.ClassTypeSignature cts = (Signature.ClassTypeSignature) parameter.classBound; + GenericSignature.FormalTypeParameter parameter = ftps[i]; + if (parameter.classBound instanceof GenericSignature.ClassTypeSignature) { + GenericSignature.ClassTypeSignature cts = (GenericSignature.ClassTypeSignature) parameter.classBound; ret.typeVariables[i] = new TypeVariable(ftps[i].identifier, UnresolvedType.forSignature(cts.outerType.identifier + ";")); - } else if (parameter.classBound instanceof Signature.TypeVariableSignature) { - Signature.TypeVariableSignature tvs = (Signature.TypeVariableSignature) parameter.classBound; + } else if (parameter.classBound instanceof GenericSignature.TypeVariableSignature) { + GenericSignature.TypeVariableSignature tvs = (GenericSignature.TypeVariableSignature) parameter.classBound; UnresolvedTypeVariableReferenceType utvrt = new UnresolvedTypeVariableReferenceType(new TypeVariable( tvs.typeVariableName)); ret.typeVariables[i] = new TypeVariable(ftps[i].identifier, utvrt); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelField.java b/weaver/src/org/aspectj/weaver/bcel/BcelField.java index a9d9859af..02da37b90 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelField.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelField.java @@ -20,11 +20,11 @@ import java.util.List; import org.aspectj.apache.bcel.classfile.Attribute; import org.aspectj.apache.bcel.classfile.ConstantPool; import org.aspectj.apache.bcel.classfile.Field; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; -import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.classfile.Synthetic; import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; import org.aspectj.apache.bcel.generic.FieldGen; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AnnotationAJ; import org.aspectj.weaver.BCException; @@ -43,8 +43,8 @@ final class BcelField extends ResolvedMemberImpl { private boolean isAjSynthetic; private boolean isSynthetic = false; private AnnotationAJ[] annotations; - private World world; - private BcelObjectType bcelObjectType; + private final World world; + private final BcelObjectType bcelObjectType; private UnresolvedType genericFieldType = null; private boolean unpackedGenericSignature = false; private boolean annotationsAdded = false; @@ -228,13 +228,14 @@ final class BcelField extends ResolvedMemberImpl { String gSig = field.getGenericSignature(); if (gSig != null) { // get from generic - Signature.FieldTypeSignature fts = new GenericSignatureParser().parseAsFieldSignature(gSig); - Signature.ClassSignature genericTypeSig = bcelObjectType.getGenericClassTypeSignature(); + GenericSignature.FieldTypeSignature fts = new GenericSignatureParser().parseAsFieldSignature(gSig); + GenericSignature.ClassSignature genericTypeSig = bcelObjectType.getGenericClassTypeSignature(); - Signature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); - Signature.FormalTypeParameter[] typeVars = ((genericTypeSig == null) ? new Signature.FormalTypeParameter[0] + GenericSignature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); + GenericSignature.FormalTypeParameter[] typeVars = ((genericTypeSig == null) ? new GenericSignature.FormalTypeParameter[0] : genericTypeSig.formalTypeParameters); - Signature.FormalTypeParameter[] formals = new Signature.FormalTypeParameter[parentFormals.length + typeVars.length]; + GenericSignature.FormalTypeParameter[] formals = new GenericSignature.FormalTypeParameter[parentFormals.length + + typeVars.length]; // put method formal in front of type formals for overriding in // lookup System.arraycopy(typeVars, 0, formals, 0, typeVars.length); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java b/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java index e6f8829bf..608c489fe 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java @@ -14,8 +14,8 @@ package org.aspectj.weaver.bcel; import java.util.HashMap; import java.util.Map; -import org.aspectj.apache.bcel.classfile.Signature; -import org.aspectj.apache.bcel.classfile.Signature.SimpleClassTypeSignature; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignature.SimpleClassTypeSignature; import org.aspectj.weaver.BoundedReferenceType; import org.aspectj.weaver.ReferenceType; import org.aspectj.weaver.ResolvedType; @@ -28,204 +28,168 @@ import org.aspectj.weaver.tools.Trace; import org.aspectj.weaver.tools.TraceFactory; /** - * A utility class that assists in unpacking constituent parts of - * generic signature attributes and returning their equivalents in + * A utility class that assists in unpacking constituent parts of generic signature attributes and returning their equivalents in * UnresolvedType world. */ public class BcelGenericSignatureToTypeXConverter { private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelGenericSignatureToTypeXConverter.class); - - public static ResolvedType classTypeSignature2TypeX( - Signature.ClassTypeSignature aClassTypeSignature, - Signature.FormalTypeParameter[] typeParams, - World world) - throws GenericSignatureFormatException - { + + public static ResolvedType classTypeSignature2TypeX(GenericSignature.ClassTypeSignature aClassTypeSignature, + GenericSignature.FormalTypeParameter[] typeParams, World world) throws GenericSignatureFormatException { Map typeMap = new HashMap(); - ResolvedType ret = classTypeSignature2TypeX(aClassTypeSignature,typeParams,world,typeMap); + ResolvedType ret = classTypeSignature2TypeX(aClassTypeSignature, typeParams, world, typeMap); fixUpCircularDependencies(ret, typeMap); return ret; } - - - private static ResolvedType classTypeSignature2TypeX( - Signature.ClassTypeSignature aClassTypeSignature, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { + + private static ResolvedType classTypeSignature2TypeX(GenericSignature.ClassTypeSignature aClassTypeSignature, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { // class type sig consists of an outer type, and zero or more nested types // the fully qualified name is outer-type.nested-type1.nested-type2.... // each type in the hierarchy may have type arguments - + // first build the 'raw type' signature StringBuffer sig = new StringBuffer(); - sig.append(aClassTypeSignature.outerType.identifier.replace(';',' ').trim()); + sig.append(aClassTypeSignature.outerType.identifier.replace(';', ' ').trim()); for (int i = 0; i < aClassTypeSignature.nestedTypes.length; i++) { - sig.append("$"); - sig.append(aClassTypeSignature.nestedTypes[i].identifier.replace(';',' ').trim()); + sig.append("$"); + sig.append(aClassTypeSignature.nestedTypes[i].identifier.replace(';', ' ').trim()); } sig.append(";"); - + // now look for any type parameters. // I *think* we only need to worry about the 'right-most' type... SimpleClassTypeSignature innerType = aClassTypeSignature.outerType; if (aClassTypeSignature.nestedTypes.length > 0) { - innerType = aClassTypeSignature.nestedTypes[aClassTypeSignature.nestedTypes.length-1]; + innerType = aClassTypeSignature.nestedTypes[aClassTypeSignature.nestedTypes.length - 1]; } if (innerType.typeArguments.length > 0) { // we have to create a parameterized type // type arguments may be array types, class types, or typevariable types ResolvedType theBaseType = UnresolvedType.forSignature(sig.toString()).resolve(world); - + // Sometimes we may find that when the code is being load-time woven that the types have changed. // Perhaps an old form of a library jar is being used - this can mean we discover right here - // that a type is not parameterizable (is that a word?). I think in these cases it is ok to + // that a type is not parameterizable (is that a word?). I think in these cases it is ok to // just return with what we know (the base type). (see pr152848) if (!(theBaseType.isGenericType() || theBaseType.isRawType())) { - if (trace.isTraceEnabled()) trace.event("classTypeSignature2TypeX: this type is not a generic type:",null,new Object[]{theBaseType}); + if (trace.isTraceEnabled()) + trace.event("classTypeSignature2TypeX: this type is not a generic type:", null, new Object[] { theBaseType }); return theBaseType; } - + ResolvedType[] typeArgumentTypes = new ResolvedType[innerType.typeArguments.length]; for (int i = 0; i < typeArgumentTypes.length; i++) { - typeArgumentTypes[i] = typeArgument2TypeX(innerType.typeArguments[i],typeParams,world,inProgressTypeVariableResolutions); + typeArgumentTypes[i] = typeArgument2TypeX(innerType.typeArguments[i], typeParams, world, + inProgressTypeVariableResolutions); } - return - TypeFactory.createParameterizedType( - theBaseType, - typeArgumentTypes, - world); - -// world.resolve(UnresolvedType.forParameterizedTypes( -// UnresolvedType.forSignature(sig.toString()).resolve(world), -// typeArgumentTypes)); + return TypeFactory.createParameterizedType(theBaseType, typeArgumentTypes, world); + + // world.resolve(UnresolvedType.forParameterizedTypes( + // UnresolvedType.forSignature(sig.toString()).resolve(world), + // typeArgumentTypes)); } else { // we have a non-parameterized type return world.resolve(UnresolvedType.forSignature(sig.toString())); } } - - public static ResolvedType fieldTypeSignature2TypeX( - Signature.FieldTypeSignature aFieldTypeSignature, - Signature.FormalTypeParameter[] typeParams, - World world) - throws GenericSignatureFormatException - { + + public static ResolvedType fieldTypeSignature2TypeX(GenericSignature.FieldTypeSignature aFieldTypeSignature, + GenericSignature.FormalTypeParameter[] typeParams, World world) throws GenericSignatureFormatException { Map typeMap = new HashMap(); - ResolvedType ret = fieldTypeSignature2TypeX(aFieldTypeSignature,typeParams,world,typeMap); + ResolvedType ret = fieldTypeSignature2TypeX(aFieldTypeSignature, typeParams, world, typeMap); fixUpCircularDependencies(ret, typeMap); return ret; } - - private static ResolvedType fieldTypeSignature2TypeX( - Signature.FieldTypeSignature aFieldTypeSignature, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { + + private static ResolvedType fieldTypeSignature2TypeX(GenericSignature.FieldTypeSignature aFieldTypeSignature, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { if (aFieldTypeSignature.isClassTypeSignature()) { - return classTypeSignature2TypeX((Signature.ClassTypeSignature)aFieldTypeSignature,typeParams,world,inProgressTypeVariableResolutions); + return classTypeSignature2TypeX((GenericSignature.ClassTypeSignature) aFieldTypeSignature, typeParams, world, + inProgressTypeVariableResolutions); } else if (aFieldTypeSignature.isArrayTypeSignature()) { int dims = 0; - Signature.TypeSignature ats = aFieldTypeSignature; - while(ats instanceof Signature.ArrayTypeSignature) { + GenericSignature.TypeSignature ats = aFieldTypeSignature; + while (ats instanceof GenericSignature.ArrayTypeSignature) { dims++; - ats = ((Signature.ArrayTypeSignature)ats).typeSig; + ats = ((GenericSignature.ArrayTypeSignature) ats).typeSig; } - return world.resolve(UnresolvedType.makeArray(typeSignature2TypeX(ats,typeParams,world,inProgressTypeVariableResolutions), dims)); + return world.resolve(UnresolvedType.makeArray(typeSignature2TypeX(ats, typeParams, world, + inProgressTypeVariableResolutions), dims)); } else if (aFieldTypeSignature.isTypeVariableSignature()) { - ResolvedType rtx = typeVariableSignature2TypeX((Signature.TypeVariableSignature)aFieldTypeSignature,typeParams,world,inProgressTypeVariableResolutions); + ResolvedType rtx = typeVariableSignature2TypeX((GenericSignature.TypeVariableSignature) aFieldTypeSignature, + typeParams, world, inProgressTypeVariableResolutions); return rtx; } else { - throw new GenericSignatureFormatException("Cant understand field type signature: " + aFieldTypeSignature); + throw new GenericSignatureFormatException("Cant understand field type signature: " + aFieldTypeSignature); } } - public static TypeVariable formalTypeParameter2TypeVariable( - Signature.FormalTypeParameter aFormalTypeParameter, - Signature.FormalTypeParameter[] typeParams, - World world) - throws GenericSignatureFormatException - { + public static TypeVariable formalTypeParameter2TypeVariable(GenericSignature.FormalTypeParameter aFormalTypeParameter, + GenericSignature.FormalTypeParameter[] typeParams, World world) throws GenericSignatureFormatException { Map typeMap = new HashMap(); - return formalTypeParameter2TypeVariable(aFormalTypeParameter,typeParams,world,typeMap); + return formalTypeParameter2TypeVariable(aFormalTypeParameter, typeParams, world, typeMap); } - private static TypeVariable formalTypeParameter2TypeVariable( - Signature.FormalTypeParameter aFormalTypeParameter, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { - UnresolvedType upperBound = fieldTypeSignature2TypeX(aFormalTypeParameter.classBound,typeParams,world,inProgressTypeVariableResolutions); - UnresolvedType[] ifBounds = new UnresolvedType[aFormalTypeParameter.interfaceBounds.length]; - for (int i = 0; i < ifBounds.length; i++) { - ifBounds[i] = fieldTypeSignature2TypeX(aFormalTypeParameter.interfaceBounds[i], typeParams,world,inProgressTypeVariableResolutions); - } - return new TypeVariable(aFormalTypeParameter.identifier,upperBound,ifBounds); + private static TypeVariable formalTypeParameter2TypeVariable(GenericSignature.FormalTypeParameter aFormalTypeParameter, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { + UnresolvedType upperBound = fieldTypeSignature2TypeX(aFormalTypeParameter.classBound, typeParams, world, + inProgressTypeVariableResolutions); + UnresolvedType[] ifBounds = new UnresolvedType[aFormalTypeParameter.interfaceBounds.length]; + for (int i = 0; i < ifBounds.length; i++) { + ifBounds[i] = fieldTypeSignature2TypeX(aFormalTypeParameter.interfaceBounds[i], typeParams, world, + inProgressTypeVariableResolutions); + } + return new TypeVariable(aFormalTypeParameter.identifier, upperBound, ifBounds); } - - private static ResolvedType typeArgument2TypeX( - Signature.TypeArgument aTypeArgument, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { - if (aTypeArgument.isWildcard) return UnresolvedType.SOMETHING.resolve(world); + + private static ResolvedType typeArgument2TypeX(GenericSignature.TypeArgument aTypeArgument, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { + if (aTypeArgument.isWildcard) + return UnresolvedType.SOMETHING.resolve(world); if (aTypeArgument.isMinus) { - UnresolvedType bound = fieldTypeSignature2TypeX(aTypeArgument.signature, typeParams,world,inProgressTypeVariableResolutions); + UnresolvedType bound = fieldTypeSignature2TypeX(aTypeArgument.signature, typeParams, world, + inProgressTypeVariableResolutions); ReferenceType rBound = (ReferenceType) world.resolve(bound); - return new BoundedReferenceType(rBound,false,world); + return new BoundedReferenceType(rBound, false, world); } else if (aTypeArgument.isPlus) { - UnresolvedType bound = fieldTypeSignature2TypeX(aTypeArgument.signature, typeParams,world,inProgressTypeVariableResolutions); + UnresolvedType bound = fieldTypeSignature2TypeX(aTypeArgument.signature, typeParams, world, + inProgressTypeVariableResolutions); ReferenceType rBound = (ReferenceType) world.resolve(bound); - return new BoundedReferenceType(rBound,true,world); + return new BoundedReferenceType(rBound, true, world); } else { - return fieldTypeSignature2TypeX(aTypeArgument.signature,typeParams,world,inProgressTypeVariableResolutions); + return fieldTypeSignature2TypeX(aTypeArgument.signature, typeParams, world, inProgressTypeVariableResolutions); } } - - public static ResolvedType typeSignature2TypeX( - Signature.TypeSignature aTypeSig, - Signature.FormalTypeParameter[] typeParams, - World world) - throws GenericSignatureFormatException - { + public static ResolvedType typeSignature2TypeX(GenericSignature.TypeSignature aTypeSig, + GenericSignature.FormalTypeParameter[] typeParams, World world) throws GenericSignatureFormatException { Map typeMap = new HashMap(); - ResolvedType ret = typeSignature2TypeX(aTypeSig,typeParams,world,typeMap); + ResolvedType ret = typeSignature2TypeX(aTypeSig, typeParams, world, typeMap); fixUpCircularDependencies(ret, typeMap); return ret; } - - private static ResolvedType typeSignature2TypeX( - Signature.TypeSignature aTypeSig, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { + + private static ResolvedType typeSignature2TypeX(GenericSignature.TypeSignature aTypeSig, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { if (aTypeSig.isBaseType()) { - return world.resolve(UnresolvedType.forSignature(((Signature.BaseTypeSignature)aTypeSig).toString())); + return world.resolve(UnresolvedType.forSignature(((GenericSignature.BaseTypeSignature) aTypeSig).toString())); } else { - return fieldTypeSignature2TypeX((Signature.FieldTypeSignature)aTypeSig,typeParams,world,inProgressTypeVariableResolutions); + return fieldTypeSignature2TypeX((GenericSignature.FieldTypeSignature) aTypeSig, typeParams, world, + inProgressTypeVariableResolutions); } } - - private static ResolvedType typeVariableSignature2TypeX( - Signature.TypeVariableSignature aTypeVarSig, - Signature.FormalTypeParameter[] typeParams, - World world, - Map inProgressTypeVariableResolutions) - throws GenericSignatureFormatException - { - Signature.FormalTypeParameter typeVarBounds = null; + + private static ResolvedType typeVariableSignature2TypeX(GenericSignature.TypeVariableSignature aTypeVarSig, + GenericSignature.FormalTypeParameter[] typeParams, World world, Map inProgressTypeVariableResolutions) + throws GenericSignatureFormatException { + GenericSignature.FormalTypeParameter typeVarBounds = null; for (int i = 0; i < typeParams.length; i++) { if (typeParams[i].identifier.equals(aTypeVarSig.typeVariableName)) { typeVarBounds = typeParams[i]; @@ -233,52 +197,55 @@ public class BcelGenericSignatureToTypeXConverter { } } if (typeVarBounds == null) { - // blowing up here breaks the situation with ITDs where the type variable is mentioned in the - // declaring type and used somewhere in the signature. Temporary change to allow it to return just a + // blowing up here breaks the situation with ITDs where the type variable is mentioned in the + // declaring type and used somewhere in the signature. Temporary change to allow it to return just a // 'dumb' typevariablereference. - return new TypeVariableReferenceType(new TypeVariable(aTypeVarSig.typeVariableName),world); + return new TypeVariableReferenceType(new TypeVariable(aTypeVarSig.typeVariableName), world); // throw new GenericSignatureFormatException("Undeclared type variable in signature: " + aTypeVarSig.typeVariableName); } if (inProgressTypeVariableResolutions.containsKey(typeVarBounds)) { return (ResolvedType) inProgressTypeVariableResolutions.get(typeVarBounds); } - inProgressTypeVariableResolutions.put(typeVarBounds,new FTPHolder(typeVarBounds,world)); - ResolvedType ret = new TypeVariableReferenceType( - formalTypeParameter2TypeVariable(typeVarBounds,typeParams,world,inProgressTypeVariableResolutions), - world); - inProgressTypeVariableResolutions.put(typeVarBounds,ret); + inProgressTypeVariableResolutions.put(typeVarBounds, new FTPHolder(typeVarBounds, world)); + ResolvedType ret = new TypeVariableReferenceType(formalTypeParameter2TypeVariable(typeVarBounds, typeParams, world, + inProgressTypeVariableResolutions), world); + inProgressTypeVariableResolutions.put(typeVarBounds, ret); return ret; } - + private static void fixUpCircularDependencies(ResolvedType aTypeX, Map typeVariableResolutions) { - if (! (aTypeX instanceof ReferenceType)) return; - + if (!(aTypeX instanceof ReferenceType)) + return; + ReferenceType rt = (ReferenceType) aTypeX; TypeVariable[] typeVars = rt.getTypeVariables(); if (typeVars != null) { - for (int i = 0; i < typeVars.length; i++) { - if (typeVars[i].getUpperBound() instanceof FTPHolder) { - Signature.FormalTypeParameter key = ((FTPHolder) typeVars[i].getUpperBound()).ftpToBeSubstituted; - typeVars[i].setUpperBound((UnresolvedType) typeVariableResolutions.get(key)); - } - } + for (int i = 0; i < typeVars.length; i++) { + if (typeVars[i].getUpperBound() instanceof FTPHolder) { + GenericSignature.FormalTypeParameter key = ((FTPHolder) typeVars[i].getUpperBound()).ftpToBeSubstituted; + typeVars[i].setUpperBound((UnresolvedType) typeVariableResolutions.get(key)); + } + } } } - + private static class FTPHolder extends ReferenceType { - public Signature.FormalTypeParameter ftpToBeSubstituted; - public FTPHolder(Signature.FormalTypeParameter ftp, World world) { - super("Ljava/lang/Object;",world); + public GenericSignature.FormalTypeParameter ftpToBeSubstituted; + + public FTPHolder(GenericSignature.FormalTypeParameter ftp, World world) { + super("Ljava/lang/Object;", world); this.ftpToBeSubstituted = ftp; } + public String toString() { return "placeholder for TypeVariable of " + ftpToBeSubstituted.toString(); } + public ResolvedType resolve(World world) { return this; } } - + public static class GenericSignatureFormatException extends Exception { public GenericSignatureFormatException(String explanation) { super(explanation); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index 149bad649..adb91f8d9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -23,19 +23,19 @@ import java.util.StringTokenizer; import org.aspectj.apache.bcel.classfile.AnnotationDefault; import org.aspectj.apache.bcel.classfile.Attribute; import org.aspectj.apache.bcel.classfile.ExceptionTable; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.LineNumber; import org.aspectj.apache.bcel.classfile.LineNumberTable; import org.aspectj.apache.bcel.classfile.LocalVariable; import org.aspectj.apache.bcel.classfile.LocalVariableTable; import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.classfile.Signature; -import org.aspectj.apache.bcel.classfile.Signature.TypeVariableSignature; import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.SourceLocation; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; +import org.aspectj.util.GenericSignature.TypeVariableSignature; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AnnotationAJ; import org.aspectj.weaver.BCException; @@ -432,9 +432,8 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * A method can be parameterized if it has one or more generic parameters. A - * generic parameter (type variable parameter) is identified by the prefix - * "T" + * A method can be parameterized if it has one or more generic parameters. A generic parameter (type variable parameter) is + * identified by the prefix "T" */ public boolean canBeParameterized() { unpackGenericSignature(); @@ -447,8 +446,7 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * Return the parameterized/generic return type or the normal return type if - * the method is not generic. + * Return the parameterized/generic return type or the normal return type if the method is not generic. */ public UnresolvedType getGenericReturnType() { unpackGenericSignature(); @@ -472,8 +470,8 @@ class BcelMethod extends ResolvedMemberImpl { } String gSig = method.getGenericSignature(); if (gSig != null) { - Signature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);// method - // . + GenericSignature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);// method + // . // getGenericSignature // ()); if (mSig.formalTypeParameters.length > 0) { @@ -483,7 +481,7 @@ class BcelMethod extends ResolvedMemberImpl { typeVariables = new TypeVariable[mSig.formalTypeParameters.length]; for (int i = 0; i < typeVariables.length; i++) { - Signature.FormalTypeParameter methodFtp = mSig.formalTypeParameters[i]; + GenericSignature.FormalTypeParameter methodFtp = mSig.formalTypeParameters[i]; try { typeVariables[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(methodFtp, mSig.formalTypeParameters, bcelObjectType.getWorld()); @@ -494,14 +492,14 @@ class BcelMethod extends ResolvedMemberImpl { } } - Signature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); - Signature.FormalTypeParameter[] formals = new Signature.FormalTypeParameter[parentFormals.length + GenericSignature.FormalTypeParameter[] parentFormals = bcelObjectType.getAllFormals(); + GenericSignature.FormalTypeParameter[] formals = new GenericSignature.FormalTypeParameter[parentFormals.length + mSig.formalTypeParameters.length]; // put method formal in front of type formals for overriding in // lookup System.arraycopy(mSig.formalTypeParameters, 0, formals, 0, mSig.formalTypeParameters.length); System.arraycopy(parentFormals, 0, formals, mSig.formalTypeParameters.length, parentFormals.length); - Signature.TypeSignature returnTypeSignature = mSig.returnType; + GenericSignature.TypeSignature returnTypeSignature = mSig.returnType; try { genericReturnType = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(returnTypeSignature, formals, bcelObjectType.getWorld()); @@ -510,7 +508,7 @@ class BcelMethod extends ResolvedMemberImpl { throw new IllegalStateException("While determing the generic return type of " + this.toString() + " with generic signature " + gSig + " the following error was detected: " + e.getMessage()); } - Signature.TypeSignature[] paramTypeSigs = mSig.parameters; + GenericSignature.TypeSignature[] paramTypeSigs = mSig.parameters; genericParameterTypes = new UnresolvedType[paramTypeSigs.length]; for (int i = 0; i < paramTypeSigs.length; i++) { try { @@ -580,9 +578,8 @@ class BcelMethod extends ResolvedMemberImpl { } /** - * Returns whether or not the given object is equivalent to the current one. - * Returns true if getMethod().getCode().getCodeString() are equal. Allows - * for different line number tables. + * Returns whether or not the given object is equivalent to the current one. Returns true if + * getMethod().getCode().getCodeString() are equal. Allows for different line number tables. */ // bug 154054: is similar to equals(Object) however // doesn't require implementing equals in Method and Code diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 8f531a97a..2940c7bf0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -34,6 +34,7 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen; import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen; import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.MessageUtil; +import org.aspectj.util.GenericSignature; import org.aspectj.weaver.AbstractReferenceTypeDelegate; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AjcMemberMaker; @@ -87,7 +88,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { private List typeMungers = Collections.EMPTY_LIST; private List declares = Collections.EMPTY_LIST; - private Signature.FormalTypeParameter[] formalsForResolution = null; + private GenericSignature.FormalTypeParameter[] formalsForResolution = null; private String declaredSignature = null; private boolean hasBeenWoven = false; @@ -278,7 +279,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { return TypeVariable.NONE; if (typeVars == null) { - Signature.ClassSignature classSig = getGenericClassTypeSignature();// cachedGenericClassTypeSignature + GenericSignature.ClassSignature classSig = getGenericClassTypeSignature();// cachedGenericClassTypeSignature // ; // / // / @@ -287,7 +288,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { // getGenericClassTypeSignature(); typeVars = new TypeVariable[classSig.formalTypeParameters.length]; for (int i = 0; i < typeVars.length; i++) { - Signature.FormalTypeParameter ftp = classSig.formalTypeParameters[i]; + GenericSignature.FormalTypeParameter ftp = classSig.formalTypeParameters[i]; try { typeVars[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(ftp, classSig.formalTypeParameters, getResolvedTypeX().getWorld()); @@ -727,13 +728,13 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { bitflag |= UNPACKED_GENERIC_SIGNATURE; if (!getResolvedTypeX().getWorld().isInJava5Mode()) return; - Signature.ClassSignature cSig = getGenericClassTypeSignature(); + GenericSignature.ClassSignature cSig = getGenericClassTypeSignature(); if (cSig != null) { formalsForResolution = cSig.formalTypeParameters; if (isNested()) { // we have to find any type variables from the outer type before // proceeding with resolution. - Signature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass(); + GenericSignature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass(); if (extraFormals.length > 0) { List allFormals = new ArrayList(); for (int i = 0; i < formalsForResolution.length; i++) { @@ -742,11 +743,11 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { for (int i = 0; i < extraFormals.length; i++) { allFormals.add(extraFormals[i]); } - formalsForResolution = new Signature.FormalTypeParameter[allFormals.size()]; + formalsForResolution = new GenericSignature.FormalTypeParameter[allFormals.size()]; allFormals.toArray(formalsForResolution); } } - Signature.ClassTypeSignature superSig = cSig.superclassSignature; + GenericSignature.ClassTypeSignature superSig = cSig.superclassSignature; try { // this.superClass = // BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( @@ -800,10 +801,10 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { } } - public Signature.FormalTypeParameter[] getAllFormals() { + public GenericSignature.FormalTypeParameter[] getAllFormals() { ensureGenericSignatureUnpacked(); if (formalsForResolution == null) { - return new Signature.FormalTypeParameter[0]; + return new GenericSignature.FormalTypeParameter[0]; } else { return formalsForResolution; } diff --git a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java b/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java index 84853ac33..2090ed446 100644 --- a/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java +++ b/weaver/testsrc/org/aspectj/weaver/BcweaverModuleTests.java @@ -1,4 +1,5 @@ package org.aspectj.weaver; + /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. @@ -12,7 +13,6 @@ package org.aspectj.weaver; * ******************************************************************/ // default package - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -21,16 +21,19 @@ import org.aspectj.weaver.tools.ToolsTests; public class BcweaverModuleTests extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(BcweaverModuleTests.class.getName()); - suite.addTest(org.aspectj.weaver.bcel.BcelTests.suite()); - suite.addTest(org.aspectj.weaver.BcweaverTests.suite()); - suite.addTest(org.aspectj.weaver.patterns.PatternsTests.suite()); - suite.addTestSuite(LocaleTest.class); - suite.addTest(ToolsTests.suite()); - return suite; - } + public static Test suite() { + TestSuite suite = new TestSuite(BcweaverModuleTests.class.getName()); + suite.addTest(org.aspectj.weaver.bcel.BcelTests.suite()); + suite.addTest(org.aspectj.weaver.BcweaverTests.suite()); + suite.addTest(org.aspectj.weaver.patterns.PatternsTests.suite()); + suite.addTestSuite(LocaleTest.class); + suite.addTestSuite(GenericSignatureParserTest.class); + suite.addTest(ToolsTests.suite()); + return suite; + } - public BcweaverModuleTests(String name) { super(name); } + public BcweaverModuleTests(String name) { + super(name); + } -} +} diff --git a/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java b/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java new file mode 100644 index 000000000..e5948eb40 --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/GenericSignatureParserTest.java @@ -0,0 +1,63 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * ******************************************************************/ + package org.aspectj.weaver; + +import junit.framework.TestCase; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.util.GenericSignatureParser; + +/** + * @author Adrian Colyer + * @author Andy Clement + */ +public class GenericSignatureParserTest extends TestCase { + + GenericSignatureParser parser; + + protected void setUp() throws Exception { + super.setUp(); + parser = new GenericSignatureParser(); + } + + public void testClassSignatureParsingInJDK() throws Exception { + SyntheticRepository repository = SyntheticRepository.getInstance(); + String[] testClasses = new String[] { "java.lang.Comparable", "java.lang.Iterable", "java.lang.Class", "java.lang.Enum", + "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", + "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", + "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; + for (int i = 0; i < testClasses.length; i++) { + JavaClass jc = repository.loadClass(testClasses[i]); + String sig = jc.getGenericSignature(); + parser.parseAsClassSignature(sig); + } + } + + public void testMethodSignatureParsingInJDK() throws Exception { + SyntheticRepository repository = SyntheticRepository.getInstance(); + String[] testClasses = new String[] { "java.lang.Comparable", "java.lang.Iterable", "java.lang.Class", "java.lang.Enum", + "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", + "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", + "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; + for (int i = 0; i < testClasses.length; i++) { + JavaClass jc = repository.loadClass(testClasses[i]); + Method[] methods = jc.getMethods(); + for (int j = 0; j < methods.length; j++) { + String sig = methods[j].getGenericSignature(); + if (sig != null) + parser.parseAsMethodSignature(sig); + } + } + } + +} diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java index 168400e91..9ba0b1943 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXTestCase.java @@ -14,59 +14,74 @@ package org.aspectj.weaver.bcel; import junit.framework.TestCase; import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.GenericSignatureParser; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.util.GenericSignature; +import org.aspectj.util.GenericSignatureParser; +import org.aspectj.util.GenericSignature.ClassSignature; import org.aspectj.weaver.UnresolvedType; /** * @author colyer - * + * */ public class BcelGenericSignatureToTypeXTestCase extends TestCase { + public final GenericSignature.ClassSignature getGenericClassTypeSignature(JavaClass jClass) { + Signature sig = jClass.getSignatureAttribute(); + if (sig != null) { + GenericSignatureParser parser = new GenericSignatureParser(); + ClassSignature classSig = parser.parseAsClassSignature(sig.getSignature()); + return classSig; + } + return null; + } + + // public final GenericSignature.MethodTypeSignature getGenericMethodTypeSignature(JavaClass jClass) { + // Signature sig = jClass.getSignatureAttribute(); + // if (sig != null) { + // GenericSignatureParser parser = new GenericSignatureParser(); + // MethodTypeSignature mSig = parser.parseAsMethodSignature(sig); + // return mSig; + // } + // return null; + // } + + // public FieldTypeSignature asFieldTypeSignature() { + // if (fieldSig == null) { + // GenericSignatureParser parser = new GenericSignatureParser(); + // fieldSig = parser.parseAsFieldSignature(getSignature()); + // } + // return fieldSig; + // } + public void testEnumFromHell() throws Exception { BcelWorld world = new BcelWorld(); JavaClass javaLangEnum = Repository.lookupClass("java/lang/Enum"); - Signature.ClassSignature cSig = javaLangEnum.getGenericClassTypeSignature(); - UnresolvedType superclass = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superclassSignature, - cSig.formalTypeParameters, - world - ); - assertEquals("Ljava/lang/Object;",superclass.getSignature()); - assertEquals("2 superinterfaces",2,cSig.superInterfaceSignatures.length); - UnresolvedType comparable = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[0], - cSig.formalTypeParameters, - world - ); - assertEquals("Pjava/lang/Comparable;",comparable.getSignature()); - UnresolvedType serializable = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[1], - cSig.formalTypeParameters, - world - ); - assertEquals("Ljava/io/Serializable;",serializable.getSignature()); + GenericSignature.ClassSignature cSig = getGenericClassTypeSignature(javaLangEnum); + UnresolvedType superclass = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superclassSignature, + cSig.formalTypeParameters, world); + assertEquals("Ljava/lang/Object;", superclass.getSignature()); + assertEquals("2 superinterfaces", 2, cSig.superInterfaceSignatures.length); + UnresolvedType comparable = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superInterfaceSignatures[0], + cSig.formalTypeParameters, world); + assertEquals("Pjava/lang/Comparable;", comparable.getSignature()); + UnresolvedType serializable = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( + cSig.superInterfaceSignatures[1], cSig.formalTypeParameters, world); + assertEquals("Ljava/io/Serializable;", serializable.getSignature()); } - + public void testColonColon() throws Exception { BcelWorld world = new BcelWorld(); - Signature.ClassSignature cSig = new GenericSignatureParser().parseAsClassSignature("Ljava/lang/Object;Ljava/lang/Comparable;"); - UnresolvedType resolved = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superclassSignature, - cSig.formalTypeParameters, - world); - assertEquals("Ljava/lang/Object;",resolved.getSignature()); -// UnresolvedType resolvedInt = - BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX( - cSig.superInterfaceSignatures[0], - cSig.formalTypeParameters, + GenericSignature.ClassSignature cSig = new GenericSignatureParser() + .parseAsClassSignature("Ljava/lang/Object;Ljava/lang/Comparable;"); + UnresolvedType resolved = BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superclassSignature, + cSig.formalTypeParameters, world); + assertEquals("Ljava/lang/Object;", resolved.getSignature()); + // UnresolvedType resolvedInt = + BcelGenericSignatureToTypeXConverter.classTypeSignature2TypeX(cSig.superInterfaceSignatures[0], cSig.formalTypeParameters, world); - + } - + }