]> source.dussan.org Git - aspectj.git/commitdiff
211146: testcode: generics info lost from itds
authoraclement <aclement>
Thu, 21 Aug 2008 23:08:08 +0000 (23:08 +0000)
committeraclement <aclement>
Thu, 21 Aug 2008 23:08:08 +0000 (23:08 +0000)
weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java
weaver/src/org/aspectj/weaver/ResolvedType.java
weaver/src/org/aspectj/weaver/TypeVariable.java
weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index 995bc8817511db50e92c48cbe2d37b46451a6aee..6f516887fce55fede3bebb00ade3855e81a7a770 100644 (file)
@@ -395,8 +395,37 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                        returnType.write(s);
                }
     }
+
+    /**
+     * Return the member generic signature that would be suitable for inclusion in
+     * a class file Signature attribute.
+     * For:
+     * <T> List<String> getThem(T t) {}
+     * we would create:
+     * <T:Ljava/lang/Object;>(TT;)Ljava/util/List<Ljava/lang/String;>;;
+     * 
+     * @return the generic signature for the member that could be inserted into a class file
+     */
+    public String getSignatureForAttribute() {
+        StringBuffer sb = new StringBuffer();
+        if (typeVariables!=null) {
+         sb.append("<");
+                       for (int i = 0; i < typeVariables.length; i++) {
+                               sb.append(typeVariables[i].getSignatureForAttribute()); // need a 'getSignatureForAttribute()'
+                       }
+                       sb.append(">");
+         }
+        sb.append("(");
+        for (int i = 0; i < parameterTypes.length; i++) {
+                       ResolvedType ptype = (ResolvedType)parameterTypes[i];
+                       sb.append(ptype.getSignatureForAttribute());
+           }
+        sb.append(")");
+        sb.append(((ResolvedType)returnType).getSignatureForAttribute());
+        return sb.toString();
+      }
     
-    public String getGenericSignature() {
+      public String getGenericSignature() {
         StringBuffer sb = new StringBuffer();
         if (typeVariables!=null) {
          sb.append("<");
@@ -407,13 +436,13 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
          }
         sb.append("(");
         for (int i = 0; i < parameterTypes.length; i++) {
-               UnresolvedType array_element = parameterTypes[i];
-               sb.append(array_element.getSignature());
-         }
+                       UnresolvedType ptype = parameterTypes[i];
+                       sb.append(ptype.getSignature());
+           }
         sb.append(")");
         sb.append(returnType.getSignature());
         return sb.toString();
-      }
+    }
 
     public static void writeArray(ResolvedMember[] members, DataOutputStream s) throws IOException {
                s.writeInt(members.length);
index 81b6b8d499654aea292358bed10723b7315b039c..9b42665e58e91c406e85517f98db4297a55a250a 100644 (file)
@@ -2113,11 +2113,8 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
            return isAssignableFrom(o);
        }
        
-       /** 
-     * Implemented by ReferenceTypes
-     */
        public String getSignatureForAttribute() {
-               throw new RuntimeException("Cannot ask this type "+this+" for a generic sig attribute");
+               return signature;  // Assume if this is being called that it is for a simple type (eg. void, int, etc)
        }
        
        private FuzzyBoolean parameterizedWithTypeVariable = FuzzyBoolean.MAYBE;
index 344a71557ef88294ca8af47aa197c2b9d8d00fd3..1241c7a17e63a787ab507d03a6b38e1c298abd95 100644 (file)
@@ -262,7 +262,8 @@ public class TypeVariable {
        }
        
        /**
-        * Return *full* signature for insertion in signature attribute, e.g. "T extends Number" would return "T:Ljava/lang/Number;"
+        * Return complete signature, e.g. "T extends Number" would return "T:Ljava/lang/Number;"
+        * note: MAY INCLUDE P types if bounds are parameterized types
         */
        public String getSignature() {
                StringBuffer sb = new StringBuffer();
@@ -279,6 +280,25 @@ public class TypeVariable {
                return sb.toString();
        }
        
+       /**
+        * @return signature for inclusion in an attribute, there must be no 'P' in it signatures
+        */
+       public String getSignatureForAttribute() {
+               StringBuffer sb = new StringBuffer();
+               sb.append(name);
+               sb.append(":");
+               sb.append(((ResolvedType)upperBound).getSignatureForAttribute());
+               if (additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) {
+                       sb.append(":");
+                       for (int i = 0; i < additionalInterfaceBounds.length; i++) {
+                               ResolvedType iBound = (ResolvedType)additionalInterfaceBounds[i];
+                               sb.append(iBound.getSignatureForAttribute());
+                       }
+               }
+               return sb.toString();
+       }
+
+       
        public void setRank(int rank) {
                this.rank=rank;
        }
@@ -350,4 +370,5 @@ public class TypeVariable {
        public String getErasureSignature() {
                return getFirstBound().getErasureSignature();
        }
+
 }
index e81574f2cf00491667f269137911880540fa5f4c..9a823e6d4e3cd8a76983b5625c506c25fa23d21a 100644 (file)
@@ -83,7 +83,7 @@ public class TypeVariableReferenceType extends BoundedReferenceType implements T
        }
        
        public TypeVariable getTypeVariable() {
-               // if (!fixedUp) throw new BCException("ARGH"); // SAUSAGES - fix it up now?
+               // if (!fixedUp) throw new BCException("ARGH"); // fix it up now?
                return typeVariable;
        }
        
index a91ffa1ab8e6f727013a1eb7ec8940f069a68bd8..4341ed7f2ce5bfece57c713a5c03d1a9b102dad8 100644 (file)
@@ -24,6 +24,7 @@ import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.apache.bcel.generic.InstructionBranch;
 import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.Signature;
 import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
@@ -55,6 +56,7 @@ import org.aspectj.weaver.NewParentTypeMunger;
 import org.aspectj.weaver.PerObjectInterfaceTypeMunger;
 import org.aspectj.weaver.PrivilegedAccessMunger;
 import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedMemberImpl;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.ResolvedTypeMunger;
 import org.aspectj.weaver.Shadow;
@@ -858,6 +860,14 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        }
                        
 
+                       if (weaver.getWorld().isInJava5Mode()){
+                               String basicSignature = mangledInterMethod.getSignature();
+                               String genericSignature = ((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
+                               if (!basicSignature.equals(genericSignature)) {
+                                       // Add a signature attribute to it
+                                       newMethod.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+                               }
+                       }
                        // XXX make sure to check that we set exceptions properly on this guy.
                        weaver.addLazyMethodGen(newMethod);
                        weaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(),getSignature().getSourceLocation());
@@ -942,6 +952,16 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                          body.append(InstructionFactory.createReturn(returnType));
                          mg.definingType = onType;
                        
+
+                         if (weaver.getWorld().isInJava5Mode()) {
+                                 String basicSignature = mangledInterMethod.getSignature();
+                                 String genericSignature = ((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
+                                 if (!basicSignature.equals(genericSignature)) {
+                                         // Add a signature attribute to it
+                                         mg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+                                 }
+                         }
+                               
                          weaver.addOrReplaceLazyMethodGen(mg);
                        
                          addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled());
@@ -1000,6 +1020,16 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                }
        }
        
+       /** 
+        * Helper method to create a signature attribute based on a string signature:
+        *  e.g. "Ljava/lang/Object;LI<Ljava/lang/Double;>;"
+        */
+       private Signature createSignatureAttribute(ConstantPool cp,String signature) {
+               int nameIndex = cp.addUtf8("Signature");
+               int sigIndex  = cp.addUtf8(signature);
+               return new Signature(nameIndex,2,sigIndex,cp);
+       }
+       
        /**
         * Create any bridge method required because of covariant returns being used.  This method is used in the case
         * where an ITD is applied to some type and it may be in an override relationship with a method from the supertype - but
@@ -1586,6 +1616,17 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                        }
                                }
                                
+                               
+
+                               if (weaver.getWorld().isInJava5Mode()){
+                                       String basicSignature = field.getSignature();
+                                       String genericSignature = field.getReturnType().resolve(weaver.getWorld()).getSignatureForAttribute();
+       //                              String genericSignature = ((ResolvedMemberImpl)field).getSignatureForAttribute();
+                                       if (!basicSignature.equals(genericSignature)) {
+                                                 // Add a signature attribute to it
+                                                 fg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+                                       }
+                               }
                                gen.addField(fg,getSourceLocation());
                        
                        }