diff options
author | aclement <aclement> | 2004-12-08 14:15:42 +0000 |
---|---|---|
committer | aclement <aclement> | 2004-12-08 14:15:42 +0000 |
commit | 6e6d34c79638763ab180578dd169147fda5011cc (patch) | |
tree | b4a0def4960a386fe5d05c8209ba49419d402e79 /weaver/testsrc | |
parent | 4c20738fbb3560cccf1bc7e5bc0a21618c9559c7 (diff) | |
download | aspectj-6e6d34c79638763ab180578dd169147fda5011cc.tar.gz aspectj-6e6d34c79638763ab180578dd169147fda5011cc.zip |
Annotation matching.
Diffstat (limited to 'weaver/testsrc')
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java | 59 | ||||
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java | 23 |
2 files changed, 76 insertions, 6 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java index e525f8578..fba58dae0 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java @@ -11,15 +11,14 @@ * ******************************************************************/ package org.aspectj.weaver.patterns; -import java.util.List; import java.util.ArrayList; +import java.util.List; import junit.framework.TestCase; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHandler; -import org.aspectj.bridge.MessageHandler; import org.aspectj.bridge.IMessage.Kind; import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.ResolvedMember; @@ -186,5 +185,61 @@ public class AnnotationPatternMatchingTestCase extends TestCase { simpleAnnotationTP.matches(aField).alwaysTrue()); } + + public void testAnnotationTypeResolutionOnTypes() { + ResolvedTypeX rtx = loadType("AnnotatedClass"); + ResolvedTypeX[] types = rtx.getAnnotationTypes(); + assertTrue("Did not expect null",types!=null); + assertTrue("Expected 1 entry but got "+types.length,types.length==1); + assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], + types[0].equals(world.resolve("p.SimpleAnnotation"))); + } + + public void testAnnotationTypeResolutionOnMethods() { + ResolvedTypeX rtx = loadType("AnnotatedClass"); + + ResolvedMember aMethod = rtx.getDeclaredMethods()[1]; + assertTrue("Haven't got the right method, I'm looking for 'm1()': "+aMethod.getName(), + aMethod.getName().equals("m1")); + + ResolvedTypeX[] types = aMethod.getAnnotationTypes(); + assertTrue("Did not expect null",types!=null); + assertTrue("Expected 1 entry but got "+types.length,types.length==1); + assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], + types[0].equals(world.resolve("p.SimpleAnnotation"))); + } + + public void testAnnotationTypeResolutionOnFields() { + ResolvedTypeX rtx = loadType("AnnotatedClass"); + + ResolvedMember aField = rtx.getDeclaredFields()[0]; + + assertTrue("Haven't got the right field, I'm looking for 'i'"+aField.getName(), + aField.getName().equals("i")); + + ResolvedTypeX[] types = aField.getAnnotationTypes(); + assertTrue("Did not expect null",types!=null); + assertTrue("Expected 1 entry but got "+types.length,types.length==1); + assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], + types[0].equals(world.resolve("p.SimpleAnnotation"))); + } + + public void testWildPatternMatchingOnTypes() { + + ResolvedTypeX rtx = loadType("AnnotatedClass"); + initAnnotationTypePatterns(); + + // Let's create something wild + PatternParser p = new PatternParser("@Foo || @Boo"); + AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); + ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); + assertTrue("shouldnt match the type AnnotatedClass",ap.matches(rtx).alwaysFalse()); + + + p = new PatternParser("@p.SimpleAnnotation || @Boo"); + ap = p.maybeParseAnnotationPattern(); + ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); + assertTrue("should match the type AnnotatedClass",ap.matches(rtx).alwaysTrue()); + } } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java index 46475c3a6..bf1471667 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java @@ -15,6 +15,8 @@ package org.aspectj.weaver.patterns; import junit.framework.TestCase; +import org.aspectj.weaver.BcweaverTests; +import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.BcelShadow; import org.aspectj.weaver.bcel.BcelWorld; @@ -33,7 +35,7 @@ public class ParserTestCase extends TestCase { super(arg0); } - World world = new BcelWorld(); + World world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); public void testNamePatterns() { @@ -58,10 +60,23 @@ public class ParserTestCase extends TestCase { } catch (ParserException pe) { // good } - - - } + + public void testParseWithAnnotation() { + PatternParser parser = new PatternParser("execution(@p.SimpleAnnotation void Hello.*(..))"); + KindedPointcut p = (KindedPointcut) parser.parsePointcut(); + // XXX - needs finishing... + // 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); + } + } |