]> source.dussan.org Git - aspectj.git/commitdiff
AspectJ6: beginnings of fix for proper parameterization of generic ITDs
authoraclement <aclement>
Thu, 17 Jan 2008 00:24:51 +0000 (00:24 +0000)
committeraclement <aclement>
Thu, 17 Jan 2008 00:24:51 +0000 (00:24 +0000)
weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java
weaver/src/org/aspectj/weaver/JoinPointSignature.java
weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java
weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java
weaver/src/org/aspectj/weaver/ReferenceType.java
weaver/src/org/aspectj/weaver/ResolvedMember.java
weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java
weaver/src/org/aspectj/weaver/ResolvedType.java
weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index abb85f65aeb4c52e7288dfa9f5caf3d17416bc9c..65a485e00d900441b3f6b13ec6bb6ba75ed7e838 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.aspectj.weaver;
 
+import java.util.Map;
+
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.util.PartialOrder;
 
@@ -123,4 +125,6 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab
                if (munger==null) return false;
                return munger.isLateMunger();
        }
+
+       public abstract ConcreteTypeMunger parameterizeWith(Map parameterizationMap, World world);
 }
index 246de45f3e3341f8e0b97b857e4b6ad3a31aa933..57752d232cd23d279c202ceecb5b6b66f750d2cd 100644 (file)
@@ -16,6 +16,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.weaver.AjAttribute.EffectiveSignatureAttribute;
@@ -406,4 +407,8 @@ public class JoinPointSignature implements ResolvedMember {
        }
 
        public void evictWeavingState() { realMember.evictWeavingState(); }
+
+       public ResolvedMember parameterizedWith(Map m, World w) {
+               return realMember.parameterizedWith(m,w);
+       }
 }
index 6a0974965ece1ad38938bae1c9f0d5056c1d341d..19ed670ab60c406bd346fafbf014000069dba5da 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.weaver;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.ISourceLocation;
@@ -94,6 +95,14 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger {
            return nftm;
        }
 
+       public ResolvedTypeMunger parameterizeWith(Map m, World w) {
+               ResolvedMember parameterizedSignature = getSignature().parameterizedWith(m,w);
+               NewFieldTypeMunger nftm = new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+               nftm.setDeclaredSignature(getSignature());
+               nftm.setSourceLocation(getSourceLocation());
+               return nftm;
+       }
+
     public boolean equals(Object other) {
         if (! (other instanceof NewFieldTypeMunger)) return false;
         NewFieldTypeMunger o = (NewFieldTypeMunger) other;
index 05b6112ce7f943764098d83a57b0c2edcebc2552..7ce5e1e8a9ea4ca16c0349e226a4972c5db786b6 100644 (file)
@@ -16,11 +16,15 @@ package org.aspectj.weaver;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.weaver.patterns.DeclareParents;
 
 public class NewMethodTypeMunger extends ResolvedTypeMunger {
+
+
        public NewMethodTypeMunger(
                ResolvedMember signature,
                Set superMethodsCalled,
@@ -128,5 +132,13 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger {
         result = 37*result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
         return result;
     }
-       
+
+       public ResolvedTypeMunger parameterizeWith(Map m, World w) {
+               ResolvedMember parameterizedSignature = getSignature().parameterizedWith(m,w);
+               NewMethodTypeMunger nmtm = new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+               nmtm.setDeclaredSignature(getSignature());
+               nmtm.setSourceLocation(getSourceLocation());
+               return nmtm;
+       }
+
 }
index 31313cad8fc394dc3f69c3da77770f8267bf78f0..8ffac153b567ff53ccc70f5843d08ff1a08e1bb9 100644 (file)
@@ -65,6 +65,7 @@ public class ReferenceType extends ResolvedType {
        ResolvedMember[] parameterizedPointcuts = null;
        ResolvedType[] parameterizedInterfaces = null;
        Collection parameterizedDeclares = null;
+       Collection parameterizedTypeMungers = null;
        
        //??? should set delegate before any use
     public ReferenceType(String signature, World world) {
@@ -596,7 +597,28 @@ public class ReferenceType extends ResolvedType {
                return declares;
        }
        
-       protected Collection getTypeMungers() { return delegate.getTypeMungers(); }
+       protected Collection getTypeMungers() { 
+               return delegate.getTypeMungers();
+       }
+               // GENERICITDFIX
+////           Map parameterizationMap = getAjMemberParameterizationMap();
+//             
+//     //      if (parameterizedTypeMungers != null) return parameterizedTypeMungers;
+//             Collection ret = null;
+//             if (ajMembersNeedParameterization()) {
+//                     Collection genericDeclares = delegate.getTypeMungers(); 
+//                     parameterizedTypeMungers = new ArrayList();
+//                     Map parameterizationMap = getAjMemberParameterizationMap();
+//                     for (Iterator iter = genericDeclares.iterator(); iter.hasNext();) {
+//                             ConcreteTypeMunger munger = (ConcreteTypeMunger)iter.next();
+//                             parameterizedTypeMungers.add(munger.parameterizeWith(parameterizationMap,world));
+//                     }
+//                     ret = parameterizedTypeMungers;
+//             } else {
+//                     ret = delegate.getTypeMungers(); 
+//             }
+//             return ret;
+//     }
        
        protected Collection getPrivilegedAccesses() { return delegate.getPrivilegedAccesses(); }
 
index 1664f1a18e7cd174c79edf25c6b75e0614f1caf4..61008578f5c24aee6cc64a38b2bca37862b7c43a 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.weaver;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
 import org.aspectj.bridge.ISourceLocation;
 
@@ -159,4 +160,6 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe
     public void resetReturnTypeToObjectArray();
     
        public void evictWeavingState();
+
+       public ResolvedMember parameterizedWith(Map m, World w);
 }
\ No newline at end of file
index d1bff981621239189a4cc67d638c66d9f2d8657c..8401fa4c8ce1890029013b6229742b632182ad36 100644 (file)
@@ -660,6 +660,68 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                ret.setParameterNames(getParameterNames());
                return ret;
        }
+       
+
+       /**
+        * Replace occurrences of type variables in the signature with values contained in the map.  The map is of the form A=String,B=Integer and
+        * so a signature List<A> Foo.m(B i) {} would become List<String> Foo.m(Integer i) {}
+        */
+       public ResolvedMember parameterizedWith(Map m, World w) {
+//             if (//isParameterized &&  <-- might need this bit...
+//                             !getDeclaringType().isGenericType()) {
+//                     throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: "+getDeclaringType()+"  kind("+getDeclaringType().typeKind+")");
+//             }
+        declaringType = declaringType.resolve(w);
+        if (declaringType.isRawType()) declaringType = ((ResolvedType)declaringType).getGenericType();
+               TypeVariable[] typeVariables = getDeclaringType().getTypeVariables();
+//             if (isParameterized && (typeVariables.length != typeParameters.length)) {
+//                     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.
+//                     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(),m,true,w);
+               UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length];           
+               UnresolvedType[] genericParameterTypes = getGenericParameterTypes(); 
+               for (int i = 0; i < parameterizedParameterTypes.length; i++) {
+                       parameterizedParameterTypes[i] = 
+                               parameterize(genericParameterTypes[i], m,true,w);
+               }
+               ResolvedMemberImpl ret = new ResolvedMemberImpl(
+                                       getKind(),
+                                       declaringType,
+                                       getModifiers(),
+                                       parameterizedReturnType,
+                                       getName(),
+                                       parameterizedParameterTypes,
+                                       getExceptions(),
+                                       this
+                               );
+               ret.setTypeVariables(getTypeVariables());
+               ret.setSourceContext(getSourceContext());
+               ret.setPosition(getStart(),getEnd());
+               ret.setParameterNames(getParameterNames());
+               return ret;
+       }
                
        public void setTypeVariables(TypeVariable[] tvars) {
                typeVariables = tvars;
@@ -668,8 +730,12 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
        public TypeVariable[] getTypeVariables() {
                return typeVariables;
        }
-       
+
        protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType) {
+               return parameterize(aType,typeVariableMap,inParameterizedType,null);
+       }
+       
+       protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType,World w) {
                if (aType instanceof TypeVariableReference) {
                        String variableName = ((TypeVariableReference)aType).getTypeVariable().getName();
                        if (!typeVariableMap.containsKey(variableName)) {
@@ -678,7 +744,15 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                        return (UnresolvedType) typeVariableMap.get(variableName);
                } else if (aType.isParameterizedType()) {
                        if (inParameterizedType) {
-                               if (aType instanceof UnresolvedType) aType= aType.resolve(((ResolvedType)getDeclaringType()).getWorld());
+//                             if (!(getDeclaringType() instanceof ResolvedType)) {
+//                                     int stop = 1;
+//                             }
+                               if (aType instanceof UnresolvedType) {
+                                       if (w!=null) aType = aType.resolve(w);
+                                       else {
+                                               aType= aType.resolve(((ResolvedType)getDeclaringType()).getWorld());
+                                       }
+                               }
                                return aType.parameterize(typeVariableMap);
                        } else {
                                return aType.getRawType();
index 7d0bf1fafb8d4ddd2504d7befdbe78306b6ead1b..65fa61ac9de51cbb1af4793f12bc3ba8abd59c74 100644 (file)
@@ -508,7 +508,9 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                crosscuttingMembers = new CrosscuttingMembers(this,shouldConcretizeIfNeeded);
                crosscuttingMembers.setPerClause(getPerClause());
                crosscuttingMembers.addShadowMungers(collectShadowMungers());
-               crosscuttingMembers.addTypeMungers(getTypeMungers());
+               // GENERICITDFIX
+//             crosscuttingMembers.addTypeMungers(collectTypeMungers());
+        crosscuttingMembers.addTypeMungers(getTypeMungers());
         //FIXME AV - skip but needed ?? or  ?? crosscuttingMembers.addLateTypeMungers(getLateTypeMungers());
                crosscuttingMembers.addDeclares(collectDeclares(!this.doesNotExposeShadowMungers()));
                crosscuttingMembers.addPrivilegedAccesses(getPrivilegedAccesses());
@@ -518,6 +520,41 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                return crosscuttingMembers;
        }
        
+       public final Collection collectTypeMungers() {
+               if (! this.isAspect() ) return Collections.EMPTY_LIST;
+               
+               ArrayList ret = new ArrayList();
+               //if (this.isAbstract()) {
+//             for (Iterator i = getDeclares().iterator(); i.hasNext();) {
+//                     Declare dec = (Declare) i.next();
+//                     if (!dec.isAdviceLike()) ret.add(dec);
+//             }
+//        
+//        if (!includeAdviceLike) return ret;
+        
+               if (!this.isAbstract()) {
+                       final Iterators.Filter dupFilter = Iterators.dupFilter();
+               Iterators.Getter typeGetter = new Iterators.Getter() {
+                   public Iterator get(Object o) {
+                       return 
+                           dupFilter.filter(
+                               ((ResolvedType)o).getDirectSupertypes());
+                   }
+               };
+               Iterator typeIterator = Iterators.recur(this, typeGetter);
+       
+               while (typeIterator.hasNext()) {
+                       ResolvedType ty = (ResolvedType) typeIterator.next();
+                       for (Iterator i = ty.getTypeMungers().iterator(); i.hasNext();) {
+                               ConcreteTypeMunger dec = (ConcreteTypeMunger) i.next();
+                                       ret.add(dec);
+                               }
+               }
+               }
+               
+               return ret;
+    }
+       
        public final Collection collectDeclares(boolean includeAdviceLike) {
                if (! this.isAspect() ) return Collections.EMPTY_LIST;
                
@@ -1480,6 +1517,22 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
        //??? returning too soon
        private boolean compareToExistingMembers(ConcreteTypeMunger munger, Iterator existingMembers) {
                ResolvedMember sig = munger.getSignature();
+               
+               ResolvedType declaringAspectType = munger.getAspectType();
+//             if (declaringAspectType.isRawType()) declaringAspectType = declaringAspectType.getGenericType();
+//             if (declaringAspectType.isGenericType()) {
+//
+//                    ResolvedType genericOnType =             getWorld().resolve(sig.getDeclaringType()).getGenericType();
+//                    ConcreteTypeMunger ctm =         munger.parameterizedFor(discoverActualOccurrenceOfTypeInHierarchy(genericOnType));
+//                    sig = ctm.getSignature(); // possible sig change when type
+//             }
+//                if (munger.getMunger().hasTypeVariableAliases()) {
+//                    ResolvedType genericOnType =
+//             getWorld().resolve(sig.getDeclaringType()).getGenericType();
+//                    ConcreteTypeMunger ctm =
+//             munger.parameterizedFor(discoverActualOccurrenceOfTypeInHierarchy(genericOnType));
+//                    sig = ctm.getSignature(); // possible sig change when type parameters filled in
+//                    }
                while (existingMembers.hasNext()) {
                        
                        ResolvedMember existingMember = (ResolvedMember)existingMembers.next();
index 594e31030a04fb077ab04d2b75cb3fcc0f37de16..f3c631399b36e4adeaf8f2a7ff84fe6734b2e4d6 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.bridge.ISourceLocation;
@@ -68,6 +69,17 @@ public abstract class ResolvedTypeMunger {
                        if (declaringType.isRawType()) throw new IllegalStateException("Use generic type, not raw type");
                        if (declaringType.isParameterizedType()) throw new IllegalStateException("Use generic type, not parameterized type");
                }
+//             boolean aChangeOccurred = false;
+//             
+//             UnresolvedType rt = signature.getReturnType();
+//             if (rt.isParameterizedType() || rt.isGenericType()) {rt = rt.getRawType();aChangeOccurred=true;}
+//             UnresolvedType[] pt = signature.getParameterTypes();
+//             for (int i = 0; i < pt.length; i++) {
+//                     if (pt[i].isParameterizedType() || pt[i].isGenericType()) { pt[i] = pt[i].getRawType();aChangeOccurred=true;}
+//             }
+//             if (aChangeOccurred) {
+//                     this.signature = new ResolvedMemberImpl(signature.getKind(),signature.getDeclaringType(),signature.getModifiers(),rt,signature.getName(),pt,signature.getExceptions());
+//             }
        }
        
        public void setSourceLocation(ISourceLocation isl) {
@@ -424,5 +436,9 @@ public abstract class ResolvedTypeMunger {
        public boolean existsToSupportShadowMunging() {
                return false;
        }
+
+       public ResolvedTypeMunger parameterizeWith(Map m, World w) {
+               throw new BCException("Dont call parameterizeWith() on a type munger of this kind: "+this.getClass());
+       }
        
 }
index fec373f0c68a569497eb188474187268f8a37649..143fa1f3b883cfe5b005c907b6d0ae59d715bccb 100644 (file)
@@ -17,6 +17,7 @@ package org.aspectj.weaver.bcel;
 import java.lang.reflect.Modifier;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.apache.bcel.Constants;
@@ -1713,6 +1714,10 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
        public ConcreteTypeMunger parameterizedFor(ResolvedType target) {
                return new BcelTypeMunger(munger.parameterizedFor(target),aspectType);
        }
+
+       public ConcreteTypeMunger parameterizeWith(Map m, World w) {
+               return new BcelTypeMunger(munger.parameterizeWith(m,w),aspectType);
+       }
        
        /**
         * Returns a list of type variable aliases used in this munger.  For example, if the