From: aclement Date: Thu, 16 Jun 2005 08:30:14 +0000 (+0000) Subject: Fix and tests for bug 100227: [generics][itds] inner class with generic enclosing... X-Git-Tag: PRE_ANDY~152 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7d5002ad52c86eefdf58535310fb41f042206d11;p=aspectj.git Fix and tests for bug 100227: [generics][itds] inner class with generic enclosing class --- 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 b4b89cf5e..6380392fa 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 @@ -199,13 +199,18 @@ public class EclipseFactory { return TypeX.forRawTypeNames(getName(binding)); } ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) binding; - String[] arguments = new String[ptb.arguments.length]; - for (int i = 0; i < arguments.length; i++) { - if (ptb.arguments[i] instanceof WildcardBinding) { - WildcardBinding wcb = (WildcardBinding) ptb.arguments[i]; - arguments[i] = getName(((TypeVariableBinding)wcb.typeVariable()).firstBound); - } else { - arguments[i] = fromBinding(ptb.arguments[i]).getName(); + + String[] arguments = null; + + if (ptb.arguments!=null) { // null can mean this is an inner type of a Parameterized Type with no bounds of its own (pr100227) + arguments = new String[ptb.arguments.length]; + for (int i = 0; i < arguments.length; i++) { + if (ptb.arguments[i] instanceof WildcardBinding) { + WildcardBinding wcb = (WildcardBinding) ptb.arguments[i]; + arguments[i] = getName(((TypeVariableBinding)wcb.typeVariable()).firstBound); + } else { + arguments[i] = fromBinding(ptb.arguments[i]).getName(); + } } } return TypeX.forParameterizedTypeNames(getName(binding), arguments); diff --git a/tests/bugs150/pr100227.aj b/tests/bugs150/pr100227.aj new file mode 100644 index 000000000..b7c899b0f --- /dev/null +++ b/tests/bugs150/pr100227.aj @@ -0,0 +1,33 @@ +class Outer { + class Inner {public void p() {System.err.println("Outer.Inner.p() executing");} } + public void m() { new Inner().p(); } +} + +class Generic_Outer { + class Inner {public void p() {System.err.println("Generic_Outer.Inner.p() executing");} } + + public void m() { new Inner().p(); } +} + +aspect Injector { + int Outer.outer = 1; + int Outer.Inner.inner = 2; + int Generic_Outer.outer = 3; + int Generic_Outer.Inner.inner = 4; + + before(Object o): execution(* p()) && this(o) { + if (o instanceof Outer.Inner) { + System.err.println("Outer.Inner.inner="+((Outer.Inner)o).inner); + } + if (o instanceof Generic_Outer.Inner) { + System.err.println("Generic_Outer.Inner.inner="+((Generic_Outer.Inner)o).inner); + } + } +} + +public class pr100227 { + public static void main(String []argv) { + new Outer().m(); + new Generic_Outer().m(); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index f3bf1c418..1292a7475 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -180,9 +180,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testGenerics_pr99089() {runTest("ArrayIndexOutOfBoundsException - Generics in privileged aspects");} - public void testItdGenerics_pr99228() {runTest("ITD of a field into a generic class");} - public void testItdGenerics_pr98320() {runTest("intertype with nested generic type");} - + public void testItdGenerics_pr99228() {runTest("ITD of a field into a generic class");} + public void testItdGenerics_pr98320() {runTest("intertype with nested generic type");} + public void testItdGenerics_pr100227() {runTest("inner class with generic enclosing class");} + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 00ab89eb9..48cadc36e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2275,6 +2275,18 @@ + + + + + + + + + + + + // end of generic bugs // generic aspects diff --git a/weaver/src/org/aspectj/weaver/TypeX.java b/weaver/src/org/aspectj/weaver/TypeX.java index 4e5cdb38f..e57cdf5d1 100644 --- a/weaver/src/org/aspectj/weaver/TypeX.java +++ b/weaver/src/org/aspectj/weaver/TypeX.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.List; + public class TypeX implements AnnotatedElement { /** @@ -34,11 +35,13 @@ public class TypeX implements AnnotatedElement { */ protected String rawTypeSignature; - /** - * If this is a parameterized type, these are its parameters - */ + // It is not sufficient to say that a parameterized type with no type parameters in fact + // represents a raw type - a parameterized type with no type parameters can represent + // an inner type of a parameterized type that specifies no type parameters of its own. protected TypeX[] typeParameters; private boolean isParameterized = false; + private boolean isRawtype = false; + /** * @param signature the bytecode string representation of this Type @@ -194,26 +197,32 @@ 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]); + ret.typeParameters = null; + if (paramTypeNames!=null) { + ret.typeParameters = new TypeX[paramTypeNames.length]; + for (int i = 0; i < paramTypeNames.length; i++) { + ret.typeParameters[i] = TypeX.forName(paramTypeNames[i]); + } } ret.rawTypeSignature = ret.signature; // sig for e.g. List is Ljava/util/List; - StringBuffer sigAddition = new StringBuffer(); - sigAddition.append("<"); - for (int i = 0; i < ret.typeParameters.length; i++) { - sigAddition.append(ret.typeParameters[i].signature); + if (ret.typeParameters!=null) { + StringBuffer sigAddition = new StringBuffer(); + sigAddition.append("<"); + for (int i = 0; i < ret.typeParameters.length; i++) { + sigAddition.append(ret.typeParameters[i].signature); + } + sigAddition.append(">"); + sigAddition.append(";"); + ret.signature = ret.signature.substring(0,ret.signature.length()-1) + sigAddition.toString(); } - sigAddition.append(">"); - sigAddition.append(";"); - ret.signature = ret.signature.substring(0,ret.signature.length()-1) + sigAddition.toString(); return ret; } public static TypeX forRawTypeNames(String name) { TypeX ret = TypeX.forName(name); ret.setParameterized(true); + ret.setRawtype(true); // FIXME asc no need to mess up the signature is there? // ret.signature = ret.signature+"#RAW"; return ret; @@ -324,7 +333,10 @@ public class TypeX implements AnnotatedElement { String name = getName(); if (isParameterized()) { if (isRawType()) return name; - else return name.substring(0,name.indexOf("<")); + else { + if (typeParameters==null) return name; + else return name.substring(0,name.indexOf("<")); + } } else { return name; } @@ -387,23 +399,24 @@ public class TypeX implements AnnotatedElement { return signature.startsWith("["); } - /** - * Determines if this represents a parameterized type. - */ public final boolean isParameterized() { return isParameterized; -// return signature.indexOf("<") != -1; -// //(typeParameters != null) && (typeParameters.length > 0); } public final boolean isRawType() { - return isParameterized && typeParameters==null; + return isRawtype; +// return isParameterized && typeParameters==null; } private final void setParameterized(boolean b) { isParameterized=b; } + private final void setRawtype(boolean b) { + isRawtype=b; + } + + /** * Returns a TypeX object representing the effective outermost enclosing type