]> source.dussan.org Git - aspectj.git/commitdiff
226567: test and fix - generic return types and overridden methods
authoraclement <aclement>
Thu, 24 Apr 2008 04:07:23 +0000 (04:07 +0000)
committeraclement <aclement>
Thu, 24 Apr 2008 04:07:23 +0000 (04:07 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java

index 771245cef2f4dc18cd1e19763bcbcd7394e19cea..36f29a4ed9df061cbccef8dbdac4608d9121e2d6 100644 (file)
@@ -409,6 +409,9 @@ public final class BcelMethod extends ResolvedMemberImpl {
                 return genericParameterTypes;
         }
         
+        /**
+      * Return the parameterized/generic return type or the normal return type if the method is not generic.
+      */
         public UnresolvedType getGenericReturnType() {
                 unpackGenericSignature();
                 return genericReturnType;
index 143fa1f3b883cfe5b005c907b6d0ae59d715bccb..0cdf07be9a8f30f2c03da3ba932bd1461707730d 100644 (file)
@@ -333,25 +333,24 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
      */
     private boolean enforceDecpRule4_compatibleReturnTypes(BcelClassWeaver weaver, ResolvedMember superMethod, LazyMethodGen subMethod) {
         boolean cont = true;
-        String superReturnTypeSig = superMethod.getReturnType().getSignature();
-          String subReturnTypeSig   = subMethod.getReturnType().getSignature();
-          superReturnTypeSig = superReturnTypeSig.replace('.','/');
-          subReturnTypeSig = subReturnTypeSig.replace('.','/');
-          if (!superReturnTypeSig.equals(subReturnTypeSig)) {
-            // Allow for covariance - wish I could test this (need Java5...)
+        String superReturnTypeSig = superMethod.getGenericReturnType().getSignature(); // eg. Pjava/util/Collection<LFoo;>
+        String subReturnTypeSig = subMethod.getGenericReturnTypeSignature();
+        superReturnTypeSig = superReturnTypeSig.replace('.', '/');
+        subReturnTypeSig = subReturnTypeSig.replace('.', '/');
+        if (!superReturnTypeSig.equals(subReturnTypeSig)) {
+            // Check for covariance
             ResolvedType subType   = weaver.getWorld().resolve(subMethod.getReturnType());
             ResolvedType superType = weaver.getWorld().resolve(superMethod.getReturnType());
             if (!superType.isAssignableFrom(subType)) {
-                ISourceLocation sloc = subMethod.getSourceLocation();
                 weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
-                        "The return type is incompatible with "+superMethod.getDeclaringType()+"."+superMethod.getName()+superMethod.getParameterSignature(),
-                        subMethod.getSourceLocation()));
+                        "The return type is incompatible with " + superMethod.getDeclaringType() + "." + superMethod.getName()
+                        + superMethod.getParameterSignature(), subMethod.getSourceLocation()));
 // this just might be a better error message...                      
 //                        "The return type '"+subReturnTypeSig+"' is incompatible with the overridden method "+superMethod.getDeclaringType()+"."+
 //                        superMethod.getName()+superMethod.getParameterSignature()+" which returns '"+superReturnTypeSig+"'",
                  cont=false;
             }
-          }
+        }
         return cont;
     }
     
@@ -380,11 +379,14 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
     }
    
 
+    /**
+     * Search the specified type for a particular method - do not use the return value in the comparison as it is not
+     * considered for overriding.
+     */
        private LazyMethodGen findMatchingMethod(LazyClassGen newParentTarget, ResolvedMember m) {
         LazyMethodGen found = null;
-               // Search the type for methods overriding super methods (methods that come from the new parent)
-               // Don't use the return value in the comparison as overriding doesnt
-               for (Iterator i = newParentTarget.getMethodGens().iterator(); i.hasNext() && found==null;) {
+        List methodGens = newParentTarget.getMethodGens();
+        for (Iterator i = methodGens.iterator(); i.hasNext() && found == null;) {
                    LazyMethodGen gen = (LazyMethodGen) i.next();
                    if (gen.getName().equals(m.getName()) && 
                        gen.getParameterSignature().equals(m.getParameterSignature())) {
index ddb77ace9246552d566bb5659e0aa2c2462c810e..872a5c0e40866222378282823db94eb5acd50c09 100644 (file)
@@ -887,6 +887,14 @@ public final class LazyMethodGen implements Traceable {
         return name;
     }
 
+    public String getGenericReturnTypeSignature() {
+        if (memberView == null) {
+            return getReturnType().getSignature();
+        } else {
+            return memberView.getGenericReturnType().getSignature();
+        }
+    }
+    
     public Type getReturnType() {
        initialize();
         return returnType;