]> source.dussan.org Git - aspectj.git/commitdiff
Changes for generic field itds - see 112105 comment 9
authoraclement <aclement>
Thu, 20 Oct 2005 08:33:35 +0000 (08:33 +0000)
committeraclement <aclement>
Thu, 20 Oct 2005 08:33:35 +0000 (08:33 +0000)
12 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseTypeMunger.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeFieldBinding.java
tests/src/org/aspectj/systemtest/ajc150/GenericITDsDesign.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.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/ResolvedType.java
weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java

index d91c04eec469616b7f8c921856a13d5b8482f078..ec9ff1fb5d31b3cc7f31e7b0b75567b06fbf505f 100644 (file)
@@ -200,12 +200,12 @@ public class InterTypeFieldDeclaration extends InterTypeDeclaration {
                }
                
                // Build a half correct resolvedmember (makeResolvedMember understands tvars) then build a fully correct sig from it
-               ResolvedMember sigtemp = world.makeResolvedMember(binding,onTypeBinding);
+               ResolvedMember sigtemp = world.makeResolvedMemberForITD(binding,onTypeBinding,interTypeScope.getRecoveryAliases());
                ResolvedMember sig = new ResolvedMemberImpl(Member.FIELD,declaringType,declaredModifiers,
                                                  sigtemp.getReturnType(),new String(declaredSelector),UnresolvedType.NONE);
                sig.setTypeVariables(sigtemp.getTypeVariables());
                
-               NewFieldTypeMunger myMunger = new NewFieldTypeMunger(sig, null);
+               NewFieldTypeMunger myMunger = new NewFieldTypeMunger(sig, null,typeVariableAliases);
                setMunger(myMunger);
                ResolvedType aspectType = world.fromEclipse(classScope.referenceContext.binding);
                ResolvedMember me = 
index 4b6287d770837e6f88d1cfdee502c2ff96316579..ba7926a864f80825e5ef7e8811eb4155c09732fb 100644 (file)
@@ -55,6 +55,8 @@ import org.aspectj.weaver.BoundedReferenceType;
 import org.aspectj.weaver.ConcreteTypeMunger;
 import org.aspectj.weaver.IHasPosition;
 import org.aspectj.weaver.Member;
+import org.aspectj.weaver.NewFieldTypeMunger;
+import org.aspectj.weaver.NewMethodTypeMunger;
 import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedMemberImpl;
@@ -642,21 +644,69 @@ public class EclipseFactory {
                }
                return ret;
        }
-
        
+       
+       // field related
+       
+       public FieldBinding makeFieldBinding(NewFieldTypeMunger nftm) {
+               return internalMakeFieldBinding(nftm.getSignature(),nftm.getTypeVariableAliases());
+       }
+
+       /**
+        * Convert a resolvedmember into an eclipse field binding
+        */
+       public FieldBinding makeFieldBinding(ResolvedMember member,List aliases) {
+               return internalMakeFieldBinding(member,aliases);
+       }
+
+       /**
+        * Convert a resolvedmember into an eclipse field binding
+        */
        public FieldBinding makeFieldBinding(ResolvedMember member) {
-               currentType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
+               return internalMakeFieldBinding(member,null);
+       }
+       
+       /**
+        * Take a normal AJ member and convert it into an eclipse fieldBinding.
+        * Taking into account any aliases that it may include due to being
+        * a generic itd.  Any aliases are put into the typeVariableToBinding
+        * map so that they will be substituted as appropriate in the returned
+        * fieldbinding.
+        */
+       public FieldBinding internalMakeFieldBinding(ResolvedMember member,List aliases) {
+               typeVariableToTypeBinding.clear();
+               TypeVariableBinding[] tvbs = null;
+               
+               ReferenceBinding declaringType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
+               
+               // If there are aliases, place them in the map
+               if (aliases!=null && aliases.size()>0) {
+                       int i =0;
+                       for (Iterator iter = aliases.iterator(); iter.hasNext();) {
+                               String element = (String) iter.next();
+                               typeVariableToTypeBinding.put(element,declaringType.typeVariables()[i++]);
+                       }
+               }
+               
+               currentType = declaringType;
                FieldBinding fb =  new FieldBinding(member.getName().toCharArray(),
                                makeTypeBinding(member.getReturnType()),
                                member.getModifiers(),
                                currentType,
                                Constant.NotAConstant);
+               typeVariableToTypeBinding.clear();
                currentType = null;
                return fb;
        }
 
        private ReferenceBinding currentType = null;
 
+       // method binding related
+       
+       public MethodBinding makeMethodBinding(NewMethodTypeMunger nmtm) {
+               return internalMakeMethodBinding(nmtm.getSignature(),nmtm.getTypeVariableAliases());
+       }
+       
        /**
         * Convert a resolvedmember into an eclipse method binding.
         */
@@ -669,33 +719,10 @@ public class EclipseFactory {
         */
        public MethodBinding makeMethodBinding(ResolvedMember member) {
                return internalMakeMethodBinding(member,null); // there are no aliases
-               
-//             typeVariableToTypeBinding.clear(); // will be filled in as we go along...
-//             TypeVariableBinding[] tvbs = null;
-//             
-//             if (member.getTypeVariables()!=null)  {
-//                     if (member.getTypeVariables().length==0)        tvbs = MethodBinding.NoTypeVariables;
-//                     else                                            tvbs = makeTypeVariableBindingsFromAJTypeVariables(member.getTypeVariables());
-//                     // QQQ do we need to bother fixing up the declaring element for each type variable?
-//             }               
-//             
-//             ReferenceBinding declaringType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
-//             currentType = declaringType;
-//             MethodBinding mb =  new MethodBinding(member.getModifiers(), 
-//                             member.getName().toCharArray(),
-//                             makeTypeBinding(member.getReturnType()),
-//                             makeTypeBindings(member.getParameterTypes()),
-//                             makeReferenceBindings(member.getExceptions()),
-//                             declaringType);
-//
-//             if (tvbs!=null) mb.typeVariables = tvbs;
-//             typeVariableToTypeBinding.clear();
-//             currentType = null;
-//             return mb;
        }
        
        /**
-        * Convert a normal AJ member and convert it into an eclipse methodBinding.
+        * Take a normal AJ member and convert it into an eclipse methodBinding.
         * Taking into account any aliases that it may include due to being a 
         * generic ITD.  Any aliases are put into the typeVariableToBinding
         * map so that they will be substituted as appropriate in the returned 
@@ -713,18 +740,18 @@ public class EclipseFactory {
                                // QQQ do we need to bother fixing up the declaring element here?
                        }
                }       
+
+               ReferenceBinding declaringType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
                
                // If there are aliases, place them in the map
                if (aliases!=null && aliases.size()!=0) {
-                       ReferenceBinding tType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
                        int i=0;
                        for (Iterator iter = aliases.iterator(); iter.hasNext();) {
                                String element = (String) iter.next();
-                               typeVariableToTypeBinding.put(element,tType.typeVariables()[i++]);
+                               typeVariableToTypeBinding.put(element,declaringType.typeVariables()[i++]);
                        }
                }
                
-               ReferenceBinding declaringType = (ReferenceBinding)makeTypeBinding(member.getDeclaringType());
                currentType = declaringType;
                MethodBinding mb =  new MethodBinding(member.getModifiers(), 
                                member.getName().toCharArray(),
index f4eca2a492ec2828ea7fd0353876ce37e333fa84..db287ecbef841588ec84a0a6403fc54f1742b870 100644 (file)
@@ -20,7 +20,6 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclarati
 import org.aspectj.org.eclipse.jdt.internal.compiler.env.IConstants;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
-import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
 import org.aspectj.weaver.ConcreteTypeMunger;
 import org.aspectj.weaver.NewConstructorTypeMunger;
@@ -154,12 +153,12 @@ public class EclipseTypeMunger extends ConcreteTypeMunger {
 
        private void mungeNewField(SourceTypeBinding sourceType, NewFieldTypeMunger munger) {           
                if (shouldTreatAsPublic() && !targetTypeX.isInterface()) {
-                       FieldBinding binding = world.makeFieldBinding(munger.getSignature());
+                       FieldBinding binding = world.makeFieldBinding(munger);
                        findOrCreateInterTypeMemberFinder(sourceType).addInterTypeField(binding);
                        //classScope.referenceContext.binding.addField(binding);
                } else {
                        InterTypeFieldBinding binding =
-                               new InterTypeFieldBinding(world, munger.getSignature(), aspectType, sourceMethod);
+                               new InterTypeFieldBinding(world, munger, aspectType, sourceMethod);
                        findOrCreateInterTypeMemberFinder(sourceType).addInterTypeField(binding);
                }
        }
index b2f0f0569900f0558c83e5a6caf725936f7814f4..e45e15c1c9e4e8cd69d87c3106b5f05e57d79aeb 100644 (file)
@@ -14,7 +14,7 @@
 package org.aspectj.ajdt.internal.compiler.lookup;
 
 import org.aspectj.weaver.AjcMemberMaker;
-import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedTypeMunger;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
@@ -31,22 +31,22 @@ public class InterTypeFieldBinding extends FieldBinding {
        public SyntheticMethodBinding writer;
        public AbstractMethodDeclaration sourceMethod;
        
-       public InterTypeFieldBinding(EclipseFactory world, ResolvedMember signature, UnresolvedType withinType,
+       public InterTypeFieldBinding(EclipseFactory world, ResolvedTypeMunger munger, UnresolvedType withinType,
                                                                        AbstractMethodDeclaration sourceMethod)
        {
-               super(world.makeFieldBinding(signature), null);
+               super(world.makeFieldBinding(munger.getSignature(),munger.getTypeVariableAliases()), null);
                this.sourceMethod = sourceMethod;
                
-               targetType = (ReferenceBinding)world.makeTypeBinding(signature.getDeclaringType());
+               targetType = (ReferenceBinding)world.makeTypeBinding(munger.getSignature().getDeclaringType());
                this.declaringClass = (ReferenceBinding)world.makeTypeBinding(withinType);
        
                reader = new SimpleSyntheticAccessMethodBinding(
                                                                world.makeMethodBinding(
-                       AjcMemberMaker.interFieldGetDispatcher(signature, withinType)
+                       AjcMemberMaker.interFieldGetDispatcher(munger.getSignature(), withinType)
                ));
                
                writer = new SimpleSyntheticAccessMethodBinding(world.makeMethodBinding(
-                       AjcMemberMaker.interFieldSetDispatcher(signature, withinType)
+                       AjcMemberMaker.interFieldSetDispatcher(munger.getSignature(), withinType)
                ));
        }
        
index 3f251e21034cfcfe4fec4bb981d08f5d3ea89037..2a1bb9ac538b5bf68913763ad920fe1574e707ac 100644 (file)
@@ -1,12 +1,14 @@
 package org.aspectj.systemtest.ajc150;
 
 import java.io.File;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.Test;
 
 import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.classfile.JavaClass;
 import org.aspectj.apache.bcel.classfile.Signature;
 import org.aspectj.apache.bcel.util.ClassPath;
@@ -24,6 +26,7 @@ import org.aspectj.weaver.World;
 import org.aspectj.weaver.bcel.BcelTypeMunger;
 import org.aspectj.weaver.bcel.BcelWorld;
 
+
 public class GenericITDsDesign extends XMLBasedAjcTestCase {
 
        private World recentWorld;
@@ -42,25 +45,28 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                                theMember.toDebugString().equals(string));
        }
 
-       
-       public static Signature getClassSignature(Ajc ajc,String classname) {
+       public static JavaClass getClassFromDisk(Ajc ajc,String classname) {
                try {
-                       ClassPath cp = 
-                               new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
-                   SyntheticRepository sRepos =  SyntheticRepository.getInstance(cp);
-                       JavaClass clazz = sRepos.loadClass(classname);
-                       Signature sigAttr = null;
-                       Attribute[] attrs = clazz.getAttributes();
-                       for (int i = 0; i < attrs.length; i++) {
-                               Attribute attribute = attrs[i];
-                               if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
-                       }
-                       return sigAttr;
+               ClassPath cp = 
+                       new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
+           SyntheticRepository sRepos =  SyntheticRepository.getInstance(cp);
+                       return sRepos.loadClass(classname);
                } catch (ClassNotFoundException e) {
                        fail("Couldn't find class "+classname+" in the sandbox directory.");
                }
                return null;
        }
+       
+       public static Signature getClassSignature(Ajc ajc,String classname) {
+               JavaClass clazz = getClassFromDisk(ajc,classname);
+               Signature sigAttr = null;
+               Attribute[] attrs = clazz.getAttributes();
+               for (int i = 0; i < attrs.length; i++) {
+                       Attribute attribute = attrs[i];
+                       if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
+               }
+               return sigAttr;
+       }
        // Check the signature attribute on a class is correct
        public static void verifyClassSignature(Ajc ajc,String classname,String sig) {
                Signature sigAttr = getClassSignature(ajc,classname);
@@ -93,6 +99,18 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                fail("Couldn't find a type munger from line "+linenumber+" in class "+classname);
                return null;
        }
+
+       public Hashtable getMeTheFields(String classname) {
+               JavaClass theClass = getClassFromDisk(ajc,classname);
+               Hashtable retval = new Hashtable();
+               org.aspectj.apache.bcel.classfile.Field[] fs = theClass.getFields();
+               for (int i = 0; i < fs.length; i++) {
+                       Field field = fs[i];
+                       retval.put(field.getName(),field);
+               }
+               return retval;
+       }
+       
        /* 
                test plan:
                  1. Serializing and recovering 'default bounds' type variable info:
@@ -192,6 +210,61 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                verifyDebugString(theBcelMunger.getMunger().getSignature(),"java.util.List<Q> C.m0(Q, int, java.util.List<java.util.List<Q>>)");
        }
        
+       // Verify: a) for fields, sharing type vars with some target type results in the correct entries in the class file
+       public void testDesignE() {
+               runTest("generic itds - design E"); 
+               BcelTypeMunger theBcelMunger = getMungerFromLine("X",9);
+               verifyDebugString(theBcelMunger.getMunger().getSignature(),"java.util.List<Z> C.ln");
+               assertTrue("Expected to find \"Z\": "+theBcelMunger.getTypeVariableAliases(),theBcelMunger.getTypeVariableAliases().contains("Z"));
+               
+               theBcelMunger = getMungerFromLine("X",11);
+               verifyDebugString(theBcelMunger.getMunger().getSignature(),"Q C.n");
+               assertTrue("Expected to find \"Q\": "+theBcelMunger.getTypeVariableAliases(),theBcelMunger.getTypeVariableAliases().contains("Q"));
+       }
+       
+       // Verifying what gets into a class targetted with a field ITD
+       public void testDesignF() {
+         runTest("generic itds - design F");   
+         Hashtable fields = getMeTheFields("C");
+      
+      // Declared in src as: List C.list1;         and       List<Z> C<Z>.list2;
+      Field list1 = (Field)fields.get("ajc$interField$$list1");
+      assertTrue("Field list1 should be of type 'Ljava/util/List;' but is "+list1.getSignature(),
+                 list1.getSignature().equals("Ljava/util/List;"));
+      Field list2 = (Field)fields.get("ajc$interField$$list1");
+      assertTrue("Field list2 should be of type 'Ljava/util/List;' but is "+list2.getSignature(),
+                 list2.getSignature().equals("Ljava/util/List;"));
+      
+      // Declared in src as: String C.field1;      and      Q C<Q>.field2;
+      // bound for second field collapses to Object
+      Field field1 = (Field)fields.get("ajc$interField$$field1");
+      assertTrue("Field list1 should be of type 'Ljava/lang/String;' but is "+field1.getSignature(),
+                 field1.getSignature().equals("Ljava/lang/String;"));
+      Field field2 = (Field)fields.get("ajc$interField$$field2");
+      assertTrue("Field list2 should be of type 'Ljava/lang/Object;' but is "+field2.getSignature(),
+                 field2.getSignature().equals("Ljava/lang/Object;"));
+       }
+       
+
+       // Verifying what gets into a class when an interface it implements was targetted with a field ITD
+       public void testDesignG() {
+      runTest("generic itds - design G");
+         Hashtable fields = getMeTheFields("C");
+     
+      // The ITDs are targetting an interface.  That interface is generic and is parameterized with
+      // 'String' when implemented in the class C.  This means the fields that make it into C should
+      // be parameterized with String also.
+         
+         //   List<Z> I<Z>.ln;                 and                                     Q I<Q>.n;
+//      Field field1 = (Field)fields.get("ajc$interField$X$I$ln");
+//      assertTrue("Field list1 should be of type 'Ljava/util/List;' but is "+field1.getSignature(),
+//               field1.getSignature().equals("Ljava/util/List;"));
+//      Field field2 = (Field)fields.get("ajc$interField$X$I$n");
+//      assertTrue("Field list2 should be of type 'Ljava/lang/String;' but is "+field2.getSignature(),
+//               field2.getSignature().equals("Ljava/lang/String;"));
+       }
+
+       
 //     // Verify: a) sharing type vars with some target type results in the correct variable names in the serialized form
 //     public void testDesignE() {
 //             runTest("generic itds - design E");
index 52a2e57a211f20dd1de476f41c6f0ebd2d750a37..5e907a2c8d7c43722ddc0833ee71eb41788ed13b 100644 (file)
        <compile files="A2.aj" inpath="code.jar" options="-1.5,-showWeaveInfo">
          <message kind="weave" text="Type 'BaseClass' (BaseClass.java) has intertyped field from 'A1' (A1.aj:'java.util.List&lt;java.lang.String&gt; BaseClass.list1')"/>
             <message kind="weave" text="Type 'BaseClass' (BaseClass.java:12) advised by after advice from 'A1' (A1.aj:7)"/>
-            <message kind="weave" text="Type 'BaseClass' (BaseClass.java) has intertyped field from 'A2' (A2.aj:'java.util.List&lt;N&gt; BaseClass.list2')"/>
+            <message kind="weave" text="Type 'BaseClass' (BaseClass.java) has intertyped field from 'A2' (A2.aj:'java.util.List&lt;Z&gt; BaseClass.list2')"/>
          <message kind="weave" text="Type 'BaseClass' (BaseClass.java:13) advised by after advice from 'A2' (A2.aj:8)"/>
        </compile>
         <run class="BaseClass">
    </ajc-test>
    
    <ajc-test dir="java5/generics/itds/design" title="generic itds - design D">
-     <compile files="DesignD.java" options="-1.5,-XnoWeave"/>
+     <compile files="DesignD.java" options="-1.5"/>
+   </ajc-test>
+
+   <ajc-test dir="java5/generics/itds/design" title="generic itds - design E">
+     <compile files="DesignE.java" options="-1.5"/>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/itds/design" title="generic itds - design F">
+     <compile files="DesignF.java" options="-1.5"/>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/itds/design" title="generic itds - design G">
+     <compile files="DesignG.java" options="-1.5"/>
    </ajc-test>
 
 </suite>
\ No newline at end of file
index 0f23fcf972513183e11a6fa9d75a7c9aef5e0219..e1ed8fbe1b815715ebb87d516d2ba97f4576c6dd 100644 (file)
@@ -94,4 +94,27 @@ public class NewConstructorTypeMunger extends ResolvedTypeMunger {
                }
        }
 
+       /**
+     * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
+     */
+       public ResolvedTypeMunger parameterizedFor(ResolvedType target) {
+               ResolvedType genericType = target;
+               if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType();
+               ResolvedMember parameterizedSignature = null;
+               // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used 
+               // in the original ITD declaration to the ones used in the actual target type declaration.
+               if (target.isGenericType()) {
+                       TypeVariable vars[] = target.getTypeVariables();
+                       UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
+                       for (int i = 0; i < vars.length; i++) {
+                               varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
+                       }
+                       parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases);
+               } else {
+                 // For raw and 'normal' parameterized targets  (e.g. Interface, Interface<String>)
+                 parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases);
+               }
+               return new NewConstructorTypeMunger(parameterizedSignature,syntheticConstructor,explicitConstructor,getSuperMethodsCalled(),typeVariableAliases);
+       }
+
 }
index e7b2a3ca57503e383a9546aca264f58ea48ab24b..6bd54722313a19543ed07ad02094c685f5db6489 100644 (file)
@@ -15,12 +15,16 @@ 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;
+
 public class NewFieldTypeMunger extends ResolvedTypeMunger {
 
-       public NewFieldTypeMunger(ResolvedMember signature, Set superMethodsCalled) {
+       public NewFieldTypeMunger(ResolvedMember signature, Set superMethodsCalled, List typeVariableAliases) {
                super(Field, signature);
+               this.typeVariableAliases = typeVariableAliases;
                signature.setAnnotatedElsewhere(true);
                this.setSuperMethodsCalled(superMethodsCalled);
        }
@@ -34,12 +38,17 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger {
                signature.write(s);
                writeSuperMethodsCalled(s);
                writeSourceLocation(s);
+               writeOutTypeAliases(s);
        }
 
        public static ResolvedTypeMunger readField(VersionedDataInputStream s, ISourceContext context) throws IOException {
-               ResolvedTypeMunger munger = new NewFieldTypeMunger(
-                       ResolvedMemberImpl.readResolvedMember(s, context),readSuperMethodsCalled(s));
-               munger.setSourceLocation(readSourceLocation(s));
+               ISourceLocation sloc = null;
+               ResolvedMember fieldSignature = ResolvedMemberImpl.readResolvedMember(s, context);
+               Set superMethodsCalled        = readSuperMethodsCalled(s);
+               sloc                          = readSourceLocation(s);
+               List aliases                  = readInTypeAliases(s);
+               ResolvedTypeMunger munger = new NewFieldTypeMunger(fieldSignature,superMethodsCalled,aliases);
+               if (sloc!=null) munger.setSourceLocation(sloc);
                return munger;
        }
        
@@ -58,4 +67,30 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger {
                if (ResolvedType.matches(ret, member)) return getSignature();
                return super.getMatchingSyntheticMember(member, aspectType);
        }
+
+       /**
+     * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
+     */
+       public ResolvedTypeMunger parameterizedFor(ResolvedType target) {
+               ResolvedType genericType = target;
+               if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType();
+               ResolvedMember parameterizedSignature = null;
+               // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used 
+               // in the original ITD declaration to the ones used in the actual target type declaration.
+               if (target.isGenericType()) {
+                       TypeVariable vars[] = target.getTypeVariables();
+                       UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
+                       for (int i = 0; i < vars.length; i++) {
+                               varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
+                       }
+                       parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases);
+               } else {
+                 // For raw and 'normal' parameterized targets  (e.g. Interface, Interface<String>)
+                 parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases);
+               }
+               NewFieldTypeMunger nftm = new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+           nftm.setOriginalSignature(getSignature());
+           return nftm;
+       }
+
 }
index f4fdeafca1cb8cd34960ecb2dfcc90eed44ba093..531b493124c715f27277d321b93a2718b9a6d5d5 100644 (file)
@@ -63,15 +63,31 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger {
                if (ResolvedType.matches(ret, member)) return getSignature();
                return super.getMatchingSyntheticMember(member, aspectType);
        }
-       
+
        /**
-     * ResolvedTypeMunger.parameterizedFor(ResolvedType)
+     * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
      */
        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(),typeVariableAliases);
-               return new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+               ResolvedMember parameterizedSignature = null;
+               // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used 
+               // in the original ITD declaration to the ones used in the actual target type declaration.
+               if (target.isGenericType()) {
+                       TypeVariable vars[] = target.getTypeVariables();
+                       UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
+                       for (int i = 0; i < vars.length; i++) {
+                               varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
+                       }
+                       parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases);
+               } else {
+                 // For raw and 'normal' parameterized targets  (e.g. Interface, Interface<String>)
+                 parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases);
+               }
+               NewMethodTypeMunger nmtm = new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+               nmtm.setOriginalSignature(getSignature());
+               return nmtm;
        }
-
+       
+       
 }
index b9036ab656a8a2e2dd0d0f3f808f8a3faf246c1e..41d98f72bfdce4c9589b9a005f2b53f09d91db7d 100644 (file)
@@ -286,7 +286,11 @@ public class ReferenceType extends ResolvedType {
 
                if (other.isTypeVariableReference()) {
                        TypeVariableReferenceType otherType = (TypeVariableReferenceType) other;
-                       return this.isAssignableFrom(otherType.getUpperBound().resolve(world));
+                       if (this instanceof TypeVariableReference) {
+                               return ((TypeVariableReference)this).getTypeVariable()==otherType.getTypeVariable();
+                       } else {
+                               return this.isAssignableFrom(otherType.getTypeVariable().getFirstBound().resolve(world));
+                       }
                }
                
                if (allowMissing && other.isMissing()) return false;
index 1f931754e33ff143805932637e06b69eed2b0b75..ba8271901a4819376d7e9ff172ddf734bfa11592 100644 (file)
@@ -1324,10 +1324,12 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                    if (debug) System.err.println("Occurrence in "+this+" is actually "+actualTarget+"  ("+actualTarget.typeKind+")");
                    // parameterize the signature
                    // ResolvedMember newOne = member.parameterizedWith(actualTarget.getTypeParameters(),onType,actualTarget.isParameterizedType());
-                   munger = munger.parameterizedFor(actualTarget);
-                   if (debug) System.err.println("New sig: "+munger.getSignature());
-                   
                }
+              //if (!actualTarget.isRawType()) 
+                  munger = munger.parameterizedFor(actualTarget);
+               if (debug) System.err.println("New sig: "+munger.getSignature());
+                   
+               
                if (debug) System.err.println("=====================================");
                }
                return munger;
@@ -1498,6 +1500,9 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
              ResolvedType rtParentReturnType = parent.getGenericReturnType().resolve(world);
                  ResolvedType rtChildReturnType  = child.getGenericReturnType().resolve(world);
                  incompatibleReturnTypes = !rtParentReturnType.isAssignableFrom(rtChildReturnType);
+                 if (incompatibleReturnTypes) {
+                         incompatibleReturnTypes = !rtParentReturnType.isAssignableFrom(rtChildReturnType);
+                 }
                } else {
                  incompatibleReturnTypes =!parent.getReturnType().equals(child.getReturnType());
                }
index 73588f89cf4dc926c96ec778bfb0c863a19fd01e..1389d78c6c0e9a4db5817743091ff74afedb09ab 100644 (file)
@@ -40,6 +40,17 @@ public abstract class ResolvedTypeMunger {
        protected Kind kind;
        protected ResolvedMember signature;
        
+       protected ResolvedMember originalSignature;
+       
+       public void setOriginalSignature(ResolvedMember rm) {
+               originalSignature = rm;
+       }
+       
+       public ResolvedMember getMostOriginalSignature() {
+               if (originalSignature==null) return signature;
+               return originalSignature;
+       }
+       
        // This list records the occurences (in order) of any names specified in the <> 
        // for a target type for the ITD.  So for example, for List<C,B,A> this list
        // will be C,B,A - the list is used later to map other occurrences of C,B,A
@@ -339,6 +350,33 @@ public abstract class ResolvedTypeMunger {
      * see ConcreteTypeMunger.parameterizedFor
      */
        public ResolvedTypeMunger parameterizedFor(ResolvedType target) {
-               throw new BCException("Should *NOT* be called for this kind of munger: "+this);
+               throw new BCException("Dont call parameterizedFor on a type munger of this kind: "+this.getClass());
        }
+//             ResolvedType genericType = target;
+//             if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType();
+//             ResolvedMember parameterizedSignature = null;
+//             // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used 
+//             // in the original ITD declaration to the ones used in the actual target type declaration.
+//             if (target.isGenericType()) {
+//                     TypeVariable vars[] = target.getTypeVariables();
+//                     UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
+//                     for (int i = 0; i < vars.length; i++) {
+//                             varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
+//                     }
+//                     parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases);
+//             } else {
+//               // For raw and 'normal' parameterized targets  (e.g. Interface, Interface<String>)
+//               parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases);
+//             }
+//             return new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+//     }
+//     /**
+//     * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
+//     */
+//     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(),typeVariableAliases);
+//             return new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases);
+//     }
 }