From: aclement Date: Mon, 23 Jan 2006 10:47:29 +0000 (+0000) Subject: test and fix for pr124803 - mixing numbers of tvars/tparams in a hierarchy X-Git-Tag: POST_MEMORY_CHANGES~161 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8676df9bca4e5e169206f314c8ad5d3da38bc28e;p=aspectj.git test and fix for pr124803 - mixing numbers of tvars/tparams in a hierarchy --- diff --git a/tests/bugs151/pr124803/Test.java b/tests/bugs151/pr124803/Test.java new file mode 100644 index 000000000..5c4784cac --- /dev/null +++ b/tests/bugs151/pr124803/Test.java @@ -0,0 +1,19 @@ +interface Generic1 { + public void foo(T p); +} + + +interface Generic2 extends Generic1 { + public void foo2(Y p); +} + +public class Test implements Generic2{ + public void foo2(Y p) { } + public void foo(Y p) { } + + public static void main(String []argv) { + Test t = new Test(); + t.foo(7); + t.foo2(9); + } +} diff --git a/tests/bugs151/pr124803/Test2.java b/tests/bugs151/pr124803/Test2.java new file mode 100644 index 000000000..58a364573 --- /dev/null +++ b/tests/bugs151/pr124803/Test2.java @@ -0,0 +1,19 @@ +class Generic1 { + public void foo(T p) { } +} + + +class Generic2 extends Generic1 { + public void foo2(Y p) {} +} + +public class Test2 extends Generic2{ + public void foo2(Y p) { } + public void foo(Y p) { } + + public static void main(String []argv) { + Test2 t = new Test2(); + t.foo(7); + t.foo2(9); + } +} diff --git a/tests/bugs151/pr124803/TestAspect.java b/tests/bugs151/pr124803/TestAspect.java new file mode 100644 index 000000000..c22b8f966 --- /dev/null +++ b/tests/bugs151/pr124803/TestAspect.java @@ -0,0 +1,8 @@ +public privileged aspect TestAspect { + pointcut TestInheritance(Test test) : target(test) && execution (* Generic1.*(..)); + + after (Test test) : TestInheritance(test) { + System.err.println("Aspects:"+thisJoinPoint); + } +} + diff --git a/tests/bugs151/pr124803/TestAspect2.java b/tests/bugs151/pr124803/TestAspect2.java new file mode 100644 index 000000000..62d7ab513 --- /dev/null +++ b/tests/bugs151/pr124803/TestAspect2.java @@ -0,0 +1,8 @@ +public privileged aspect TestAspect2 { + pointcut TestInheritance(Test2 test) : target(test) && execution (* Generic1.*(..)); + + after (Test2 test) : TestInheritance(test) { + System.err.println("Aspects:"+thisJoinPoint); + } +} + diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index 6bf01d7f3..396f2ed85 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -22,6 +22,8 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testMemberTypesInGenericTypes_pr122458_2() { runTest("member types in generic types - 2");} public void testNPEOnDeclareAnnotation_pr123695() { runTest("Internal nullptr exception with complex declare annotation");} public void testHasMemberPackageProblem_pr124105() { runTest("hasMember problems with packages");} + public void testDifferentNumbersofTVars_pr124803() { runTest("generics and different numbers of type variables");} + public void testDifferentNumbersofTVars_pr124803_2() { runTest("generics and different numbers of type variables - classes");} ///////////////////////////////////////// public static Test suite() { diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index 4fb00ce91..5c578a1d6 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -22,5 +22,27 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 9a3b4df98..907d46a12 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -386,7 +386,28 @@ public class ReferenceType extends ResolvedType { UnresolvedType[] paramTypes = getTypesForMemberParameterization(); parameterizedInterfaces = new ResolvedType[delegateInterfaces.length]; for (int i = 0; i < delegateInterfaces.length; i++) { - parameterizedInterfaces[i] = delegateInterfaces[i].parameterizedWith(paramTypes); + // We may have to subset the set of parametertypes if the implemented interface + // needs less than this type does. (pr124803) + + // wonder if this could be done with getMemberParameterizationMap() like it is in getSuperclass()?? Something like: +// parameterizedInterfaces[i] = delegateInterfaces[i].parameterize(getMemberParameterizationMap()).resolve(world); + TypeVariable[] tvarsOnImplementedInterface = delegateInterfaces[i].getTypeVariables(); + TypeVariable[] tvarsOnThisGenericType = this.genericType.getTypeVariables(); + ResolvedType parameterizedInterface = null; + if (tvarsOnImplementedInterface!=null && tvarsOnThisGenericType!=null) { + if (tvarsOnImplementedInterface.length' where thisGenericType is something like 'Generic' + // we need to subset the type parameters based on their name + UnresolvedType[] subsetParameterTypes = new ResolvedType[tvarsOnImplementedInterface.length]; + for (int j = 0; j < subsetParameterTypes.length; j++) { + subsetParameterTypes[j] = findTypeParameterInList(tvarsOnImplementedInterface[j].getName(),tvarsOnThisGenericType,paramTypes); + } + parameterizedInterface = delegateInterfaces[i].parameterizedWith(subsetParameterTypes); + } + } + if (parameterizedInterface==null) parameterizedInterface = delegateInterfaces[i].parameterizedWith(paramTypes); + + parameterizedInterfaces[i] = parameterizedInterface; } return parameterizedInterfaces; } else if (isRawType()){ @@ -410,6 +431,21 @@ public class ReferenceType extends ResolvedType { return delegate.getDeclaredInterfaces(); } + /** + * Locates the named type variable in the list of those on this generic type and returns + * the type parameter from the second list supplied. Returns null if it can't be found + */ + private UnresolvedType findTypeParameterInList(String name, TypeVariable[] tvarsOnThisGenericType, UnresolvedType[] paramTypes) { + int position = -1; + for (int i = 0; i < tvarsOnThisGenericType.length; i++) { + TypeVariable tv = tvarsOnThisGenericType[i]; + if (tv.getName().equals(name)) position = i; + } + if (position == -1 ) return null; + return paramTypes[position]; + } + + /** * It is possible this type has multiple type variables but the interface we are about to parameterize * only uses a subset - this method determines the subset to use by looking at the type variable names