diff options
author | aclement <aclement> | 2009-10-06 21:07:17 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-10-06 21:07:17 +0000 |
commit | 8808125e1f90ef9c7ca813858d291ecb973d651d (patch) | |
tree | 9d6a314a6a5568fd9d10de50a624fd99a82ac96e /weaver/testsrc | |
parent | d12d461249f35b2ecc5bbd233af38335bdd8ceb4 (diff) | |
download | aspectj-8808125e1f90ef9c7ca813858d291ecb973d651d.tar.gz aspectj-8808125e1f90ef9c7ca813858d291ecb973d651d.zip |
291523: annotation pattern parsing changes for (@a.b.c.Foo *)
Diffstat (limited to 'weaver/testsrc')
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java | 125 |
1 files changed, 43 insertions, 82 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java index 2e767b636..2d0820999 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java @@ -19,7 +19,6 @@ import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.bcel.BcelWorld; -import org.aspectj.weaver.patterns.TestScope; public class AnnotationPatternTestCase extends TestCase { @@ -27,29 +26,21 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("@Foo"); AnnotationTypePattern foo = p.maybeParseAnnotationPattern(); foo = foo.resolveBindings(makeSimpleScope(), new Bindings(3), true); - assertTrue("ExactAnnotationTypePattern", - foo instanceof ExactAnnotationTypePattern); - assertEquals("Foo", UnresolvedType.forSignature("LFoo;"), - ((ExactAnnotationTypePattern) foo).annotationType); + assertTrue("ExactAnnotationTypePattern", foo instanceof ExactAnnotationTypePattern); + assertEquals("Foo", UnresolvedType.forSignature("LFoo;"), ((ExactAnnotationTypePattern) foo).annotationType); } public void testParseAndAnnotationPattern() { PatternParser p = new PatternParser("@Foo @Goo"); AnnotationTypePattern fooAndGoo = p.maybeParseAnnotationPattern(); - assertTrue("AndAnnotationTypePattern", - fooAndGoo instanceof AndAnnotationTypePattern); + assertTrue("AndAnnotationTypePattern", fooAndGoo instanceof AndAnnotationTypePattern); assertEquals("@(Foo) @(Goo)", fooAndGoo.toString()); - fooAndGoo = fooAndGoo.resolveBindings(makeSimpleScope(), - new Bindings(3), true); + fooAndGoo = fooAndGoo.resolveBindings(makeSimpleScope(), new Bindings(3), true); assertEquals("@Foo @Goo", fooAndGoo.toString()); - AnnotationTypePattern left = ((AndAnnotationTypePattern) fooAndGoo) - .getLeft(); - AnnotationTypePattern right = ((AndAnnotationTypePattern) fooAndGoo) - .getRight(); - assertEquals("Foo", UnresolvedType.forSignature("LFoo;"), - ((ExactAnnotationTypePattern) left).annotationType); - assertEquals("Goo", UnresolvedType.forSignature("LGoo;"), - ((ExactAnnotationTypePattern) right).annotationType); + AnnotationTypePattern left = ((AndAnnotationTypePattern) fooAndGoo).getLeft(); + AnnotationTypePattern right = ((AndAnnotationTypePattern) fooAndGoo).getRight(); + assertEquals("Foo", UnresolvedType.forSignature("LFoo;"), ((ExactAnnotationTypePattern) left).annotationType); + assertEquals("Goo", UnresolvedType.forSignature("LGoo;"), ((ExactAnnotationTypePattern) right).annotationType); } // @@ -72,15 +63,11 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseNotAnnotationPattern() { PatternParser p = new PatternParser("!@Foo"); AnnotationTypePattern notFoo = p.maybeParseAnnotationPattern(); - assertTrue("NotAnnotationTypePattern", - notFoo instanceof NotAnnotationTypePattern); - notFoo = notFoo.resolveBindings(makeSimpleScope(), new Bindings(3), - true); + assertTrue("NotAnnotationTypePattern", notFoo instanceof NotAnnotationTypePattern); + notFoo = notFoo.resolveBindings(makeSimpleScope(), new Bindings(3), true); assertEquals("!@Foo", notFoo.toString()); - AnnotationTypePattern body = ((NotAnnotationTypePattern) notFoo) - .getNegatedPattern(); - assertEquals("Foo", UnresolvedType.forName("Foo"), - ((ExactAnnotationTypePattern) body).annotationType); + AnnotationTypePattern body = ((NotAnnotationTypePattern) notFoo).getNegatedPattern(); + assertEquals("Foo", UnresolvedType.forName("Foo"), ((ExactAnnotationTypePattern) body).annotationType); } public void testParseBracketedAnnotationPattern() { @@ -102,8 +89,7 @@ public class AnnotationPatternTestCase extends TestCase { AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); AndAnnotationTypePattern atp = (AndAnnotationTypePattern) ap; - NotAnnotationTypePattern notBoo = (NotAnnotationTypePattern) atp - .getRight(); + NotAnnotationTypePattern notBoo = (NotAnnotationTypePattern) atp.getRight(); // ExactAnnotationTypePattern boo = (ExactAnnotationTypePattern) notBoo.getNegatedPattern(); // AnnotationTypePattern fooOrGoo = (AnnotationTypePattern) @@ -138,8 +124,7 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("Foo"); AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern(); assertTrue("ExactAnnotationTypePattern expected", foo != null); - assertEquals("Foo", UnresolvedType.forName("Foo"), - ((ExactAnnotationTypePattern) foo).annotationType); + assertEquals("Foo", UnresolvedType.forName("Foo"), ((ExactAnnotationTypePattern) foo).annotationType); } public void testParseNameOrVarAnnotationPatternWithNot() { @@ -157,17 +142,14 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("Foo || Boo"); AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern(); // rest of pattern not consumed... - assertTrue("ExactAnnotationTypePattern", - foo instanceof ExactAnnotationTypePattern); - assertEquals("Foo", UnresolvedType.forName("Foo"), - ((ExactAnnotationTypePattern) foo).annotationType); + assertTrue("ExactAnnotationTypePattern", foo instanceof ExactAnnotationTypePattern); + assertEquals("Foo", UnresolvedType.forName("Foo"), ((ExactAnnotationTypePattern) foo).annotationType); } public void testParseNameOrVarAnnotationWithBinding() { PatternParser p = new PatternParser("foo"); AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern(); - assertTrue("ExactAnnotationTypePattern", - foo instanceof ExactAnnotationTypePattern); + assertTrue("ExactAnnotationTypePattern", foo instanceof ExactAnnotationTypePattern); assertEquals("@foo", ((ExactAnnotationTypePattern) foo).toString()); } @@ -184,14 +166,13 @@ public class AnnotationPatternTestCase extends TestCase { assertNotNull("Should find annotation pattern", a); p = new PatternParser("Foo && Boo"); a = p.maybeParseAnnotationPattern(); - assertEquals("Should be ANY pattern for a non-match", - AnnotationTypePattern.ANY, a); + assertEquals("Should be ANY pattern for a non-match", AnnotationTypePattern.ANY, a); } public void testParseTypePatternsWithAnnotations() { PatternParser p = new PatternParser("@Foo *"); TypePattern t = p.parseTypePattern(); - assertTrue("WildTypePattern", t instanceof WildTypePattern); + assertTrue("AnyWithAnnotationTypePattern", t instanceof AnyWithAnnotationTypePattern); AnnotationTypePattern atp = t.annotationPattern; assertEquals("@(Foo)", atp.toString()); assertEquals("(@(Foo) *)", t.toString()); @@ -201,8 +182,7 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("(@(Foo || Boo) (Foo || Boo))"); TypePattern t = p.parseTypePattern(); assertTrue("OrTypePattern", t instanceof OrTypePattern); - assertEquals("((@((Foo || Boo)) Foo) || (@((Foo || Boo)) Boo))", t - .toString()); + assertEquals("((@((Foo || Boo)) Foo) || (@((Foo || Boo)) Boo))", t.toString()); } public void testNotSyntax() { @@ -215,8 +195,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseMethodOrConstructorSigNoAP() { PatternParser p = new PatternParser("* *.*(..)"); SignaturePattern s = p.parseMethodOrConstructorSignaturePattern(); - assertEquals("Any annotation", AnnotationTypePattern.ANY, s - .getAnnotationPattern()); + assertEquals("Any annotation", AnnotationTypePattern.ANY, s.getAnnotationPattern()); assertEquals("Any return", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -226,8 +205,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseMethodOrConstructorSigSimpleAP() { PatternParser p = new PatternParser("@Foo * *.*(..)"); SignaturePattern s = p.parseMethodOrConstructorSignaturePattern(); - assertEquals("@(Foo) annotation", "@(Foo)", s.getAnnotationPattern() - .toString()); + assertEquals("@(Foo) annotation", "@(Foo)", s.getAnnotationPattern().toString()); assertEquals("Any return", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -237,8 +215,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseMethodOrConstructorSigComplexAP() { PatternParser p = new PatternParser("!@(Foo || Goo) * *.*(..)"); SignaturePattern s = p.parseMethodOrConstructorSignaturePattern(); - assertEquals("complex annotation", "!@((Foo || Goo))", s - .getAnnotationPattern().toString()); + assertEquals("complex annotation", "!@((Foo || Goo))", s.getAnnotationPattern().toString()); assertEquals("Any return", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -248,8 +225,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseMethodFieldSigNoAP() { PatternParser p = new PatternParser("* *.*"); SignaturePattern s = p.parseFieldSignaturePattern(); - assertEquals("Any annotation", AnnotationTypePattern.ANY, s - .getAnnotationPattern()); + assertEquals("Any annotation", AnnotationTypePattern.ANY, s.getAnnotationPattern()); assertEquals("Any field type", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -259,8 +235,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseFieldSigSimpleAP() { PatternParser p = new PatternParser("@Foo * *.*"); SignaturePattern s = p.parseFieldSignaturePattern(); - assertEquals("@Foo annotation", "@(Foo)", s.getAnnotationPattern() - .toString()); + assertEquals("@Foo annotation", "@(Foo)", s.getAnnotationPattern().toString()); assertEquals("Any field type", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -270,8 +245,7 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseFieldSigComplexAP() { PatternParser p = new PatternParser("!@(Foo || Goo) * *.*"); SignaturePattern s = p.parseFieldSignaturePattern(); - assertEquals("complex annotation", "!@((Foo || Goo))", s - .getAnnotationPattern().toString()); + assertEquals("complex annotation", "!@((Foo || Goo))", s.getAnnotationPattern().toString()); assertEquals("Any field type", "*", s.getReturnType().toString()); assertEquals("Any dec type", "*", s.getDeclaringType().toString()); assertEquals("Any name", "*", s.getName().toString()); @@ -283,13 +257,10 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("@Foo"); AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); - AnnotatedElementImpl ae = new AnnotatedElementImpl( - new String[] { "Foo" }); + AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { "Foo" }); assertTrue("matches element with Foo", ap.matches(ae).alwaysTrue()); - AnnotatedElementImpl ae2 = new AnnotatedElementImpl( - new String[] { "Boo" }); - assertTrue("does not match element with Boo", ap.matches(ae2) - .alwaysFalse()); + AnnotatedElementImpl ae2 = new AnnotatedElementImpl(new String[] { "Boo" }); + assertTrue("does not match element with Boo", ap.matches(ae2).alwaysFalse()); } } @@ -298,17 +269,14 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("foo"); AnnotationTypePattern ap = p.parseAnnotationNameOrVarTypePattern(); try { - ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), - true); + ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); } catch (AbortException abEx) { - assertEquals( - "Binding not supported in @pcds (1.5.0 M1 limitation): null", - abEx.getMessage()); + assertEquals("Binding not supported in @pcds (1.5.0 M1 limitation): null", abEx.getMessage()); } // uncomment these next lines once binding is supported // AnnotatedElementImpl ae = new AnnotatedElementImpl(new // String[]{"Foo"}); - //assertTrue("matches element with Foo",ap.matches(ae).alwaysTrue()) + // assertTrue("matches element with Foo",ap.matches(ae).alwaysTrue()) // ; // AnnotatedElementImpl ae2 = new AnnotatedElementImpl(new // String[]{"Boo"}); @@ -322,8 +290,7 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("@Foo @Boo"); AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); - AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { - "Foo", "Boo" }); + AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { "Foo", "Boo" }); assertTrue("matches foo and boo", ap.matches(ae).alwaysTrue()); ae = new AnnotatedElementImpl(new String[] { "Foo" }); assertTrue("does not match foo", ap.matches(ae).alwaysFalse()); @@ -355,32 +322,25 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("!@Foo"); AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); - AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { - "Foo", "Boo" }); - assertTrue("does not match foo and boo", ap.matches(ae) - .alwaysFalse()); + AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { "Foo", "Boo" }); + assertTrue("does not match foo and boo", ap.matches(ae).alwaysFalse()); ae = new AnnotatedElementImpl(new String[] { "Boo" }); assertTrue("matches boo", ap.matches(ae).alwaysTrue()); } } public void testAnyAnnotationPatternMatching() { - AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { - "Foo", "Boo" }); - assertTrue("always matches", AnnotationTypePattern.ANY.matches(ae) - .alwaysTrue()); + AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] { "Foo", "Boo" }); + assertTrue("always matches", AnnotationTypePattern.ANY.matches(ae).alwaysTrue()); ae = new AnnotatedElementImpl(new String[] {}); - assertTrue("always matches", AnnotationTypePattern.ANY.matches(ae) - .alwaysTrue()); + assertTrue("always matches", AnnotationTypePattern.ANY.matches(ae).alwaysTrue()); } public TestScope makeSimpleScope() { - BcelWorld bWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH - + "/testcode.jar"); // testcode contains Foo/Boo/Goo/etc + BcelWorld bWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); // testcode contains Foo/Boo/Goo/etc bWorld.setBehaveInJava5Way(true); - return new TestScope(new String[] { "int", "java.lang.String", "Foo", - "Boo", "Goo" }, new String[] { "a", "b", "foo", "boo", "goo" }, - bWorld); + return new TestScope(new String[] { "int", "java.lang.String", "Foo", "Boo", "Goo" }, new String[] { "a", "b", "foo", + "boo", "goo" }, bWorld); } // put test cases for AnnotationPatternList matching in separate test @@ -396,8 +356,9 @@ public class AnnotationPatternTestCase extends TestCase { public boolean hasAnnotation(UnresolvedType ofType) { for (int i = 0; i < annotationTypes.length; i++) { - if (annotationTypes[i].equals(ofType.getName())) + if (annotationTypes[i].equals(ofType.getName())) { return true; + } } return false; } |