From: aclement Date: Fri, 6 May 2005 15:18:54 +0000 (+0000) Subject: Fix for 91053 (Generics): Generics problem with Set X-Git-Tag: PRE_ANDY~367 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=952dda914064ff58a39fc682d18cdbf3ad171475;p=aspectj.git Fix for 91053 (Generics): Generics problem with Set --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java index 395094b25..b294efccb 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java @@ -192,8 +192,12 @@ public class EclipseFactory { return TypeX.forName(getName(tvb.superclass)); } } - // FIXME asc/amc cope properly with RawTypeBindings - if (binding instanceof ParameterizedTypeBinding && !(binding instanceof RawTypeBinding)) { + + if (binding instanceof ParameterizedTypeBinding) { + if (binding instanceof RawTypeBinding) { + // special case where no parameters are specified! + return TypeX.forRawTypeNames(getName(binding)); + } ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) binding; String[] arguments = new String[ptb.arguments.length]; for (int i = 0; i < arguments.length; i++) { @@ -348,16 +352,22 @@ public class EclipseFactory { typeX = typeX.getComponentType(); } return lookupEnvironment.createArrayType(makeTypeBinding(typeX), dim); - } else if (typeX.isParameterized()){ - TypeX[] typeParameters = typeX.getTypeParameters(); - ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName()); - ReferenceBinding[] argumentBindings = new ReferenceBinding[typeParameters.length]; - for (int i = 0; i < argumentBindings.length; i++) { - argumentBindings[i] = lookupBinding(typeParameters[i].getName()); + } else if (typeX.isParameterized()) { + if (typeX.isRawType()) { + ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName()); + RawTypeBinding rtb = lookupEnvironment.createRawType(baseTypeBinding,baseTypeBinding.enclosingType()); + return rtb; + } else { + TypeX[] typeParameters = typeX.getTypeParameters(); + ReferenceBinding baseTypeBinding = lookupBinding(typeX.getBaseName()); + ReferenceBinding[] argumentBindings = new ReferenceBinding[typeParameters.length]; + for (int i = 0; i < argumentBindings.length; i++) { + argumentBindings[i] = lookupBinding(typeParameters[i].getName()); + } + ParameterizedTypeBinding ptb = + lookupEnvironment.createParameterizedType(baseTypeBinding,argumentBindings,baseTypeBinding.enclosingType()); + return ptb; } - ParameterizedTypeBinding ptb = - lookupEnvironment.createParameterizedType(baseTypeBinding,argumentBindings,baseTypeBinding.enclosingType()); - return ptb; } else { return lookupBinding(typeX.getName()); } diff --git a/tests/java5/generics/bugs/PR91053.aj b/tests/java5/generics/bugs/PR91053.aj new file mode 100644 index 000000000..75aa004a7 --- /dev/null +++ b/tests/java5/generics/bugs/PR91053.aj @@ -0,0 +1,18 @@ +import java.util.*; + +aspect X { + + private Set PR91053.aSet = new HashSet(); + + public void PR91053.add(String s) { + aSet.add(s); + } + +} + +public class PR91053 { + + public static void main(String[]argv) { + new PR91053().add("hello"); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index 96557dfe5..fe265050a 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -27,4 +27,8 @@ public class GenericsTests extends XMLBasedAjcTestCase { public void testPR91267_2() { runTest("NPE using generic methods in aspects 2"); } + + public void testPR91053() { + runTest("Generics problem with Set"); + } } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 8dca8410f..e9ef342c3 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2164,5 +2164,10 @@ + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/TypeX.java b/weaver/src/org/aspectj/weaver/TypeX.java index f3f078c37..3f5c1f39e 100644 --- a/weaver/src/org/aspectj/weaver/TypeX.java +++ b/weaver/src/org/aspectj/weaver/TypeX.java @@ -28,6 +28,8 @@ public class TypeX implements AnnotatedElement { * If this is a parameterized type, these are its parameters */ protected TypeX[] typeParameters; + + protected boolean isParameterized = false; /** * @param signature the bytecode string representation of this Type @@ -114,6 +116,7 @@ public class TypeX implements AnnotatedElement { */ public static TypeX forParameterizedTypeNames(String name, String[] paramTypeNames) { TypeX ret = TypeX.forName(name); + ret.setParameterized(true); ret.typeParameters = new TypeX[paramTypeNames.length]; for (int i = 0; i < paramTypeNames.length; i++) { ret.typeParameters[i] = TypeX.forName(paramTypeNames[i]); @@ -130,6 +133,14 @@ public class TypeX implements AnnotatedElement { return ret; } + public static TypeX forRawTypeNames(String name) { + TypeX ret = TypeX.forName(name); + ret.setParameterized(true); + // FIXME asc no need to mess up the signature is there? + // ret.signature = ret.signature+"#RAW"; + return ret; + } + /** * Creates a new type array with a fresh type appended to the end. * @@ -237,7 +248,8 @@ public class TypeX implements AnnotatedElement { public String getBaseName() { String name = getName(); if (isParameterized()) { - return name.substring(0,name.indexOf("<")); + if (isRawType()) return name; + else return name.substring(0,name.indexOf("<")); } else { return name; } @@ -292,9 +304,17 @@ public class TypeX implements AnnotatedElement { * Determines if this represents a parameterized type. */ public final boolean isParameterized() { - return signature.indexOf("<") != -1; - //(typeParameters != null) && (typeParameters.length > 0); + return isParameterized; +// return signature.indexOf("<") != -1; +// //(typeParameters != null) && (typeParameters.length > 0); } + + public final boolean isRawType() { + return isParameterized && typeParameters==null; + } + + private final void setParameterized(boolean b) { isParameterized=b;} + /** * Returns a TypeX object representing the effective outermost enclosing type diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 04ec34815..cdcac9fc5 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -137,7 +137,7 @@ public abstract class World implements Dump.INode { dumpState_cantFindTypeExceptions.add(new RuntimeException("Can't find type "+ty.getName())); } } - if (ty.isParameterized()) { + if (ty.isParameterized() && !ty.isRawType()) { for (int i = 0; i < ty.typeParameters.length; i++) { ty.typeParameters[i] = resolve(ty.typeParameters[i],allowMissing); }