]> source.dussan.org Git - aspectj.git/commitdiff
see pr112105: can parameterize taking aliases into account
authoraclement <aclement>
Tue, 18 Oct 2005 08:22:01 +0000 (08:22 +0000)
committeraclement <aclement>
Tue, 18 Oct 2005 08:22:01 +0000 (08:22 +0000)
weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java
weaver/src/org/aspectj/weaver/ResolvedMember.java
weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java

index 33e43a605964be70f5eda2ae9fbece1e9b92b759..6f60d9965dfab27c1c5c00f90ee260c53e0547d2 100644 (file)
@@ -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);
        }
 
index 5e3bf381195c963febe2485796b785a599b9d6b4..fe178a248766e33e60b098332e2366173976a789 100644 (file)
@@ -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();
index e1eafa1a66a4aa128980758fb138bded61e96c2d..8b69403ce52b05ce731903272b6f22fbdff9023c 100644 (file)
@@ -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<String> (for example) - if (!isParameterized) then List<T> 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];