]> source.dussan.org Git - aspectj.git/commitdiff
test cases and fix for Bugzilla Bug 81863
authoracolyer <acolyer>
Wed, 5 Jan 2005 15:15:28 +0000 (15:15 +0000)
committeracolyer <acolyer>
Wed, 5 Jan 2005 15:15:28 +0000 (15:15 +0000)
   Annotation matching using within() PCD doesn't appear to be working.

tests/java5/annotations/within/PlainWithin.jar [new file with mode: 0644]
tests/java5/annotations/within/PlainWithin.java
tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java
tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java
weaver/src/org/aspectj/weaver/patterns/AnnotationTypePattern.java
weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java
weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java
weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java
weaver/src/org/aspectj/weaver/patterns/TypePattern.java
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java
weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java

diff --git a/tests/java5/annotations/within/PlainWithin.jar b/tests/java5/annotations/within/PlainWithin.jar
new file mode 100644 (file)
index 0000000..d541167
Binary files /dev/null and b/tests/java5/annotations/within/PlainWithin.jar differ
index e19368cb20fc24e5bc1bf158c0a914417f4cd50b..ac541dbaa8519656a3de459e15447f69df336855 100644 (file)
@@ -15,7 +15,7 @@
  * TODO To change the template for this generated type comment go to
  * Window - Preferences - Java - Code Generation - Code and Comments
  */
-@MyClassRetententionAnnotation
+@MyAnnotation
 public class PlainWithin {
 
     public void foo() {}
index 54bc08ffcaed05112b237fd306523f081fc49fc4..cc75ea350ca188aac911165444d913ab56ebc65a 100644 (file)
@@ -46,10 +46,30 @@ public class AnnotationPointcutsTests extends TestUtils {
       assertMessages(cR, new MessageSpec(expectedWarnings, new ArrayList()));
   }
   
+  public void test003_Within_Code() {
+       baseDir = new File("../tests/java5/annotations/within_code");
+      CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5);
+      List warnings = new ArrayList();
+      warnings.add(new Message(32,"@within match on non-inherited annotation"));
+      warnings.add(new Message(39,"@within match on non-inherited annotation"));
+      warnings.add(new Message(39,"@within match on inheritable annotation"));
+      warnings.add(new Message(43,"@within match on inheritable annotation"));
+      warnings.add(new Message(32,"@withincode match"));
+      MessageSpec mSpec = new MessageSpec(warnings,new ArrayList());
+      assertMessages(cR,mSpec);        
+  }
+  
+  public void test004_Within() {
+       baseDir = new File("../tests/java5/annotations/within");
+        CompilationResult cR = binaryWeave("PlainWithin.jar","PlainWithinTests.java",0,2);
+        List warnings = new ArrayList();
+        warnings.add(new Message(21,"positive within match on annotation"));
+        warnings.add(new Message(25,"negative within match on annotation"));
+        MessageSpec mSpec = new MessageSpec(warnings,new ArrayList());
+        assertMessages(cR,mSpec);      
+    }
   
   // TODO extra tests
-  // 1) @within  (matches, does not match, matches inherited annotation)
-  // 2) @withincode (matches, does not match)
   // 3) @annotation on the different join point kinds, matches with inherited annotation
   
 }
\ No newline at end of file
index 53b43299c77c4cd50ce7272a651a628b64955d7c..b59f214235940e6bac9f5f5d9d47bb7bef596745 100644 (file)
@@ -75,16 +75,4 @@ public class AnnotationRuntimeTests extends TestUtils {
         assertMessages(cR, messageSpec);
     }
 
-    public void test007_Within_Code() {
-       baseDir = new File("../tests/java5/annotations/within_code");
-        CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5);
-        List warnings = new ArrayList();
-        warnings.add(new Message(32,"@within match on non-inherited annotation"));
-        warnings.add(new Message(39,"@within match on non-inherited annotation"));
-        warnings.add(new Message(39,"@within match on inheritable annotation"));
-        warnings.add(new Message(43,"@within match on inheritable annotation"));
-        warnings.add(new Message(32,"@withincode match"));
-        MessageSpec mSpec = new MessageSpec(warnings,new ArrayList());
-        assertMessages(cR,mSpec);      
-    }
 }
index 1a4a34d18d93f3c9875c862ed3f4ae927f2ec1d6..df5952b72e683e4041ed3feaede2e7932a1b2482 100644 (file)
@@ -83,6 +83,10 @@ public abstract class AnnotationTypePattern extends PatternNode {
 
 class AnyAnnotationTypePattern extends AnnotationTypePattern {
 
+    public FuzzyBoolean fastMatches(AnnotatedElement annotated) {
+        return FuzzyBoolean.YES;
+    }
+    
        public FuzzyBoolean matches(AnnotatedElement annotated) {
                return FuzzyBoolean.YES;
        }
index 51ac632c679610986843691c5e685c8e4ed97967..61b1eaa13b389fbdf8e918450818547a9c80647c 100644 (file)
@@ -81,7 +81,8 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern {
 
        
        public void resolve(World world) {
-               annotationType = annotationType.resolve(world);
+               if (!resolved) annotationType = annotationType.resolve(world);
+               resolved = true;
        }
 
        /* (non-Javadoc)
index 864a896da99adeaf125bc4b8a7c0af9c75c06d1d..2f150d3f473e3206c0166fae888bd4d2e956e209 100644 (file)
@@ -89,17 +89,20 @@ public class ExactTypePattern extends TypePattern {
        }
        
        protected boolean matchesExactly(ResolvedTypeX matchType) {
-               return this.type.equals(matchType);
+               boolean typeMatch = this.type.equals(matchType);
+               boolean annMatch = this.annotationPattern.matches(matchType).alwaysTrue();
+               return (typeMatch && annMatch);
        }
        
        public TypeX getType() { return type; }
 
        public FuzzyBoolean matchesInstanceof(ResolvedTypeX matchType) {
                // in our world, Object is assignable from anything
-               if (type.equals(ResolvedTypeX.OBJECT)) return FuzzyBoolean.YES;
+               if (type.equals(ResolvedTypeX.OBJECT)) 
+                   return FuzzyBoolean.YES.and(annotationPattern.matches(matchType));
                
                if (type.isAssignableFrom(matchType, matchType.getWorld())) {
-                       return FuzzyBoolean.YES;
+                       return FuzzyBoolean.YES.and(annotationPattern.matches(matchType));
                }
                
                // fix for PR 64262 - shouldn't try to coerce primitives
index f27f1f81d3ad1a80138e2c3c5fa3eeb15f324e26..398763788bb6f7782643980a56053a1a48444ead 100644 (file)
@@ -61,6 +61,8 @@ public class HandlerPointcut extends Pointcut {
        protected FuzzyBoolean matchInternal(Shadow shadow) {
                if (shadow.getKind() != Shadow.ExceptionHandler) return FuzzyBoolean.NO;
                
+               exceptionType.resolve(shadow.getIWorld());
+               
                // we know we have exactly one parameter since we're checking an exception handler
                return exceptionType.matches(
                                shadow.getSignature().getParameterTypes()[0].resolve(shadow.getIWorld()), 
index a0c42e19e58c3cd6d398713d12816ad9ff3340b3..2563731982ada25f514f7ddb5be2a06a72a657ee 100644 (file)
@@ -26,6 +26,7 @@ import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.ResolvedTypeX;
 import org.aspectj.weaver.TypeX;
 import org.aspectj.weaver.WeaverMessages;
+import org.aspectj.weaver.World;
 /**
  *  On creation, type pattern only contains WildTypePattern nodes, not BindingType or ExactType. 
  * 
@@ -91,13 +92,15 @@ public abstract class TypePattern extends PatternNode {
                if (type == ResolvedTypeX.MISSING) return FuzzyBoolean.NO;
                
                if (kind == STATIC) {
-                       typeMatch = FuzzyBoolean.fromBoolean(matchesStatically(type));
-                       return typeMatch.and(annotationPattern.matches(type));
+//                     typeMatch = FuzzyBoolean.fromBoolean(matchesStatically(type));
+//                     return typeMatch.and(annotationPattern.matches(type));
+                   return FuzzyBoolean.fromBoolean(matchesStatically(type));
                } else if (kind == DYNAMIC) {
                        //System.err.println("matching: " + this + " with " + type);
-                       typeMatch = matchesInstanceof(type);
+//                     typeMatch = matchesInstanceof(type);
                        //System.err.println("    got: " + ret);
-                       return typeMatch.and(annotationPattern.matches(type));
+//                     return typeMatch.and(annotationPattern.matches(type));
+                   return matchesInstanceof(type);
                } else {
                        throw new IllegalArgumentException("kind must be DYNAMIC or STATIC");
                }
@@ -218,6 +221,10 @@ public abstract class TypePattern extends PatternNode {
        return this;
     }
     
+    public void resolve(World world) {
+        annotationPattern.resolve(world);
+    }
+    
        public void postRead(ResolvedTypeX enclosingType) {
        }
        
index 105d8aaca86f43206e45467973eedfa3f0281e38..d0cc882a659035a82b10a4f23affb2e535fa629e 100644 (file)
@@ -114,7 +114,8 @@ public class WildTypePattern extends TypePattern {
                
                //System.err.println("match: " + targetTypeName + ", " + knownMatches); //Arrays.asList(importedPrefixes));
                
-               return matchesExactlyByName(targetTypeName);
+               return matchesExactlyByName(targetTypeName) &&
+                      annotationPattern.matches(type).alwaysTrue();
        }
 
        /**
index f622b8088c53e3be883af5d07714d30338ad8cc7..96201d2037fae26582a448ee56f7cb6c20d76208 100644 (file)
@@ -42,7 +42,7 @@ public class WithinPointcut extends Pointcut {
        
        private FuzzyBoolean isWithinType(ResolvedTypeX type) {
                while (type != null) {
-                       if (typePattern.matchesStatically(type)) {
+                       if (typePattern.matchesStatically(type)) {                          
                                return FuzzyBoolean.YES;
                        }
                        type = type.getDeclaringType();
@@ -55,7 +55,10 @@ public class WithinPointcut extends Pointcut {
        }
        
        public FuzzyBoolean fastMatch(FastMatchInfo info) {
-               return isWithinType(info.getType());
+           if (typePattern.annotationPattern instanceof AnyAnnotationTypePattern) {
+               return isWithinType(info.getType());
+           }
+           return FuzzyBoolean.MAYBE;
        }
     
        protected FuzzyBoolean matchInternal(Shadow shadow) {
@@ -67,6 +70,7 @@ public class WithinPointcut extends Pointcut {
                                shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()});
                        shadow.getIWorld().getMessageHandler().handleMessage(msg);
                }
+               typePattern.resolve(shadow.getIWorld());
                return isWithinType(enclosingType);
        }