diff options
author | aclement <aclement> | 2005-10-14 17:57:56 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-10-14 17:57:56 +0000 |
commit | 51b0f6261c8b20d424bc7d2a69dba17976894caf (patch) | |
tree | 67f8e3e772d8c74be2568c5b02c3e4fd7d613bbe /weaver | |
parent | 7e397dbfae904a4cb9d9e2fdd2f08d5361b336a0 (diff) | |
download | aspectj-51b0f6261c8b20d424bc7d2a69dba17976894caf.tar.gz aspectj-51b0f6261c8b20d424bc7d2a69dba17976894caf.zip |
Updates for generic ITDs - see pr112105 for a description of all changes.
Diffstat (limited to 'weaver')
29 files changed, 280 insertions, 61 deletions
diff --git a/weaver/src/org/aspectj/weaver/AjcMemberMaker.java b/weaver/src/org/aspectj/weaver/AjcMemberMaker.java index 142c055fa..aff454f01 100644 --- a/weaver/src/org/aspectj/weaver/AjcMemberMaker.java +++ b/weaver/src/org/aspectj/weaver/AjcMemberMaker.java @@ -643,11 +643,13 @@ public class AjcMemberMaker { int modifiers = makePublicNonFinal(meth.getModifiers()); if (onInterface) modifiers |= Modifier.ABSTRACT; - return new ResolvedMemberImpl(Member.METHOD, meth.getDeclaringType(), + ResolvedMemberImpl rmi = new ResolvedMemberImpl(Member.METHOD, meth.getDeclaringType(), modifiers, meth.getReturnType(), NameMangler.interMethod(meth.getModifiers(), aspectType, meth.getDeclaringType(), meth.getName()), - meth.getParameterTypes(), meth.getExceptions()); + meth.getParameterTypes(), meth.getExceptions()); + rmi.setTypeVariables(meth.getTypeVariables()); + return rmi; } /** @@ -661,10 +663,14 @@ public class AjcMemberMaker { paramTypes = UnresolvedType.insert(meth.getDeclaringType(), paramTypes); } - return new ResolvedMemberImpl(Member.METHOD, aspectType, PUBLIC_STATIC, + ResolvedMemberImpl rmi = new ResolvedMemberImpl(Member.METHOD, aspectType, PUBLIC_STATIC, meth.getReturnType(), NameMangler.interMethodDispatcher(aspectType, meth.getDeclaringType(), meth.getName()), paramTypes, meth.getExceptions()); + + rmi.setTypeVariables(meth.getTypeVariables()); + + return rmi; } /** @@ -684,10 +690,12 @@ public class AjcMemberMaker { } - return new ResolvedMemberImpl(Member.METHOD, aspectType, modifiers, + ResolvedMemberImpl rmi = new ResolvedMemberImpl(Member.METHOD, aspectType, modifiers, meth.getReturnType(), NameMangler.interMethodBody(aspectType, meth.getDeclaringType(), meth.getName()), paramTypes, meth.getExceptions()); + rmi.setTypeVariables(meth.getTypeVariables()); + return rmi; } diff --git a/weaver/src/org/aspectj/weaver/JoinPointSignature.java b/weaver/src/org/aspectj/weaver/JoinPointSignature.java index 7b3689173..b5fb8eb67 100644 --- a/weaver/src/org/aspectj/weaver/JoinPointSignature.java +++ b/weaver/src/org/aspectj/weaver/JoinPointSignature.java @@ -359,6 +359,10 @@ public class JoinPointSignature implements ResolvedMember { public String toGenericString() { return realMember.toGenericString(); } + + public String toDebugString() { + return realMember.toDebugString(); + } public void resetName(String newName) { realMember.resetName(newName); diff --git a/weaver/src/org/aspectj/weaver/MemberImpl.java b/weaver/src/org/aspectj/weaver/MemberImpl.java index 6a8a03472..92c1595f5 100644 --- a/weaver/src/org/aspectj/weaver/MemberImpl.java +++ b/weaver/src/org/aspectj/weaver/MemberImpl.java @@ -116,10 +116,12 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member { buf.append("("); for (int i = 0, len = paramTypes.length; i < len; i++) { if (paramTypes[i].isParameterizedType() && useRawTypes) buf.append(paramTypes[i].getErasureSignature()); + else if (paramTypes[i].isTypeVariableReference() && useRawTypes) buf.append(paramTypes[i].getErasureSignature()); else buf.append(paramTypes[i].getSignature()); } buf.append(")"); if (returnType.isParameterizedType() && useRawTypes) buf.append(returnType.getErasureSignature()); + else if (returnType.isTypeVariableReference() && useRawTypes) buf.append(returnType.getErasureSignature()); else buf.append(returnType.getSignature()); return buf.toString(); } diff --git a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java index d7538763f..1e6a286aa 100644 --- a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java @@ -15,6 +15,7 @@ package org.aspectj.weaver; import java.io.DataOutputStream; import java.io.IOException; +import java.util.List; import java.util.Set; import org.aspectj.bridge.ISourceLocation; @@ -22,8 +23,10 @@ import org.aspectj.bridge.ISourceLocation; public class NewMethodTypeMunger extends ResolvedTypeMunger { public NewMethodTypeMunger( ResolvedMember signature, - Set superMethodsCalled) { + Set superMethodsCalled, + List typeVariableAliases) { super(Method, signature); + this.typeVariableAliases = typeVariableAliases; this.setSuperMethodsCalled(superMethodsCalled); } @@ -40,14 +43,19 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger { signature.write(s); writeSuperMethodsCalled(s); writeSourceLocation(s); + writeOutTypeAliases(s); } public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException { - ResolvedMemberImpl rmi = ResolvedMemberImpl.readResolvedMember(s, context); + + ISourceLocation sloc = null; + ResolvedMemberImpl rmImpl = ResolvedMemberImpl.readResolvedMember(s, context); Set superMethodsCalled = readSuperMethodsCalled(s); - ISourceLocation sLoc = readSourceLocation(s); - ResolvedTypeMunger munger = new NewMethodTypeMunger(rmi,superMethodsCalled); - if (sLoc!=null) munger.setSourceLocation(sLoc); + sloc = readSourceLocation(s); + List typeVarAliases = readInTypeAliases(s); + + ResolvedTypeMunger munger = new NewMethodTypeMunger(rmImpl,superMethodsCalled,typeVarAliases); + if (sloc!=null) munger.setSourceLocation(sloc); return munger; } diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 42b6bc2f7..b9036ab65 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -404,7 +404,7 @@ public class ReferenceType extends ResolvedType { TypeVariable[] tvs = getGenericType().getTypeVariables(); parameters = new UnresolvedType[tvs.length]; for (int i = 0; i < tvs.length; i++) { - parameters[i] = tvs[i].getUpperBound(); + parameters[i] = tvs[i].getFirstBound(); } } return parameters; diff --git a/weaver/src/org/aspectj/weaver/ResolvedMember.java b/weaver/src/org/aspectj/weaver/ResolvedMember.java index 24736d403..5e3bf3811 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMember.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMember.java @@ -93,6 +93,8 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe // like toString but include generic signature info public String toGenericString(); + + public String toDebugString(); /** * Get the UnresolvedType for the return type, taking generic signature into account diff --git a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java index 855d6bf75..af4fe8cc1 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java @@ -355,7 +355,38 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno typeVariables[i].write(s); } } + String gsig = getGenericSignature(); + if (getSignature().equals(gsig)) { + s.writeBoolean(false); + } else { + s.writeBoolean(true); + s.writeInt(parameterTypes.length); + for (int i = 0; i < parameterTypes.length; i++) { + UnresolvedType array_element = parameterTypes[i]; + array_element.write(s); + } + returnType.write(s); + } } + + public String getGenericSignature() { + StringBuffer sb = new StringBuffer(); + if (typeVariables!=null) { + sb.append("<"); + for (int i = 0; i < typeVariables.length; i++) { + sb.append(typeVariables[i].getSignature()); + } + sb.append(">"); + } + sb.append("("); + for (int i = 0; i < parameterTypes.length; i++) { + UnresolvedType array_element = parameterTypes[i]; + sb.append(array_element.getSignature()); + } + sb.append(")"); + sb.append(returnType.getSignature()); + return sb.toString(); + } public static void writeArray(ResolvedMember[] members, DataOutputStream s) throws IOException { s.writeInt(members.length); @@ -370,7 +401,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno ResolvedMemberImpl m = new ResolvedMemberImpl(Kind.read(s), UnresolvedType.read(s), s.readInt(), s.readUTF(), s.readUTF()); m.checkedExceptions = UnresolvedType.readArray(s); - + m.start = s.readInt(); m.end = s.readInt(); m.sourceContext = sourceContext; @@ -391,6 +422,20 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno m.typeVariables[i].setDeclaringElement(m); } } + if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) { + boolean hasAGenericSignature = s.readBoolean(); + if (hasAGenericSignature) { + int ps = s.readInt(); + UnresolvedType[] params = new UnresolvedType[ps]; + for (int i = 0; i < params.length; i++) { + UnresolvedType type = params[i]; + params[i]=TypeFactory.createTypeFromSignature(s.readUTF()); + } + UnresolvedType rt = TypeFactory.createTypeFromSignature(s.readUTF()); + m.parameterTypes = params; + m.returnType = rt; + } + } } return m; } @@ -448,6 +493,9 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno public final String[] getParameterNames() { return parameterNames; } + public final void setParameterNames(String[] pnames) { + parameterNames = pnames; + } public final String[] getParameterNames(World world) { return getParameterNames(); } @@ -537,23 +585,34 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno return getParameterTypes(); } - // return a resolved member in which all type variables in the signature of this - // member have been replaced with the given bindings. - // the isParameterized flag tells us whether we are creating a raw type version or not - // if isParameterized List<T> will turn into List<String> (for example), - // but if !isParameterized List<T> will turn into List. + /** + * Return a resolvedmember in which all the type variables in the signature + * have been replaced with the given bindings. + * The 'isParameterized' flag tells us whether we are creating a raw type + * version or not. if (isParameterized) then List<T> will turn into + * List<String> (for example) - if (!isParameterized) then List<T> will turn + * into List. + */ public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized) { - if (!this.getDeclaringType().isGenericType()) { + if (//isParameterized && <-- might need this bit... + !getDeclaringType().isGenericType()) { throw new IllegalStateException("Can't ask to parameterize a member of a non-generic type"); } TypeVariable[] typeVariables = getDeclaringType().getTypeVariables(); - if (typeVariables.length != typeParameters.length) { + if (isParameterized && (typeVariables.length != typeParameters.length)) { throw new IllegalStateException("Wrong number of type parameters supplied"); } Map typeMap = new HashMap(); - for (int i = 0; i < typeVariables.length; i++) { - typeMap.put(typeVariables[i].getName(), typeParameters[i]); + if (typeVariables!=null) { + // If no 'replacements' were supplied in the typeParameters array then collapse + // type variables to their first bound. + boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0; + for (int i = 0; i < typeVariables.length; i++) { + UnresolvedType ut = (!typeParametersSupplied?typeVariables[i].getFirstBound():typeParameters[i]); + typeMap.put(typeVariables[i].getName(),ut); + } } + UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(),typeMap,isParameterized); UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length]; for (int i = 0; i < parameterizedParameterTypes.length; i++) { @@ -571,10 +630,10 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno this ); ret.setSourceContext(getSourceContext()); + ret.setPosition(getStart(),getEnd()); return ret; } - - + public void setTypeVariables(TypeVariable[] tvars) { typeVariables = tvars; } @@ -745,6 +804,53 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno } } + /** + * Useful for writing tests, returns *everything* we know about this member. + */ + public String toDebugString() { + StringBuffer r = new StringBuffer(); + + // modifiers + String mods = Modifier.toString(modifiers); + if (mods.length()!=0) r.append(mods).append(" "); + + // type variables + if (typeVariables!=null && typeVariables.length>0) { + r.append("<"); + for (int i = 0; i < typeVariables.length; i++) { + if (i>0) r.append(","); + TypeVariable t = typeVariables[i]; + r.append(t.toDebugString()); + } + r.append("> "); + } + + // 'declaring' type + r.append(returnType.toDebugString()); + r.append(' '); + + // name + r.append(declaringType.getName()); + r.append('.'); + r.append(name); + + // parameter signature if a method + if (kind != FIELD) { + r.append("("); + UnresolvedType[] params = parameterTypes; + boolean parameterNamesExist = parameterNames!=null && parameterNames.length==params.length; + if (params.length != 0) { + for (int i=0, len = params.length; i < len; i++) { + if (i>0) r.append(", "); + r.append(params[i].toDebugString()); + if (parameterNamesExist) r.append(" ").append(parameterNames[i]); + } + } + r.append(")"); + } + return r.toString(); + } + public String toGenericString() { StringBuffer buf = new StringBuffer(); buf.append(getGenericReturnType().getSimpleName()); diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java index 125e436f4..6a432dd76 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java @@ -45,7 +45,7 @@ public abstract class ResolvedTypeMunger { // across the intertype declaration to the right type variables in the generic // type upon which the itd is being made. // might need serializing the class file for binary weaving. - protected List /*String*/ typeVariableToGenericTypeVariableIndex; + protected List /*String*/ typeVariableAliases; private Set /* resolvedMembers */ superMethodsCalled = Collections.EMPTY_SET; @@ -286,4 +286,36 @@ public abstract class ResolvedTypeMunger { } } + protected static List readInTypeAliases(VersionedDataInputStream s) throws IOException { + if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) { + int count = s.readInt(); + List aliases = new ArrayList(); + for (int i=0;i<count;i++) { + aliases.add(s.readUTF()); + } + return aliases; + } + return null; + } + + protected void writeOutTypeAliases(DataOutputStream s) throws IOException { + // Write any type variable aliases + if (typeVariableAliases==null || typeVariableAliases.size()==0) { + s.writeInt(0); + } else { + s.writeInt(typeVariableAliases.size()); + for (Iterator iter = typeVariableAliases.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + s.writeUTF(element); + } + } + } + + public List getTypeVariableAliases() { + return typeVariableAliases; + } + + public boolean hasTypeVariableAliases() { + return (typeVariableAliases!=null && typeVariableAliases.size()>0); + } } diff --git a/weaver/src/org/aspectj/weaver/TypeVariable.java b/weaver/src/org/aspectj/weaver/TypeVariable.java index 1488bb25b..30ca0f9ac 100644 --- a/weaver/src/org/aspectj/weaver/TypeVariable.java +++ b/weaver/src/org/aspectj/weaver/TypeVariable.java @@ -89,6 +89,15 @@ public class TypeVariable { this.lowerBound = aLowerBound; } + // First bound is the first 'real' bound, this can be an interface if + // no class bound was specified (it will default to object) + public UnresolvedType getFirstBound() { + if (upperBound.equals(UnresolvedType.OBJECT) && additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) { + return additionalInterfaceBounds[0]; + } + return upperBound; + } + public UnresolvedType getUpperBound() { return upperBound; } @@ -253,16 +262,22 @@ public class TypeVariable { this.additionalInterfaceBounds = someTypeXs; } + public String toDebugString() { + return getDisplayName(); + } + public String getDisplayName() { StringBuffer ret = new StringBuffer(); ret.append(name); - if (!upperBound.getName().equals("java.lang.Object")) { + if (!getFirstBound().getName().equals("java.lang.Object")) { ret.append(" extends "); - ret.append(upperBound.getName()); + ret.append(getFirstBound().getName()); if (additionalInterfaceBounds != null) { for (int i = 0; i < additionalInterfaceBounds.length; i++) { - ret.append(" & "); - ret.append(additionalInterfaceBounds[i].getName()); + if (!getFirstBound().equals(additionalInterfaceBounds[i])) { + ret.append(" & "); + ret.append(additionalInterfaceBounds[i].getName()); + } } } } @@ -284,9 +299,10 @@ public class TypeVariable { public String getSignature() { StringBuffer sb = new StringBuffer(); sb.append(name); - sb.append(":"); - sb.append(upperBound.getSignature()); - if (additionalInterfaceBounds!=null) { + sb.append(":"); + sb.append(upperBound.getSignature()); + if (additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) { + sb.append(":"); for (int i = 0; i < additionalInterfaceBounds.length; i++) { UnresolvedType iBound = additionalInterfaceBounds[i]; sb.append(iBound.getSignature()); diff --git a/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java b/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java index 59b3b1b19..b12bb7262 100644 --- a/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java +++ b/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java @@ -31,13 +31,18 @@ public class TypeVariableReferenceType extends BoundedReferenceType implements T public TypeVariableReferenceType( TypeVariable aTypeVariable, World aWorld) { - super(aTypeVariable.getUpperBound().getSignature(),aWorld); + super(aTypeVariable.getFirstBound().getSignature(),aWorld); this.typeVariable = aTypeVariable; this.isExtends = false; this.isSuper = false; - setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType)aTypeVariable.getUpperBound())); } + public ReferenceTypeDelegate getDelegate() { + if (delegate==null) + setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType)typeVariable.getFirstBound())); + return delegate; + } + public UnresolvedType getUpperBound() { if (typeVariable==null) return super.getUpperBound(); return typeVariable.getUpperBound(); @@ -76,6 +81,10 @@ public class TypeVariableReferenceType extends BoundedReferenceType implements T return true; } + public String toString() { + return typeVariable.getName(); + } + public boolean isGenericWildcard() { return false; } diff --git a/weaver/src/org/aspectj/weaver/UnresolvedType.java b/weaver/src/org/aspectj/weaver/UnresolvedType.java index 7b0ef3972..abf8e000b 100644 --- a/weaver/src/org/aspectj/weaver/UnresolvedType.java +++ b/weaver/src/org/aspectj/weaver/UnresolvedType.java @@ -623,6 +623,10 @@ public class UnresolvedType implements TypeVariableDeclaringElement { public String toString() { return getName(); // + " - " + getKind(); } + + public String toDebugString() { + return getName(); + } // ---- requires worlds diff --git a/weaver/src/org/aspectj/weaver/UnresolvedTypeVariableReferenceType.java b/weaver/src/org/aspectj/weaver/UnresolvedTypeVariableReferenceType.java index e9db34508..65c109dc1 100644 --- a/weaver/src/org/aspectj/weaver/UnresolvedTypeVariableReferenceType.java +++ b/weaver/src/org/aspectj/weaver/UnresolvedTypeVariableReferenceType.java @@ -29,7 +29,7 @@ public class UnresolvedTypeVariableReferenceType extends UnresolvedType implemen } public UnresolvedTypeVariableReferenceType(TypeVariable aTypeVariable) { - super(aTypeVariable.getUpperBound().getSignature()); + super(aTypeVariable.getFirstBound().getSignature()); this.typeVariable = aTypeVariable; } @@ -111,21 +111,16 @@ public class UnresolvedTypeVariableReferenceType extends UnresolvedType implemen } } + public String toDebugString() { + return typeVariable.getName(); + } + public void write(DataOutputStream s) throws IOException { super.write(s); } - /* - public static void readDeclaringElement(DataInputStream s, UnresolvedTypeVariableReferenceType utv) - throws IOException { - int kind = s.readInt(); - utv.typeVariable.setDeclaringElementKind(kind); - if (kind == TypeVariable.TYPE) { - utv.typeVariable.setDeclaringElement(UnresolvedType.read(s)); - } else if (kind == TypeVariable.METHOD) { - // it's a method - ResolvedMember rm = ResolvedMemberImpl.readResolvedMember(new VersionedDataInputStream(s),null); - utv.typeVariable.setDeclaringElement(rm); - } + + public String getErasureSignature() { + return typeVariable.getFirstBound().getSignature(); } -*/ + } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index fae1d10b7..0ad3caa64 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -1656,7 +1656,7 @@ class BcelClassWeaver implements IClassWeaver { ResolvedMember resolvedDooberry = world.resolve(declaredSig); annotations = resolvedDooberry.getAnnotationTypes(); } else { - ResolvedMember realthing = AjcMemberMaker.interMethodDispatcher(rm,memberHostType); + ResolvedMember realthing = AjcMemberMaker.interMethodDispatcher(rm.resolve(world),memberHostType); ResolvedMember resolvedDooberry = world.resolve(realthing); // AMC temp guard for M4 if (resolvedDooberry == null) { diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java b/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java index 312280503..dbe499fd1 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java @@ -220,7 +220,11 @@ public class BcelGenericSignatureToTypeXConverter { } } if (typeVarBounds == null) { - throw new GenericSignatureFormatException("Undeclared type variable in signature: " + aTypeVarSig.typeVariableName); + // 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); + // throw new GenericSignatureFormatException("Undeclared type variable in signature: " + aTypeVarSig.typeVariableName); } if (inProgressTypeVariableResolutions.containsKey(typeVarBounds)) { return (ResolvedType) inProgressTypeVariableResolutions.get(typeVarBounds); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 7250d0f2d..32a8d36d7 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -54,9 +54,11 @@ import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.Shadow; +import org.aspectj.weaver.TypeVariableReference; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.WeaverStateInfo; +import org.aspectj.weaver.World; import org.aspectj.weaver.patterns.DeclareAnnotation; import org.aspectj.weaver.patterns.Pointcut; @@ -710,15 +712,18 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } private boolean mungeNewMethod(BcelClassWeaver weaver, NewMethodTypeMunger munger) { - ResolvedMember unMangledInterMethod = munger.getSignature(); + World w = weaver.getWorld(); + // Resolving it will sort out the tvars + ResolvedMember unMangledInterMethod = munger.getSignature().resolve(w); // do matching on the unMangled one, but actually add them to the mangled method ResolvedMember interMethodBody = munger.getInterMethodBody(aspectType); ResolvedMember interMethodDispatcher = munger.getInterMethodDispatcher(aspectType); + ResolvedMember memberHoldingAnyAnnotations = interMethodDispatcher; + ResolvedType onType = weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation()); LazyClassGen gen = weaver.getLazyClassGen(); boolean mungingInterface = gen.isInterface(); - ResolvedType onType = weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation()); if (onType.isRawType()) onType = onType.getGenericType(); boolean onInterface = onType.isInterface(); @@ -758,9 +763,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger { AnnotationX annotationsOnRealMember[] = null; ResolvedType toLookOn = aspectType; if (aspectType.isRawType()) toLookOn = aspectType.getGenericType(); - ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn,interMethodDispatcher); + ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false); if (realMember==null) throw new BCException("Couldn't find ITD holder member '"+ - interMethodDispatcher+"' on aspect "+aspectType); + memberHoldingAnyAnnotations+"' on aspect "+aspectType); annotationsOnRealMember = realMember.getAnnotations(); if (annotationsOnRealMember!=null) { @@ -878,7 +883,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } } - private ResolvedMember getRealMemberForITDFromAspect(ResolvedType aspectType,ResolvedMember lookingFor) { + private ResolvedMember getRealMemberForITDFromAspect(ResolvedType aspectType,ResolvedMember lookingFor,boolean isCtorRelated) { + World world = aspectType.getWorld(); + boolean debug = false; + if (debug) { + System.err.println("Searching for a member on type: "+aspectType); + System.err.println("Member we are looking for: "+lookingFor); + } ResolvedMember aspectMethods[] = aspectType.getDeclaredMethods(); UnresolvedType [] lookingForParams = lookingFor.getParameterTypes(); @@ -886,21 +897,39 @@ public class BcelTypeMunger extends ConcreteTypeMunger { for (int i = 0; realMember==null && i < aspectMethods.length; i++) { ResolvedMember member = aspectMethods[i]; if (member.getName().equals(lookingFor.getName())){ - UnresolvedType [] memberParams = member.getParameterTypes(); + UnresolvedType [] memberParams = member.getGenericParameterTypes(); if (memberParams.length == lookingForParams.length){ + if (debug) System.err.println("Reviewing potential candidates: "+member); boolean matchOK = true; - for (int j = 0; j < memberParams.length && matchOK; j++){ - UnresolvedType memberParam = memberParams[j]; - UnresolvedType lookingForParam = lookingForParams[j].resolve(aspectType.getWorld()); - if (lookingForParam.isTypeVariableReference()) lookingForParam = lookingForParam.getUpperBound(); - if (!memberParam.equals(lookingForParam)){ + // If not related to a ctor ITD then the name is enough to confirm we have the + // right one. If it is ctor related we need to check the params all match, although + // only the erasure. + if (isCtorRelated) { + for (int j = 0; j < memberParams.length && matchOK; j++){ + ResolvedType pMember = memberParams[j].resolve(world); + ResolvedType pLookingFor = lookingForParams[j].resolve(world); + + if (pMember.isTypeVariableReference()) + pMember = ((TypeVariableReference)pMember).getTypeVariable().getFirstBound().resolve(world); + if (pMember.isParameterizedType() || pMember.isGenericType()) + pMember = pMember.getRawType().resolve(aspectType.getWorld()); + + if (pLookingFor.isTypeVariableReference()) + pLookingFor = ((TypeVariableReference)pLookingFor).getTypeVariable().getFirstBound().resolve(world); + if (pLookingFor.isParameterizedType() || pLookingFor.isGenericType()) + pLookingFor = pLookingFor.getRawType().resolve(world); + + if (debug) System.err.println("Comparing parameter "+j+" member="+pMember+" lookingFor="+pLookingFor); + if (!pMember.equals(pLookingFor)){ matchOK=false; } + } } if (matchOK) realMember = member; } } } + if (debug && realMember==null) System.err.println("Didn't find a match"); return realMember; } @@ -981,7 +1010,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { ResolvedMember interMethodDispatcher =AjcMemberMaker.postIntroducedConstructor(aspectType,onType,newConstructorTypeMunger.getSignature().getParameterTypes()); AnnotationX annotationsOnRealMember[] = null; - ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType,interMethodDispatcher); + ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType,interMethodDispatcher,true); if (realMember==null) throw new BCException("Couldn't find ITD holder member '"+ interMethodDispatcher+"' on aspect "+aspectType); annotationsOnRealMember = realMember.getAnnotations(); @@ -1159,7 +1188,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // the below line just gets the method with the same name in aspectType.getDeclaredMethods(); ResolvedType toLookOn = aspectType; if (aspectType.isRawType()) toLookOn = aspectType.getGenericType(); - ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn,interMethodBody); + ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn,interMethodBody,false); if (realMember==null) throw new BCException("Couldn't find ITD init member '"+ interMethodBody+"' on aspect "+aspectType); annotationsOnRealMember = realMember.getAnnotations(); diff --git a/weaver/testdata/dummyAspect.jar b/weaver/testdata/dummyAspect.jar Binary files differindex 22dccf292..2f4662864 100644 --- a/weaver/testdata/dummyAspect.jar +++ b/weaver/testdata/dummyAspect.jar diff --git a/weaver/testdata/ltw-acaspects.jar b/weaver/testdata/ltw-acaspects.jar Binary files differindex d637f7e9e..357f924ce 100644 --- a/weaver/testdata/ltw-acaspects.jar +++ b/weaver/testdata/ltw-acaspects.jar diff --git a/weaver/testdata/ltw-aspects.jar b/weaver/testdata/ltw-aspects.jar Binary files differindex 5a6a924a0..9ec31adc7 100644 --- a/weaver/testdata/ltw-aspects.jar +++ b/weaver/testdata/ltw-aspects.jar diff --git a/weaver/testdata/ltw-classes.jar b/weaver/testdata/ltw-classes.jar Binary files differindex de87ac21f..029ad0c5d 100644 --- a/weaver/testdata/ltw-classes.jar +++ b/weaver/testdata/ltw-classes.jar diff --git a/weaver/testdata/ltw-deaspects.jar b/weaver/testdata/ltw-deaspects.jar Binary files differindex 39e0903ce..4d3908db0 100644 --- a/weaver/testdata/ltw-deaspects.jar +++ b/weaver/testdata/ltw-deaspects.jar diff --git a/weaver/testdata/ltw-dwaspects.jar b/weaver/testdata/ltw-dwaspects.jar Binary files differindex 278379033..fe86800bc 100644 --- a/weaver/testdata/ltw-dwaspects.jar +++ b/weaver/testdata/ltw-dwaspects.jar diff --git a/weaver/testdata/ltw-itdaspects.jar b/weaver/testdata/ltw-itdaspects.jar Binary files differindex ac8abfcf6..ce3fff669 100644 --- a/weaver/testdata/ltw-itdaspects.jar +++ b/weaver/testdata/ltw-itdaspects.jar diff --git a/weaver/testdata/ltw-peraspects.jar b/weaver/testdata/ltw-peraspects.jar Binary files differindex 3214321fb..84c8b473b 100644 --- a/weaver/testdata/ltw-peraspects.jar +++ b/weaver/testdata/ltw-peraspects.jar diff --git a/weaver/testdata/ltw-woven.jar b/weaver/testdata/ltw-woven.jar Binary files differindex 15cb0ec85..d2b4c54b2 100644 --- a/weaver/testdata/ltw-woven.jar +++ b/weaver/testdata/ltw-woven.jar diff --git a/weaver/testdata/megatrace.jar b/weaver/testdata/megatrace.jar Binary files differindex ea05f8ab5..2887da72e 100644 --- a/weaver/testdata/megatrace.jar +++ b/weaver/testdata/megatrace.jar diff --git a/weaver/testdata/megatrace0easy.jar b/weaver/testdata/megatrace0easy.jar Binary files differindex 68085fae7..42cbb2bac 100644 --- a/weaver/testdata/megatrace0easy.jar +++ b/weaver/testdata/megatrace0easy.jar diff --git a/weaver/testdata/megatrace0hard.jar b/weaver/testdata/megatrace0hard.jar Binary files differindex 08b449bba..94dfd4e98 100644 --- a/weaver/testdata/megatrace0hard.jar +++ b/weaver/testdata/megatrace0hard.jar diff --git a/weaver/testdata/megatraceNoweave.jar b/weaver/testdata/megatraceNoweave.jar Binary files differindex e0e5a5e87..9ccb03be4 100644 --- a/weaver/testdata/megatraceNoweave.jar +++ b/weaver/testdata/megatraceNoweave.jar diff --git a/weaver/testdata/tracing.jar b/weaver/testdata/tracing.jar Binary files differindex 46aeb0b70..6afb051f0 100644 --- a/weaver/testdata/tracing.jar +++ b/weaver/testdata/tracing.jar |