]> source.dussan.org Git - aspectj.git/commitdiff
Annotation matching.
authoraclement <aclement>
Wed, 8 Dec 2004 14:34:33 +0000 (14:34 +0000)
committeraclement <aclement>
Wed, 8 Dec 2004 14:34:33 +0000 (14:34 +0000)
13 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java
tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcuts.java
weaver/src/org/aspectj/weaver/AnnotatedElement.java
weaver/src/org/aspectj/weaver/Member.java
weaver/src/org/aspectj/weaver/ResolvedTypeX.java
weaver/src/org/aspectj/weaver/TypeX.java
weaver/src/org/aspectj/weaver/bcel/BcelField.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java
weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java

index 2efe987b8d1218983777c5e821d510c1a758e222..7a5207324c1d0f6021c9323770518be4e4d809be 100644 (file)
@@ -221,7 +221,7 @@ public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
                return (binding.getAccessFlags() & ACC_ANNOTATION)!=0;
        }
        
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                throw new RuntimeException("How to implement this?  Needs to ask eclipse!");
        }
        
index ec734bd87ee0f2137f94802d78034f87528ba2e1..f03ceef4f181c59039ed936e769cf0b95014b599 100644 (file)
@@ -29,6 +29,7 @@ public class AllTestsJava5_binaryWeaving {
                suite.addTestSuite(CovarianceTests.class);
                suite.addTestSuite(Enums.class);
                suite.addTestSuite(Annotations.class);
+               suite.addTestSuite(AnnotationPointcuts.class);
                suite.addTestSuite(Varargs.class);
                //$JUnit-END$
                return suite;
index dba69c367acef6bd84c4250dda5facd712dc7d46..58b41528e371019a067c6044ac28b00df44a8dad 100644 (file)
@@ -27,24 +27,28 @@ public class AnnotationPointcuts extends TestUtils {
   }
        
   // before(): call(@SimpleAnnotation * *(..)) { }
-//  public void test001_usingAnnotationsInPointcuts() {
-//     CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect02.aj",0,0);
-//     System.err.println(cR.getStandardError());
-//     System.err.println(cR.getErrorMessages());
-//     System.err.println(cR.getInfoMessages());
+  public void test001_usingAnnotationsInPointcuts() {
+       CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect02.aj",0,0);
+       System.err.println(cR.getStandardError());
+       System.err.println(cR.getErrorMessages());
+       System.err.println(cR.getInfoMessages());
+       verifyWeavingMessagesOutput(cR,new String[]{
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)",
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:2)",
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:4) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)"});
+  
+//     assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+
+//                     cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(),
+//                     cR.getErrorMessages().size()==3);
+//     IMessage msg1_ctor   = (IMessage)cR.getErrorMessages().get(0);
+//     IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1);
+//     IMessage msg3_field  = (IMessage)cR.getErrorMessages().get(2);
+//     assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor,
+//                     msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1);
+//     assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method,
+//                     msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1);
+//     assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field,
+//                     msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1);
 //     verifyWeavingMessagesOutput(cR,new String[]{});
-////   assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+
-////                   cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(),
-////                   cR.getErrorMessages().size()==3);
-////   IMessage msg1_ctor   = (IMessage)cR.getErrorMessages().get(0);
-////   IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1);
-////   IMessage msg3_field  = (IMessage)cR.getErrorMessages().get(2);
-////   assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor,
-////                   msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1);
-////   assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method,
-////                   msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1);
-////   assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field,
-////                   msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1);
-////   verifyWeavingMessagesOutput(cR,new String[]{});
-//  }
+  }
 }
\ No newline at end of file
index f83e551d0c41bdd16c9ded139269699d9e6d8073..445fda6b75f32675b8aec98bb8bda94114c61cbf 100644 (file)
@@ -13,7 +13,7 @@ package org.aspectj.weaver;
  * Represents any element that may have annotations
  */
 public interface AnnotatedElement {
-       boolean hasAnnotation(ResolvedTypeX ofType);
+       boolean hasAnnotation(TypeX ofType);
        
        ResolvedTypeX[] getAnnotationTypes();
        // SomeType getAnnotation(TypeX ofType);
index 9bd4fa7d4b078fb83db80dcf0cd767239b509ffe..eaf0c9217e70a3196310db3e35a1865e8adff1e4 100644 (file)
@@ -468,7 +468,7 @@ public class Member implements Comparable, AnnotatedElement {
      * If you want a sensible answer, resolve the member and call
      * hasAnnotation() on the ResolvedMember.
      */
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                throw new UnsupportedOperationException("You should resolve this member and call hasAnnotation() on the result...");
        }
        
index 413292468451da8fbffb5924ff5e5204faf9da29..7b9a60174acfb2d297c0be81b32bd3b436266009 100644 (file)
@@ -560,7 +560,7 @@ public abstract class ResolvedTypeX extends TypeX implements AnnotatedElement {
                return delegate.isClass();
            }
 
-           public boolean hasAnnotation(ResolvedTypeX ofType) {
+           public boolean hasAnnotation(TypeX ofType) {
                return delegate.hasAnnotation(ofType);
            }
            
@@ -725,7 +725,7 @@ public abstract class ResolvedTypeX extends TypeX implements AnnotatedElement {
            public abstract boolean isEnum();
            public abstract boolean isAnnotation();
            
-           public abstract boolean hasAnnotation(ResolvedTypeX ofType);
+           public abstract boolean hasAnnotation(TypeX ofType);
            public abstract ResolvedTypeX[] getAnnotationTypes();
 
                public abstract ResolvedMember[] getDeclaredFields();
@@ -801,7 +801,7 @@ public abstract class ResolvedTypeX extends TypeX implements AnnotatedElement {
             return ResolvedMember.NONE;
         }
         
-        public boolean hasAnnotation(ResolvedTypeX ofType) {
+        public boolean hasAnnotation(TypeX ofType) {
                return false;
         }
         
@@ -864,7 +864,7 @@ public abstract class ResolvedTypeX extends TypeX implements AnnotatedElement {
         public final boolean isPrimitive() {
             return true;
         }
-        public boolean hasAnnotation(ResolvedTypeX ofType) {
+        public boolean hasAnnotation(TypeX ofType) {
                return false;
         }
         public final boolean isAssignableFrom(TypeX other) {
@@ -941,7 +941,7 @@ public abstract class ResolvedTypeX extends TypeX implements AnnotatedElement {
         public final String getName() {
                return MISSING_NAME;
         }
-        public boolean hasAnnotation(ResolvedTypeX ofType) {
+        public boolean hasAnnotation(TypeX ofType) {
                return false;
         }
         public final ResolvedMember[] getDeclaredFields() {
index 020682322bb0e7eca02e95372ed45daf77c6d1f5..2cc7528f3616594dd939dcf2a04bd1287c2b7531 100644 (file)
@@ -552,7 +552,7 @@ public class TypeX implements AnnotatedElement {
                return world.resolve(this);
        }
 
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                throw new UnsupportedOperationException("You should resolve this member and call hasAnnotation() on the result...");
        }
 
index 57fe60b593db7acd570ec802ecd531baa33f1f27..230513585b1689268e977720e9eb2e41a714a64e 100644 (file)
@@ -79,7 +79,7 @@ final class BcelField extends ResolvedMember {
                return isSynthetic;
        }
        
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                Annotation[] anns = field.getAnnotations();
                for (int i = 0; i < anns.length; i++) {
                        Annotation annotation = anns[i];
index 360295c9279ad23058c9030298a5e221ca442161..006f9d6a05a708240c9242255ae165d0ece5f7e9 100644 (file)
@@ -141,7 +141,7 @@ final class BcelMethod extends ResolvedMember {
                }
        }
        
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                Annotation[] anns = method.getAnnotations();
                for (int i = 0; i < anns.length; i++) {
                        Annotation annotation = anns[i];
index 321480ddce0d3090e5f5cdde1ef6ac15d3b6f6cb..ce8a253b2c05ef6c9d91aa2f8a35b47552b60724 100644 (file)
@@ -323,7 +323,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
 
 
 
-       public boolean hasAnnotation(ResolvedTypeX ofType) {
+       public boolean hasAnnotation(TypeX ofType) {
                Annotation[] annotationsOnThisType = javaClass.getAnnotations();
                for (int i = 0; i < annotationsOnThisType.length; i++) {
                        Annotation a = annotationsOnThisType[i];
index 8017ec7575f46a2769e7e355612ec0f074db8e08..d1ff327d1ccc609abafb45011d12db71a7e0d30a 100644 (file)
@@ -49,10 +49,7 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern {
        }
        
        public FuzzyBoolean matches(AnnotatedElement annotated) {
-               if (!resolved) {
-                       throw new IllegalStateException("Can't match on an unresolved annotation type pattern");
-               }
-               return (annotated.hasAnnotation((ResolvedTypeX)annotationType) ?
+               return (annotated.hasAnnotation(annotationType) ?
                                   FuzzyBoolean.YES : FuzzyBoolean.NO);
        }
 
index 52b6b98a68b7564fd01ee7c8aa41013b39f03dd5..c3ea08e4d5c982ac07432f02a5f82db033d643a8 100644 (file)
@@ -327,7 +327,7 @@ public class AnnotationPatternTestCase extends TestCase {
                        this.annotationTypes = annotationTypes;
                }
                
-               public boolean hasAnnotation(ResolvedTypeX ofType) {
+               public boolean hasAnnotation(TypeX ofType) {
                        for (int i = 0; i < annotationTypes.length; i++) {
                                if (annotationTypes[i].equals(ofType.getName())) return true;
                        }
index bf14716679b6628db480f979cae1c13e4322efb0..1be5816904de252a2f4aa96e6fa94fd228976f84 100644 (file)
@@ -63,18 +63,20 @@ public class ParserTestCase extends TestCase {
        }
        
        public void testParseWithAnnotation() {
-               PatternParser parser = new PatternParser("execution(@p.SimpleAnnotation void Hello.*(..))");
+               PatternParser parser = new PatternParser("execution(@SimpleAnnotation void Hello.*(..))");
                KindedPointcut p = (KindedPointcut) parser.parsePointcut();
                // XXX - needs finishing...
-               // p.resolveBindings(makeSimpleScope(),new Bindings(3));
-//             System.err.println(p);
+               p.resolveBindings(makeSimpleScope(),new Bindings(3));
+               System.err.println(p);
 //             assertEquals(p.kind, BcelShadow.MethodExecution);
 //             assertTrue(p.signature.getName().matches("foobar"));
 //             p.signature.resolveBindings(makeSimpleScope(),new Bindings(3));         
        }
        
        public TestScope makeSimpleScope() {
-               return new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
+               TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
+               s.setImportedPrefixes(new String[]{"p."});
+               return s;
        }
 
 }