]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 124654: generic annotation matching..
authoraclement <aclement>
Mon, 23 Jan 2006 15:21:18 +0000 (15:21 +0000)
committeraclement <aclement>
Mon, 23 Jan 2006 15:21:18 +0000 (15:21 +0000)
tests/bugs151/pr124654/GenericAnnotation.java [new file with mode: 0644]
tests/bugs151/pr124654/TestSubAspect.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java

diff --git a/tests/bugs151/pr124654/GenericAnnotation.java b/tests/bugs151/pr124654/GenericAnnotation.java
new file mode 100644 (file)
index 0000000..1bb725b
--- /dev/null
@@ -0,0 +1,15 @@
+import java.lang.annotation.Annotation;
+
+public abstract aspect GenericAnnotation<A extends Annotation> {
+
+   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 (file)
index 0000000..4af2d30
--- /dev/null
@@ -0,0 +1,19 @@
+import java.lang.annotation.*;
+
+public aspect TestSubAspect extends GenericAnnotation<MyAnnotation> {
+
+  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");
+  }
+}
index 8b6e385d5232efe4928398cd1a38868fd8afd966..a163d396f5b5db3658a40858678e3cae554d3172 100644 (file)
@@ -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() {
index ccb251c10100b84c421ab59297da692724a63b97..c04af91749aa093563295f73878a83adf56dfb39 100644 (file)
           </stderr>
         </run>
     </ajc-test>
-
+    
+    <ajc-test dir="bugs151/pr124654" title="generic aspects and annotations">
+        <compile files="GenericAnnotation.java,TestSubAspect.java" options="-1.5"/>
+        <run class="TestSubAspect">
+          <stderr>
+            <line text="Reference pointcut advice. interface MyAnnotation"/>
+            <line text="Inlined pointcut advice. interface MyAnnotation"/>
+            <line text="run running"/>
+          </stderr>
+        </run>
+    </ajc-test>
 </suite>
\ No newline at end of file
index ae7b841cc792ac09a301b9b5df3ece63ac36ad16..bb2c6ba619a608912d4ba02d2241055c112ae327 100644 (file)
@@ -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;