From: aclement Date: Mon, 23 Jan 2006 15:21:18 +0000 (+0000) Subject: test and fix for 124654: generic annotation matching.. X-Git-Tag: POST_MEMORY_CHANGES~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=28f8c695ccc8513e9dcbe0c4fb6ebdc71cf84313;p=aspectj.git test and fix for 124654: generic annotation matching.. --- diff --git a/tests/bugs151/pr124654/GenericAnnotation.java b/tests/bugs151/pr124654/GenericAnnotation.java new file mode 100644 index 000000000..1bb725b55 --- /dev/null +++ b/tests/bugs151/pr124654/GenericAnnotation.java @@ -0,0 +1,15 @@ +import java.lang.annotation.Annotation; + +public abstract aspect GenericAnnotation { + + pointcut annotatedCall(A a) : call(@A * *.*(..)) && @annotation(a); + + before(A a) : annotatedCall(a) { + System.err.println("Reference pointcut advice. "+a.annotationType()); + } + + before(A a) : call(@A * *.*(..)) && @annotation(a) { + System.err.println("Inlined pointcut advice. "+a.annotationType()); + } + +} diff --git a/tests/bugs151/pr124654/TestSubAspect.java b/tests/bugs151/pr124654/TestSubAspect.java new file mode 100644 index 000000000..4af2d303f --- /dev/null +++ b/tests/bugs151/pr124654/TestSubAspect.java @@ -0,0 +1,19 @@ +import java.lang.annotation.*; + +public aspect TestSubAspect extends GenericAnnotation { + + public static void main(String []argv) { + new BasicType().run(); + } +} + +@Retention(RetentionPolicy.RUNTIME) +@interface MyAnnotation {} + + +class BasicType { + @MyAnnotation + public void run() { + System.err.println("run running"); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index 8b6e385d5..a163d396f 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -25,6 +25,7 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { 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 void testParameterizedCollectionFieldMatching_pr124808() { runTest("parameterized collection fields matched via pointcut");} + public void testGenericAspectsAndAnnotations_pr124654() { runTest("generic aspects and annotations");} ///////////////////////////////////////// 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 ccb251c10..c04af9174 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -53,5 +53,15 @@ - + + + + + + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java index ae7b841cc..bb2c6ba61 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java @@ -30,6 +30,7 @@ import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.TypeVariable; +import org.aspectj.weaver.TypeVariableReference; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.WeaverMessages; @@ -223,9 +224,17 @@ public class ReferencePointcut extends Pointcut { "bad parameter to pointcut reference"); return; } - if (!p.matchesSubtypes(parameterTypes[i]) && - !p.getExactType().equals(UnresolvedType.OBJECT)) - { + + boolean reportProblem = false; + if (parameterTypes[i].isTypeVariableReference() && p.getExactType().isTypeVariableReference()) { + UnresolvedType One = ((TypeVariableReference)parameterTypes[i]).getTypeVariable().getFirstBound(); + UnresolvedType Two = ((TypeVariableReference)p.getExactType()).getTypeVariable().getFirstBound(); + reportProblem = !One.resolve(scope.getWorld()).isAssignableFrom(Two.resolve(scope.getWorld())); + } else { + reportProblem = !p.matchesSubtypes(parameterTypes[i]) && + !p.getExactType().equals(UnresolvedType.OBJECT); + } + if (reportProblem) { scope.message(IMessage.ERROR, p, "incompatible type, expected " + parameterTypes[i].getName() + " found " + p +". Check the type specified in your pointcut"); return;