diff options
author | acolyer <acolyer> | 2005-08-10 08:39:35 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-08-10 08:39:35 +0000 |
commit | dcd86778de51b16e1d4c3922f6f2d2fe594d15b5 (patch) | |
tree | 6487c44266fd8516e8f3ee77634ac2a2cad329a8 | |
parent | 56fdece12db2228299df8f5e3481d8d3eeb2cbac (diff) | |
download | aspectj-dcd86778de51b16e1d4c3922f6f2d2fe594d15b5.tar.gz aspectj-dcd86778de51b16e1d4c3922f6f2d2fe594d15b5.zip |
support for binding of parameterized types in after returning().
-rw-r--r-- | weaver/src/org/aspectj/weaver/Advice.java | 43 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/ReferenceType.java | 7 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/Shadow.java | 2 |
3 files changed, 49 insertions, 3 deletions
diff --git a/weaver/src/org/aspectj/weaver/Advice.java b/weaver/src/org/aspectj/weaver/Advice.java index 0e70432f0..7e9863c2d 100644 --- a/weaver/src/org/aspectj/weaver/Advice.java +++ b/weaver/src/org/aspectj/weaver/Advice.java @@ -17,6 +17,9 @@ import java.util.Collections; import java.util.List; import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; +import org.aspectj.util.FuzzyBoolean; +import org.aspectj.weaver.bcel.Utility; import org.aspectj.weaver.patterns.AndPointcut; import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; @@ -106,7 +109,13 @@ public abstract class Advice extends ShadowMunger { if (hasExtraParameter() && kind == AdviceKind.AfterReturning) { - return getExtraParameterType().resolve(world).isConvertableFrom(shadow.getReturnType().resolve(world)); + ResolvedType resolvedExtraParameterType = getExtraParameterType().resolve(world); + ResolvedType shadowReturnType = shadow.getReturnType().resolve(world); + boolean matches = resolvedExtraParameterType.isConvertableFrom(shadowReturnType); + if (matches && resolvedExtraParameterType.isParameterizedType()) { + maybeIssueUncheckedMatchWarning(resolvedExtraParameterType,shadowReturnType,shadow,world); + } + return matches; } else if (kind == AdviceKind.PerTargetEntry) { return shadow.hasTarget(); } else if (kind == AdviceKind.PerThisEntry) { @@ -155,6 +164,32 @@ public abstract class Advice extends ShadowMunger { } } + /** + * In after returning advice if we are binding the extra parameter to a parameterized + * type we may not be able to do a type-safe conversion. + * @param resolvedExtraParameterType the type in the after returning declaration + * @param shadowReturnType the type at the shadow + * @param world + */ + private void maybeIssueUncheckedMatchWarning(ResolvedType afterReturningType, ResolvedType shadowReturnType, Shadow shadow, World world) { + boolean inDoubt = !afterReturningType.isAssignableFrom(shadowReturnType); + if (inDoubt && world.getLint().uncheckedArgument.isEnabled()) { + String uncheckedMatchWith = afterReturningType.getSimpleBaseName(); + if (shadowReturnType.isParameterizedType() && (shadowReturnType.getRawType() == afterReturningType.getRawType())) { + uncheckedMatchWith = shadowReturnType.getSimpleName(); + } + if (!Utility.isSuppressing(getSignature().getAnnotations(), "uncheckedArgument")) { + world.getLint().uncheckedArgument.signal( + new String[] { + afterReturningType.getSimpleName(), + uncheckedMatchWith, + afterReturningType.getSimpleBaseName(), + shadow.toResolvedString(world)}, + getSourceLocation(), + new ISourceLocation[] {shadow.getSourceLocation()}); + } + } + } // ---- @@ -204,7 +239,11 @@ public abstract class Advice extends ShadowMunger { public UnresolvedType getExtraParameterType() { if (!hasExtraParameter()) return ResolvedType.MISSING; - return signature.getParameterTypes()[getBaseParameterCount()]; + if (signature instanceof ResolvedMember) { + return ((ResolvedMember)signature).getGenericParameterTypes()[getBaseParameterCount()]; + } else { + return signature.getParameterTypes()[getBaseParameterCount()]; + } } public UnresolvedType getDeclaringAspect() { diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 28e11519f..a9dcbcf4a 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -195,6 +195,11 @@ public class ReferenceType extends ResolvedType { TypeVariable tv = tvrt.getTypeVariable(); tv.resolve(world); if (!tv.canBeBoundTo(theirTypeParameters[i])) return false; + } else if (theirTypeParameters[i].isTypeVariableReference()) { + TypeVariableReferenceType tvrt = (TypeVariableReferenceType) theirTypeParameters[i]; + TypeVariable tv = tvrt.getTypeVariable(); + tv.resolve(world); + if (!tv.canBeBoundTo(myTypeParameters[i])) return false; } else { return false; } @@ -256,6 +261,8 @@ public class ReferenceType extends ResolvedType { } } } + } else { + parametersAssignable = false; } if (parametersAssignable) return true; } diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index 27ef06c38..e0de3011f 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -202,7 +202,7 @@ public abstract class Shadow { public UnresolvedType getReturnType() { if (kind == ConstructorCall) return getSignature().getDeclaringType(); else if (kind == FieldSet) return ResolvedType.VOID; - return getSignature().getReturnType(); + return getResolvedSignature().getGenericReturnType(); } |