From: acolyer Date: Wed, 8 Dec 2004 12:46:09 +0000 (+0000) Subject: updated test cases to reflect new parsing X-Git-Tag: Root_AspectJ5_Development~184 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76448059470c526c9ac8f06a43b08a7b997fa71b;p=aspectj.git updated test cases to reflect new parsing --- diff --git a/weaver/src/org/aspectj/weaver/patterns/AndAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/AndAnnotationTypePattern.java index c6679a980..af9511b1a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AndAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/AndAnnotationTypePattern.java @@ -77,7 +77,7 @@ public class AndAnnotationTypePattern extends AnnotationTypePattern { } public String toString() { - return "(" + left.toString() + " && " + right.toString() + ")"; + return left.toString() + " " + right.toString(); } public AnnotationTypePattern getLeft() { return left; } diff --git a/weaver/src/org/aspectj/weaver/patterns/AndTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/AndTypePattern.java index 0752746fc..15b705407 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AndTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/AndTypePattern.java @@ -100,9 +100,6 @@ public class AndTypePattern extends TypePattern { StringBuffer buff = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { buff.append('('); - if (! (annotationPattern instanceof ExactAnnotationTypePattern )) { - buff.append('@'); - } buff.append(annotationPattern.toString()); buff.append(' '); } diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java index 8d7bc8d5a..8017ec757 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java @@ -76,7 +76,7 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { "name binding only allowed in @pcds, args, this, and target"); return this; } - + verifyIsAnnotationType(formalBinding.getType(),scope); BindingAnnotationTypePattern binding = new BindingAnnotationTypePattern(formalBinding); binding.copyLocationFrom(this); bindings.register(binding, scope); @@ -89,17 +89,24 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { } } else { annotationType = annotationType.resolve(scope.getWorld()); - if (!annotationType.isAnnotation(scope.getWorld())) { - IMessage m = MessageUtil.error( - WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE,annotationType.getName()), - getSourceLocation()); - scope.getWorld().getMessageHandler().handleMessage(m); - resolved = false; - } + verifyIsAnnotationType(annotationType,scope); return this; } } + /** + * @param scope + */ + private void verifyIsAnnotationType(TypeX type,IScope scope) { + if (!type.isAnnotation(scope.getWorld())) { + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE,type.getName()), + getSourceLocation()); + scope.getWorld().getMessageHandler().handleMessage(m); + resolved = false; + } + } + private static byte VERSION = 1; // rev if serialisation form changes /* (non-Javadoc) * @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream) diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java index 755e025e2..6da79c779 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java @@ -185,9 +185,6 @@ public class ExactTypePattern extends TypePattern { StringBuffer buff = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { buff.append('('); - if (! (annotationPattern instanceof ExactAnnotationTypePattern )) { - buff.append('@'); - } buff.append(annotationPattern.toString()); buff.append(' '); } diff --git a/weaver/src/org/aspectj/weaver/patterns/NotAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/NotAnnotationTypePattern.java index d7869d90a..8e3679e53 100644 --- a/weaver/src/org/aspectj/weaver/patterns/NotAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/NotAnnotationTypePattern.java @@ -69,7 +69,7 @@ public class NotAnnotationTypePattern extends AnnotationTypePattern { } public String toString() { - return "(!" + negatedPattern.toString() + ")"; + return "!" + negatedPattern.toString(); } public AnnotationTypePattern getNegatedPattern() { diff --git a/weaver/src/org/aspectj/weaver/patterns/NotTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/NotTypePattern.java index 02adeadd8..cbe48e03b 100644 --- a/weaver/src/org/aspectj/weaver/patterns/NotTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/NotTypePattern.java @@ -95,9 +95,6 @@ public class NotTypePattern extends TypePattern { StringBuffer buff = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { buff.append('('); - if (! (annotationPattern instanceof ExactAnnotationTypePattern )) { - buff.append('@'); - } buff.append(annotationPattern.toString()); buff.append(' '); } diff --git a/weaver/src/org/aspectj/weaver/patterns/OrTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/OrTypePattern.java index 6d8689eb1..37fa7767a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/OrTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/OrTypePattern.java @@ -100,9 +100,6 @@ public class OrTypePattern extends TypePattern { StringBuffer buff = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { buff.append('('); - if (! (annotationPattern instanceof ExactAnnotationTypePattern )) { - buff.append('@'); - } buff.append(annotationPattern.toString()); buff.append(' '); } diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java index a91a44b6f..0cb850d3e 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java +++ b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java @@ -504,40 +504,38 @@ public class PatternParser { //int startPos = tokenSource.peek(-1).getStart(); //??? we lose source location for true start of !type TypePattern p = new NotTypePattern(parseAtomicTypePattern()); + p = setAnnotationPatternForTypePattern(p,ap); return p; } if (maybeEat("(")) { TypePattern p = parseTypePattern(); + p = setAnnotationPatternForTypePattern(p,ap); eat(")"); return p; } -// if (maybeEat("@")) { -// AnnotationTypePattern ap = null; -// if (maybeEat("(")) { -// ap = parseAnnotationTypePattern(); -// eat(")"); -// } else { -// ap = parseSimpleAnnotationName(); -// } -// int startPos = tokenSource.peek().getStart(); -// TypePattern p = parseAtomicTypePattern(); -// int endPos = tokenSource.peek(-1).getEnd(); -// p.setLocation(sourceContext, startPos, endPos); -// if (ap != null) { -// if (p == TypePattern.ANY) { -// p = new WildTypePattern(new NamePattern[] {NamePattern.ANY},false,0); -// } -// p.setAnnotationTypePattern(ap); -// } -// return p; -// } int startPos = tokenSource.peek().getStart(); TypePattern p = parseSingleTypePattern(); int endPos = tokenSource.peek(-1).getEnd(); + p = setAnnotationPatternForTypePattern(p,ap); p.setLocation(sourceContext, startPos, endPos); return p; } + private TypePattern setAnnotationPatternForTypePattern(TypePattern t, AnnotationTypePattern ap) { + TypePattern ret = t; + if (ap != AnnotationTypePattern.ANY) { + if (t == TypePattern.ANY) { + ret = new WildTypePattern(new NamePattern[] {NamePattern.ANY},false,0,false); + } + if (t.annotationPattern == AnnotationTypePattern.ANY) { + ret.setAnnotationTypePattern(ap); + } else { + ret.setAnnotationTypePattern(new AndAnnotationTypePattern(ap,t.annotationPattern)); //??? + } + } + return ret; + } + public AnnotationTypePattern maybeParseAnnotationPattern() { AnnotationTypePattern ret = AnnotationTypePattern.ANY; AnnotationTypePattern nextPattern = null; @@ -560,6 +558,7 @@ public class PatternParser { if (maybeEat("(")) { TypePattern p = parseTypePattern(); ret = new NotAnnotationTypePattern(new WildAnnotationTypePattern(p)); + eat(")"); return ret; } else { TypePattern p = parseSingleTypePattern(); @@ -575,6 +574,7 @@ public class PatternParser { if (maybeEat("(")) { TypePattern p = parseTypePattern(); ret = new WildAnnotationTypePattern(p); + eat(")"); return ret; } else { TypePattern p = parseSingleTypePattern(); @@ -617,35 +617,35 @@ public class PatternParser { - private AnnotationTypePattern completeAnnotationPattern(AnnotationTypePattern p) { - if (maybeEat("&&")) { - return new AndAnnotationTypePattern(p,parseNotOrAnnotationPattern()); - } - if (maybeEat("||")) { - return new OrAnnotationTypePattern(p,parseAnnotationTypePattern()); - } - return p; - } - - protected AnnotationTypePattern parseAnnotationTypePattern() { - AnnotationTypePattern ap = parseAtomicAnnotationPattern(); - if (maybeEat("&&")) { - ap = new AndAnnotationTypePattern(ap, parseNotOrAnnotationPattern()); - } - - if (maybeEat("||")) { - ap = new OrAnnotationTypePattern(ap, parseAnnotationTypePattern()); - } - return ap; - } - - private AnnotationTypePattern parseNotOrAnnotationPattern() { - AnnotationTypePattern p = parseAtomicAnnotationPattern(); - if (maybeEat("&&")) { - p = new AndAnnotationTypePattern(p,parseAnnotationTypePattern()); - } - return p; - } +// private AnnotationTypePattern completeAnnotationPattern(AnnotationTypePattern p) { +// if (maybeEat("&&")) { +// return new AndAnnotationTypePattern(p,parseNotOrAnnotationPattern()); +// } +// if (maybeEat("||")) { +// return new OrAnnotationTypePattern(p,parseAnnotationTypePattern()); +// } +// return p; +// } +// +// protected AnnotationTypePattern parseAnnotationTypePattern() { +// AnnotationTypePattern ap = parseAtomicAnnotationPattern(); +// if (maybeEat("&&")) { +// ap = new AndAnnotationTypePattern(ap, parseNotOrAnnotationPattern()); +// } +// +// if (maybeEat("||")) { +// ap = new OrAnnotationTypePattern(ap, parseAnnotationTypePattern()); +// } +// return ap; +// } +// +// private AnnotationTypePattern parseNotOrAnnotationPattern() { +// AnnotationTypePattern p = parseAtomicAnnotationPattern(); +// if (maybeEat("&&")) { +// p = new AndAnnotationTypePattern(p,parseAnnotationTypePattern()); +// } +// return p; +// } protected AnnotationTypePattern parseAnnotationNameOrVarTypePattern() { @@ -680,32 +680,32 @@ public class PatternParser { return p; } - private AnnotationTypePattern parseAtomicAnnotationPattern() { - if (maybeEat("!")) { - //int startPos = tokenSource.peek(-1).getStart(); - //??? we lose source location for true start of !type - AnnotationTypePattern p = new NotAnnotationTypePattern(parseAtomicAnnotationPattern()); - return p; - } - if (maybeEat("(")) { - AnnotationTypePattern p = parseAnnotationTypePattern(); - eat(")"); - return p; - } - int startPos = tokenSource.peek().getStart(); - eat("@"); - StringBuffer annotationName = new StringBuffer(); - annotationName.append(parseIdentifier()); - while (maybeEat(".")) { - annotationName.append('.'); - annotationName.append(parseIdentifier()); - } - TypeX type = TypeX.forName(annotationName.toString()); - AnnotationTypePattern p = new ExactAnnotationTypePattern(type); - int endPos = tokenSource.peek(-1).getEnd(); - p.setLocation(sourceContext, startPos, endPos); - return p; - } +// private AnnotationTypePattern parseAtomicAnnotationPattern() { +// if (maybeEat("!")) { +// //int startPos = tokenSource.peek(-1).getStart(); +// //??? we lose source location for true start of !type +// AnnotationTypePattern p = new NotAnnotationTypePattern(parseAtomicAnnotationPattern()); +// return p; +// } +// if (maybeEat("(")) { +// AnnotationTypePattern p = parseAnnotationTypePattern(); +// eat(")"); +// return p; +// } +// int startPos = tokenSource.peek().getStart(); +// eat("@"); +// StringBuffer annotationName = new StringBuffer(); +// annotationName.append(parseIdentifier()); +// while (maybeEat(".")) { +// annotationName.append('.'); +// annotationName.append(parseIdentifier()); +// } +// TypeX type = TypeX.forName(annotationName.toString()); +// AnnotationTypePattern p = new ExactAnnotationTypePattern(type); +// int endPos = tokenSource.peek(-1).getEnd(); +// p.setLocation(sourceContext, startPos, endPos); +// return p; +// } private boolean isAnnotationPattern(PatternNode p) { diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java index d1cb4fee8..31cf6545a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java @@ -436,9 +436,6 @@ public class SignaturePattern extends PatternNode { StringBuffer buf = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { - if (! (annotationPattern instanceof ExactAnnotationTypePattern )) { - buf.append('@'); - } buf.append(annotationPattern.toString()); buf.append(' '); } diff --git a/weaver/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java index f76a4e65f..145915e19 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java @@ -13,12 +13,14 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.AnnotatedElement; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ResolvedTypeX; -import org.aspectj.weaver.TypeX; +import org.aspectj.weaver.WeaverMessages; /** * @author colyer @@ -29,6 +31,7 @@ import org.aspectj.weaver.TypeX; public class WildAnnotationTypePattern extends AnnotationTypePattern { private TypePattern typePattern; + private boolean resolved = false; /** * @@ -43,6 +46,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { * @see org.aspectj.weaver.patterns.AnnotationTypePattern#matches(org.aspectj.weaver.AnnotatedElement) */ public FuzzyBoolean matches(AnnotatedElement annotated) { + if (!resolved) { + throw new IllegalStateException("Can't match on an unresolved annotation type pattern"); + } // matches if the type of any of the annotations on the AnnotatedElement is // matched by the typePattern. ResolvedTypeX[] annTypes = annotated.getAnnotationTypes(); @@ -61,8 +67,16 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { boolean allowBinding) { this.typePattern = typePattern.resolveBindings(scope,bindings,false,false); + resolved = true; if (typePattern instanceof ExactTypePattern) { ExactTypePattern et = (ExactTypePattern)typePattern; + if (!et.getExactType().isAnnotation(scope.getWorld())) { + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE,et.getExactType().getName()), + getSourceLocation()); + scope.getWorld().getMessageHandler().handleMessage(m); + resolved = false; + } return new ExactAnnotationTypePattern(et.getExactType()); } else { return this; @@ -91,5 +105,27 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { ret.readLocation(context,s); return ret; } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (!(obj instanceof WildAnnotationTypePattern)) return false; + WildAnnotationTypePattern other = (WildAnnotationTypePattern) obj; + return other.typePattern.equals(typePattern); + } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return 17 + 37*typePattern.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return "@(" + typePattern.toString() + ")"; + } } diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index 2cef3745c..2be4c38b1 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -507,6 +507,7 @@ public class WildTypePattern extends TypePattern { public String toString() { StringBuffer buf = new StringBuffer(); if (annotationPattern != AnnotationTypePattern.ANY) { + buf.append('('); buf.append(annotationPattern.toString()); buf.append(' '); } @@ -519,6 +520,9 @@ public class WildTypePattern extends TypePattern { buf.append(name.toString()); } } + if (annotationPattern != AnnotationTypePattern.ANY) { + buf.append(')'); + } return buf.toString(); } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java index 8d6462b75..e525f8578 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java @@ -71,11 +71,11 @@ public class AnnotationPatternMatchingTestCase extends TestCase { private void initAnnotationTypePatterns() { PatternParser p = new PatternParser("@Foo"); - fooTP = p.parseAnnotationTypePattern(); + fooTP = p.maybeParseAnnotationPattern(); fooTP = fooTP.resolveBindings(makeSimpleScope(),new Bindings(3),true); p = new PatternParser("@p.SimpleAnnotation"); - simpleAnnotationTP = p.parseAnnotationTypePattern(); + simpleAnnotationTP = p.maybeParseAnnotationPattern(); simpleAnnotationTP = simpleAnnotationTP.resolveBindings(makeSimpleScope(),new Bindings(3),true); } @@ -108,7 +108,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase { MyMessageHandler mh = new MyMessageHandler(); world.setMessageHandler(mh); - AnnotationTypePattern atp = p.parseAnnotationTypePattern(); + AnnotationTypePattern atp = p.maybeParseAnnotationPattern(); atp = atp.resolveBindings(makeSimpleScope(),new Bindings(3),true); assertTrue("Expected 1 error message but got "+mh.messages.size(),mh.messages.size()==1); @@ -142,7 +142,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase { ResolvedTypeX rtx = loadType("AnnotatedClass"); PatternParser p = new PatternParser("@Foo"); - AnnotationTypePattern fooTP = p.parseAnnotationTypePattern(); + AnnotationTypePattern fooTP = p.maybeParseAnnotationPattern(); try { fooTP.matches(rtx); fail("Should have failed with illegal state exception, fooTP is not resolved"); diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java index 0ddbc34e2..52b6b98a6 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java @@ -21,94 +21,93 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseSimpleAnnotationPattern() { PatternParser p = new PatternParser("@Foo"); - AnnotationTypePattern foo = p.parseAnnotationTypePattern(); + AnnotationTypePattern foo = p.maybeParseAnnotationPattern(); + foo = foo.resolveBindings(makeSimpleScope(),new Bindings(3),true); assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern); assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)foo).annotationType); } public void testParseAndAnnotationPattern() { - PatternParser p = new PatternParser("@Foo && @Goo"); - AnnotationTypePattern fooAndGoo = p.parseAnnotationTypePattern(); + PatternParser p = new PatternParser("@Foo @Goo"); + AnnotationTypePattern fooAndGoo = p.maybeParseAnnotationPattern(); assertTrue("AndAnnotationTypePattern",fooAndGoo instanceof AndAnnotationTypePattern); - assertEquals("(@Foo && @Goo)",fooAndGoo.toString()); + assertEquals("@(Foo) @(Goo)",fooAndGoo.toString()); + 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",TypeX.forName("Foo"),((ExactAnnotationTypePattern)left).annotationType); assertEquals("Goo",TypeX.forName("Goo"),((ExactAnnotationTypePattern)right).annotationType); } - - public void testParseOrAnnotationPattern() { - PatternParser p = new PatternParser("@Foo || @Goo"); - AnnotationTypePattern fooOrGoo = p.parseAnnotationTypePattern(); - assertTrue("OrAnnotationTypePattern",fooOrGoo instanceof OrAnnotationTypePattern); - assertEquals("(@Foo || @Goo)",fooOrGoo.toString()); - AnnotationTypePattern left = ((OrAnnotationTypePattern)fooOrGoo).getLeft(); - AnnotationTypePattern right = ((OrAnnotationTypePattern)fooOrGoo).getRight(); - assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)left).annotationType); - assertEquals("Goo",TypeX.forName("Goo"),((ExactAnnotationTypePattern)right).annotationType); - } - +// +// public void testParseOrAnnotationPattern() { +// PatternParser p = new PatternParser("@Foo || @Goo"); +// AnnotationTypePattern fooOrGoo = p.parseAnnotationTypePattern(); +// assertTrue("OrAnnotationTypePattern",fooOrGoo instanceof OrAnnotationTypePattern); +// assertEquals("(@Foo || @Goo)",fooOrGoo.toString()); +// AnnotationTypePattern left = ((OrAnnotationTypePattern)fooOrGoo).getLeft(); +// AnnotationTypePattern right = ((OrAnnotationTypePattern)fooOrGoo).getRight(); +// assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)left).annotationType); +// assertEquals("Goo",TypeX.forName("Goo"),((ExactAnnotationTypePattern)right).annotationType); +// } +// public void testParseNotAnnotationPattern() { PatternParser p = new PatternParser("!@Foo"); - AnnotationTypePattern notFoo = p.parseAnnotationTypePattern(); + AnnotationTypePattern notFoo = p.maybeParseAnnotationPattern(); assertTrue("NotAnnotationTypePattern",notFoo instanceof NotAnnotationTypePattern); - assertEquals("(!@Foo)",notFoo.toString()); + notFoo = notFoo.resolveBindings(makeSimpleScope(),new Bindings(3),true); + assertEquals("!@Foo",notFoo.toString()); AnnotationTypePattern body = ((NotAnnotationTypePattern)notFoo).getNegatedPattern(); assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)body).annotationType); } public void testParseBracketedAnnotationPattern() { PatternParser p = new PatternParser("(@Foo)"); - AnnotationTypePattern foo = p.parseAnnotationTypePattern(); - assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern); - assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)foo).annotationType); + AnnotationTypePattern foo = p.maybeParseAnnotationPattern(); + // cannot start with ( so, we get ANY + assertEquals("ANY",AnnotationTypePattern.ANY,foo); } public void testParseFQAnnPattern() { PatternParser p = new PatternParser("@org.aspectj.Foo"); - AnnotationTypePattern foo = p.parseAnnotationTypePattern(); - assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern); - assertEquals("org.aspectj.Foo",TypeX.forName("org.aspectj.Foo"),((ExactAnnotationTypePattern)foo).annotationType); + AnnotationTypePattern foo = p.maybeParseAnnotationPattern(); + assertEquals("@(org.aspectj.Foo)",foo.toString()); } public void testParseComboPattern() { - PatternParser p = new PatternParser("!((@Foo || @Goo) && !@Boo)"); - AnnotationTypePattern ap = p.parseAnnotationTypePattern(); - NotAnnotationTypePattern ntp = (NotAnnotationTypePattern) ap; - AndAnnotationTypePattern atp = (AndAnnotationTypePattern) ntp.getNegatedPattern(); +// PatternParser p = new PatternParser("!((@Foo || @Goo) && !@Boo)"); + PatternParser p = new PatternParser("@(Foo || Goo)!@Boo"); + AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); + ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); + AndAnnotationTypePattern atp = (AndAnnotationTypePattern) ap; NotAnnotationTypePattern notBoo = (NotAnnotationTypePattern) atp.getRight(); ExactAnnotationTypePattern boo = (ExactAnnotationTypePattern) notBoo.getNegatedPattern(); - OrAnnotationTypePattern fooOrGoo = (OrAnnotationTypePattern) atp.getLeft(); - ExactAnnotationTypePattern foo = (ExactAnnotationTypePattern) fooOrGoo.getLeft(); - ExactAnnotationTypePattern goo = (ExactAnnotationTypePattern) fooOrGoo.getRight(); - assertEquals("(!((@Foo || @Goo) && (!@Boo)))",ap.toString()); - } - - public void testParseAndOrPattern() { - PatternParser p = new PatternParser("@Foo && @Boo || @Goo"); - AnnotationTypePattern andOr = p.parseAnnotationTypePattern(); - assertTrue("Should be or pattern",andOr instanceof OrAnnotationTypePattern); + WildAnnotationTypePattern fooOrGoo = (WildAnnotationTypePattern) atp.getLeft(); + assertEquals("@((Foo || Goo)) !@Boo",ap.toString()); } +// public void testParseAndOrPattern() { +// PatternParser p = new PatternParser("@Foo && @Boo || @Goo"); +// AnnotationTypePattern andOr = p.parseAnnotationTypePattern(); +// assertTrue("Should be or pattern",andOr instanceof OrAnnotationTypePattern); +// } +// public void testParseBadPattern() { PatternParser p = new PatternParser("@@Foo"); try { - AnnotationTypePattern bad = p.parseAnnotationTypePattern(); + AnnotationTypePattern bad = p.maybeParseAnnotationPattern(); fail("ParserException expected"); } catch(ParserException pEx) { - assertEquals("identifier",pEx.getMessage()); + assertEquals("expected name pattern",pEx.getMessage()); } } public void testParseBadPattern2() { PatternParser p = new PatternParser("Foo"); - try { - AnnotationTypePattern bad = p.parseAnnotationTypePattern(); - fail("ParserException expected"); - } catch(ParserException pEx) { - assertEquals("@",pEx.getMessage()); - } + AnnotationTypePattern bad = p.maybeParseAnnotationPattern(); + assertEquals("ANY",AnnotationTypePattern.ANY,bad); } + public void testParseNameOrVarAnnotationPattern() { PatternParser p = new PatternParser("@Foo"); AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern(); @@ -143,11 +142,10 @@ public class AnnotationPatternTestCase extends TestCase { } public void testParseNameOrVarAnnotationPatternWithAnd() { - PatternParser p = new PatternParser("@Foo && @Boo"); + PatternParser p = new PatternParser("@Foo @Boo"); AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern(); // rest of pattern not consumed... - assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern); - assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)foo).annotationType); + assertEquals("@Foo",foo.toString()); } public void testMaybeParseAnnotationPattern() { @@ -163,27 +161,27 @@ public class AnnotationPatternTestCase extends TestCase { PatternParser p = new PatternParser("@Foo *"); TypePattern t = p.parseTypePattern(); assertTrue("WildTypePattern",t instanceof WildTypePattern); - ExactAnnotationTypePattern etp = (ExactAnnotationTypePattern) t.annotationPattern; - assertEquals("@Foo",etp.toString()); - assertEquals("@Foo *",t.toString()); + AnnotationTypePattern atp = t.annotationPattern; + assertEquals("@(Foo)",atp.toString()); + assertEquals("(@(Foo) *)",t.toString()); } public void testParseTypePatternsWithAnnotationsComplex() { - PatternParser p = new PatternParser("(@(@Foo || @Boo) (Foo || Boo))"); + PatternParser p = new PatternParser("(@(Foo || Boo) (Foo || Boo))"); TypePattern t = p.parseTypePattern(); assertTrue("OrTypePattern",t instanceof OrTypePattern); - OrAnnotationTypePattern etp = (OrAnnotationTypePattern) t.annotationPattern; - assertEquals("(@Foo || @Boo)",etp.toString()); - assertEquals("(@(@Foo || @Boo) (Foo || Boo))",t.toString()); + WildAnnotationTypePattern wtp = (WildAnnotationTypePattern) t.annotationPattern; + assertEquals("@((Foo || Boo))",wtp.toString()); + assertEquals("(@((Foo || Boo)) (Foo || Boo))",t.toString()); } - public void testRidiculousNotSyntax() { - PatternParser p = new PatternParser("(@(!@Foo) (Foo || Boo))"); + public void testNotSyntax() { + PatternParser p = new PatternParser("!@Foo (Foo || Boo))"); TypePattern t = p.parseTypePattern(); assertTrue("OrTypePattern",t instanceof OrTypePattern); NotAnnotationTypePattern natp = (NotAnnotationTypePattern) t.annotationPattern; - assertEquals("(!@Foo)",natp.toString()); - assertEquals("(@(!@Foo) (Foo || Boo))",t.toString()); + assertEquals("!@(Foo)",natp.toString()); + assertEquals("(!@(Foo) (Foo || Boo))",t.toString()); } public void testParseMethodOrConstructorSigNoAP() { @@ -199,21 +197,21 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseMethodOrConstructorSigSimpleAP() { PatternParser p = new PatternParser("@Foo * *.*(..)"); SignaturePattern s = p.parseMethodOrConstructorSignaturePattern(); - assertEquals("Exact annotation","@Foo",((ExactAnnotationTypePattern)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()); - assertEquals("@Foo * *.*(..)",s.toString()); + assertEquals("@(Foo) * *.*(..)",s.toString()); } public void testParseMethodOrConstructorSigComplexAP() { - PatternParser p = new PatternParser("@(!@Foo || @Goo) * *.*(..)"); + 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()); - assertEquals("@((!@Foo) || @Goo) * *.*(..)",s.toString()); + assertEquals("!@((Foo || Goo)) * *.*(..)",s.toString()); } public void testParseMethodFieldSigNoAP() { @@ -229,26 +227,26 @@ public class AnnotationPatternTestCase extends TestCase { public void testParseFieldSigSimpleAP() { PatternParser p = new PatternParser("@Foo * *.*"); SignaturePattern s = p.parseFieldSignaturePattern(); - assertEquals("Exact annotation","@Foo",((ExactAnnotationTypePattern)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()); - assertEquals("@Foo * *.*",s.toString()); + assertEquals("@(Foo) * *.*",s.toString()); } public void testParseFieldSigComplexAP() { - PatternParser p = new PatternParser("@(!@Foo || @Goo) * *.*"); + 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()); - assertEquals("@((!@Foo) || @Goo) * *.*",s.toString()); + assertEquals("!@((Foo || Goo)) * *.*",s.toString()); } public void testExactAnnotationPatternMatching() { PatternParser p = new PatternParser("@Foo"); - AnnotationTypePattern ap = p.parseAnnotationTypePattern(); + AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[]{"Foo"}); assertTrue("matches element with Foo",ap.matches(ae).alwaysTrue()); @@ -267,8 +265,8 @@ public class AnnotationPatternTestCase extends TestCase { } public void testAndAnnotationPatternMatching() { - PatternParser p = new PatternParser("@Foo && @Boo"); - AnnotationTypePattern ap = p.parseAnnotationTypePattern(); + 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"}); assertTrue("matches foo and boo",ap.matches(ae).alwaysTrue()); @@ -279,24 +277,24 @@ public class AnnotationPatternTestCase extends TestCase { ae = new AnnotatedElementImpl(new String[] {"Goo"}); assertTrue("does not match goo",ap.matches(ae).alwaysFalse()); } - - public void testOrAnnotationPatternMatching() { - PatternParser p = new PatternParser("@Foo || @Boo"); - AnnotationTypePattern ap = p.parseAnnotationTypePattern(); - ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); - AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] {"Foo","Boo"}); - assertTrue("matches foo and boo",ap.matches(ae).alwaysTrue()); - ae = new AnnotatedElementImpl(new String[] {"Foo"}); - assertTrue("matches foo",ap.matches(ae).alwaysTrue()); - ae = new AnnotatedElementImpl(new String[] {"Boo"}); - assertTrue("matches boo",ap.matches(ae).alwaysTrue()); - ae = new AnnotatedElementImpl(new String[] {"Goo"}); - assertTrue("does not match goo",ap.matches(ae).alwaysFalse()); - } - +// +// public void testOrAnnotationPatternMatching() { +// PatternParser p = new PatternParser("@Foo || @Boo"); +// AnnotationTypePattern ap = p.parseAnnotationTypePattern(); +// ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); +// AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] {"Foo","Boo"}); +// assertTrue("matches foo and boo",ap.matches(ae).alwaysTrue()); +// ae = new AnnotatedElementImpl(new String[] {"Foo"}); +// assertTrue("matches foo",ap.matches(ae).alwaysTrue()); +// ae = new AnnotatedElementImpl(new String[] {"Boo"}); +// assertTrue("matches boo",ap.matches(ae).alwaysTrue()); +// ae = new AnnotatedElementImpl(new String[] {"Goo"}); +// assertTrue("does not match goo",ap.matches(ae).alwaysFalse()); +// } +// public void testNotAnnotationPatternMatching() { PatternParser p = new PatternParser("!@Foo"); - AnnotationTypePattern ap = p.parseAnnotationTypePattern(); + 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()); @@ -314,8 +312,8 @@ public class AnnotationPatternTestCase extends TestCase { public TestScope makeSimpleScope() { BcelWorld bWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); // testcode contains Foo/Boo/Goo/etc - return new TestScope(new String[] {"int", "java.lang.String","Foo"}, - new String[] {"a", "b","foo"}, + return new TestScope(new String[] {"int", "java.lang.String","Foo","Boo","Goo"}, + new String[] {"a", "b","foo","boo","goo"}, bWorld); }