From: aclement Date: Tue, 18 Oct 2005 08:22:01 +0000 (+0000) Subject: see pr112105: can parameterize taking aliases into account X-Git-Tag: V1_5_0RC1~364 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=03216706db9c7b33c60d58da09f5631b3b2f56f8;p=aspectj.git see pr112105: can parameterize taking aliases into account --- diff --git a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java index 33e43a605..6f60d9965 100644 --- a/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java @@ -71,7 +71,7 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger { public ResolvedTypeMunger parameterizedFor(ResolvedType target) { ResolvedType genericType = target; if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType(); - ResolvedMember parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType()); + ResolvedMember parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); return new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); } diff --git a/weaver/src/org/aspectj/weaver/ResolvedMember.java b/weaver/src/org/aspectj/weaver/ResolvedMember.java index 5e3bf3811..fe178a248 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMember.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMember.java @@ -15,6 +15,7 @@ package org.aspectj.weaver; import java.io.DataOutputStream; import java.io.IOException; +import java.util.List; import org.aspectj.bridge.ISourceLocation; @@ -115,6 +116,12 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe UnresolvedType[] typeParameters, ResolvedType newDeclaringType, boolean isParameterized); + // this variant allows for aliases for type variables (i.e. allowing them to have another name) + // this is used for processing ITDs that share type variables with their target generic type + public ResolvedMemberImpl parameterizedWith( + UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized,List aliases); + public void setTypeVariables(TypeVariable[] types); public TypeVariable[] getTypeVariables(); diff --git a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java index e1eafa1a6..8b69403ce 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java @@ -470,16 +470,16 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno } declaringType = declaringType.resolve(world); if (declaringType.isRawType()) declaringType = ((ReferenceType)declaringType).getGenericType(); + if (parameterTypes!=null && parameterTypes.length>0) { for (int i = 0; i < parameterTypes.length; i++) { - UnresolvedType array_element = parameterTypes[i]; - // parameterTypes[i] = parameterTypes[i].resolve(world); parameterTypes[i] = parameterTypes[i].resolve(world); } } - + returnType = returnType.resolve(world); + } finally { world.setTypeVariableLookupScope(null); } @@ -585,6 +585,12 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno return getParameterTypes(); } + + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized) { + return parameterizedWith(typeParameters,newDeclaringType,isParameterized,null); + } + + /** * Return a resolvedmember in which all the type variables in the signature * have been replaced with the given bindings. @@ -593,7 +599,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno * List (for example) - if (!isParameterized) then List will turn * into List. */ - public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized) { + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized,List aliases) { if (//isParameterized && <-- might need this bit... !getDeclaringType().isGenericType()) { throw new IllegalStateException("Can't ask to parameterize a member of a non-generic type"); @@ -603,15 +609,26 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno throw new IllegalStateException("Wrong number of type parameters supplied"); } Map typeMap = new HashMap(); + boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0; 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); } } + // For ITDs on generic types that use type variables from the target type, the aliases + // record the alternative names used throughout the ITD expression that must map to + // the same value as the type variables real name. + if (aliases!=null) { + int posn = 0; + for (Iterator iter = aliases.iterator(); iter.hasNext();) { + String typeVariableAlias = (String) iter.next(); + typeMap.put(typeVariableAlias,(!typeParametersSupplied?typeVariables[posn].getFirstBound():typeParameters[posn])); + posn++; + } + } UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(),typeMap,isParameterized); UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length];