From: aclement Date: Mon, 11 Jul 2005 10:51:48 +0000 (+0000) Subject: generics: polices the combinations of decp when using generics/raws/parameterized... X-Git-Tag: PRE_ANDY~34 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=67dda73db7ee78da816e53772e24603b6f9f13f4;p=aspectj.git generics: polices the combinations of decp when using generics/raws/parameterized types --- diff --git a/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java b/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java index ef228d43d..21a493b13 100644 --- a/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java +++ b/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java @@ -17,11 +17,16 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import org.aspectj.apache.bcel.classfile.Utility; import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; +import org.aspectj.bridge.Message; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.ISourceContext; +import org.aspectj.weaver.ReferenceType; import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.TypeX; import org.aspectj.weaver.VersionedDataInputStream; @@ -157,6 +162,45 @@ public class DeclareParents extends Declare { this.getSourceLocation(), null); return null; } + + // Ensure the target doesn't already have an + // alternate parameterization of the generic type on it + if (parentType.isParameterized() || parentType.isRawType()) { + ResolvedTypeX newParentGenericType = parentType.getGenericType(); + // Let's take a look at the parents we already have + Iterator iter = targetType.getDirectSupertypes(); + while (iter.hasNext()) { + ResolvedTypeX supertype = (ResolvedTypeX)iter.next(); + if ( ((supertype.isRawType() && parentType.isParameterized()) || + (supertype.isParameterized() && parentType.isRawType())) && newParentGenericType.equals(supertype.getGenericType())) { + // new parent is a parameterized type, but this is a raw type + world.getMessageHandler().handleMessage(new Message( + WeaverMessages.format(WeaverMessages.CANT_DECP_MULTIPLE_PARAMETERIZATIONS,parentType.getName(),targetType.getName(),supertype.getName()), + getSourceLocation(), + true, + new ISourceLocation[]{targetType.getSourceLocation()})); + return null; + } + if (supertype.isParameterized()) { + ResolvedTypeX generictype = supertype.getGenericType(); + if (newParentGenericType.equals(generictype)) { + // Have to verify the parameterizations match, otherwise its a no-go + boolean isOk = true; + for (int pNum = 0;pNum