summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2008-04-24 04:07:23 +0000
committeraclement <aclement>2008-04-24 04:07:23 +0000
commite08d3dede2af8b0aafe460f17a40912e621f4397 (patch)
tree3326a500344bfb89f75db7b65bc21a2acf990bf7
parent528ae36edbe8fefcd1620b47758cdd4fc45095a4 (diff)
downloadaspectj-e08d3dede2af8b0aafe460f17a40912e621f4397.tar.gz
aspectj-e08d3dede2af8b0aafe460f17a40912e621f4397.zip
226567: test and fix - generic return types and overridden methods
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelMethod.java3
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java28
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java8
3 files changed, 26 insertions, 13 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
index 771245cef..36f29a4ed 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
@@ -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;
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
index 143fa1f3b..0cdf07be9 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
@@ -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())) {
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
index ddb77ace9..872a5c0e4 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
@@ -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;