From 4b5e76347445be5180616f5008e52328948b6cf5 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 3 Nov 2005 10:31:03 +0000 Subject: [PATCH] fix for latest variant of 114343 (see comment #5): around advice on method returning type variable. --- tests/bugs150/pr114343/case2/TTT.java | 11 ++++++++ tests/bugs150/pr114343/case2/Test.java | 11 ++++++++ tests/bugs150/pr114343/case2/TestAspect.java | 25 +++++++++++++++++++ .../systemtest/ajc150/Ajc150Tests.java | 1 + .../org/aspectj/systemtest/ajc150/ajc150.xml | 15 +++++++++++ .../src/org/aspectj/weaver/ReferenceType.java | 5 ++++ .../src/org/aspectj/weaver/ResolvedType.java | 9 ++++--- .../src/org/aspectj/weaver/TypeFactory.java | 6 +++++ weaver/src/org/aspectj/weaver/World.java | 12 ++++++--- 9 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 tests/bugs150/pr114343/case2/TTT.java create mode 100644 tests/bugs150/pr114343/case2/Test.java create mode 100644 tests/bugs150/pr114343/case2/TestAspect.java diff --git a/tests/bugs150/pr114343/case2/TTT.java b/tests/bugs150/pr114343/case2/TTT.java new file mode 100644 index 000000000..732e0d38e --- /dev/null +++ b/tests/bugs150/pr114343/case2/TTT.java @@ -0,0 +1,11 @@ +import java.util.*; + +public class TTT { + public void foo() { + System.err.println("Creating Test instance"); + Test mt = new Test(); + System.err.println("Calling toArray"); + Integer[] arr = mt.toArray(new Integer[]{}); + System.err.println("done"); + } +} diff --git a/tests/bugs150/pr114343/case2/Test.java b/tests/bugs150/pr114343/case2/Test.java new file mode 100644 index 000000000..758094997 --- /dev/null +++ b/tests/bugs150/pr114343/case2/Test.java @@ -0,0 +1,11 @@ +import java.util.*; + +public class Test { + + Set set = new HashSet(); + + public T[] toArray(T[] a) { + System.err.println("In toArray()"); + return set.toArray(a); + } +} diff --git a/tests/bugs150/pr114343/case2/TestAspect.java b/tests/bugs150/pr114343/case2/TestAspect.java new file mode 100644 index 000000000..fcc760ac7 --- /dev/null +++ b/tests/bugs150/pr114343/case2/TestAspect.java @@ -0,0 +1,25 @@ +import java.util.*; + +public privileged aspect TestAspect { + + pointcut TestToArray(Test mt) : + target(mt) && + !within(TestAspect); + + + Object[] around(Test mt, Object[] objs) : + TestToArray(mt) && + args(objs) && + execution(Object[] Test.toArray(Object[])) { + + System.err.println("In around advice"); + objs = proceed(mt, objs); + return objs; + } + + public static void main(String[] argv) { + System.err.println("TestAspect.main: Calling foo"); + new TTT().foo(); + System.err.println("TestAspect.main: done"); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 54677b88c..c3a77ad2e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -56,6 +56,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");} public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");} public void testFieldGet_pr114343() { runTest("field-get, generics and around advice");} + public void testFieldGet_pr114343_2() { runTest("field-get, generics and around advice - 2");} public void testCaptureBinding_pr114744() { runTest("capturebinding wildcard problem");} public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 852ccb981..8d10e7563 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -29,6 +29,21 @@ + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 111762cf2..f31cf2e96 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -288,6 +288,11 @@ public class ReferenceType extends ResolvedType { } } + if (isTypeVariableReference() && !other.isTypeVariableReference()) { // eg. this=T other=Ljava/lang/Object; + TypeVariable aVar = ((TypeVariableReference)this).getTypeVariable(); + return aVar.getFirstBound().resolve(world).isAssignableFrom(other); + } + if (other.isTypeVariableReference()) { TypeVariableReferenceType otherType = (TypeVariableReferenceType) other; if (this instanceof TypeVariableReference) { diff --git a/weaver/src/org/aspectj/weaver/ResolvedType.java b/weaver/src/org/aspectj/weaver/ResolvedType.java index b6683f724..464c1675c 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedType.java +++ b/weaver/src/org/aspectj/weaver/ResolvedType.java @@ -744,14 +744,17 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl // ---- types public static ResolvedType makeArray(ResolvedType type, int dim) { if (dim == 0) return type; - ResolvedType array = new Array("[" + type.getSignature(),type.getWorld(),type); + ResolvedType array = new Array("[" + type.getSignature(),"["+type.getErasureSignature(),type.getWorld(),type); return makeArray(array,dim-1); } static class Array extends ResolvedType { ResolvedType componentType; - Array(String s, World world, ResolvedType componentType) { - super(s, world); + + + // Sometimes the erasure is different, eg. [TT; and [Ljava/lang/Object; + Array(String sig, String erasureSig,World world, ResolvedType componentType) { + super(sig,erasureSig, world); this.componentType = componentType; } public final ResolvedMember[] getDeclaredFields() { diff --git a/weaver/src/org/aspectj/weaver/TypeFactory.java b/weaver/src/org/aspectj/weaver/TypeFactory.java index b921d0aad..eb6350b33 100644 --- a/weaver/src/org/aspectj/weaver/TypeFactory.java +++ b/weaver/src/org/aspectj/weaver/TypeFactory.java @@ -110,6 +110,12 @@ public class TypeFactory { typeVariableName = typeVariableName.substring(0, typeVariableName.length() -1); } return new UnresolvedTypeVariableReferenceType(new TypeVariable(typeVariableName)); + } else if (signature.startsWith("[")) { + int dims = 0; + while (signature.charAt(dims)=='[') dims++; + UnresolvedType componentType = createTypeFromSignature(signature.substring(dims)); + return new UnresolvedType(signature, + signature.substring(0,dims)+componentType.getErasureSignature()); } return new UnresolvedType(signature); } diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 423898524..29810f984 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -204,10 +204,11 @@ public abstract class World implements Dump.INode { // no existing resolved type, create one if (ty.isArray()) { - ret = new ResolvedType.Array(signature, + ResolvedType componentType = resolve(ty.getComponentType(),allowMissing); + String brackets = signature.substring(0,signature.lastIndexOf("[")+1); + ret = new ResolvedType.Array(signature, brackets+componentType.getErasureSignature(), this, - resolve(ty.getComponentType(), - allowMissing)); + componentType); } else { ret = resolveToReferenceType(ty); if (!allowMissing && ret == ResolvedType.MISSING) { @@ -264,7 +265,8 @@ public abstract class World implements Dump.INode { return resolve(UnresolvedType.forName(name),allowMissing); } - + private ResolvedType currentlyResolvingBaseType; + /** * Resolve to a ReferenceType - simple, raw, parameterized, or generic. * Raw, parameterized, and generic versions of a type share a delegate. @@ -273,8 +275,10 @@ public abstract class World implements Dump.INode { if (ty.isParameterizedType()) { // ======= parameterized types ================ ReferenceType genericType = (ReferenceType)resolveGenericTypeFor(ty,false); + currentlyResolvingBaseType = genericType; ReferenceType parameterizedType = TypeFactory.createParameterizedType(genericType, ty.typeParameters, this); + currentlyResolvingBaseType = null; return parameterizedType; } else if (ty.isGenericType()) { -- 2.39.5