public String toString() {
return "(" + left.toString() + " && " + right.toString() + ")";
}
+
+ public AnnotationTypePattern getLeft() { return left; }
+ public AnnotationTypePattern getRight() { return right; }
}
}
public String toString() {
- return "(" + left.toString() + " && " + right.toString() + ")";
+ StringBuffer buff = new StringBuffer();
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append('(');
+ if (! (annotationPattern instanceof ExactAnnotationTypePattern )) {
+ buff.append('@');
+ }
+ buff.append(annotationPattern.toString());
+ buff.append(' ');
+ }
+ buff.append('(');
+ buff.append(left.toString());
+ buff.append(" && ");
+ buff.append(right.toString());
+ buff.append(')');
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append(')');
+ }
+ return buff.toString();
}
}
public String toString() {
//Thread.currentThread().dumpStack();
- return "BindingTypePattern(" + type.toString() + ", " + formalIndex + ")";
+ return "BindingTypePattern(" + super.toString() + ", " + formalIndex + ")";
}
}
protected TypeX annotationType;
protected String formalName;
+ private boolean resolved = true;
/**
*
public ExactAnnotationTypePattern(String formalName) {
this.formalName = formalName;
+ this.resolved = false;
// will be turned into BindingAnnotationTypePattern during resolution
}
*/
public AnnotationTypePattern resolveBindings(IScope scope,
Bindings bindings, boolean allowBinding) {
+ if (resolved) return this;
+ resolved = true;
if (formalName != null) {
FormalBinding formalBinding = scope.lookupFormal(formalName);
if (formalBinding != null) {
public void write(DataOutputStream s) throws IOException {
s.writeByte(AnnotationTypePattern.EXACT);
s.writeByte(VERSION);
- annotationType.write(s);
+ s.writeBoolean(resolved);
+ if (resolved) {
+ annotationType.write(s);
+ } else {
+ s.writeUTF(formalName);
+ }
writeLocation(s);
}
if (version > VERSION) {
throw new BCException("ExactAnnotationTypePattern was written by a newer version of AspectJ");
}
- ret = new ExactAnnotationTypePattern(TypeX.read(s));
+ boolean isResolved = s.readBoolean();
+ if (isResolved) {
+ ret = new ExactAnnotationTypePattern(TypeX.read(s));
+ } else {
+ ret = new ExactAnnotationTypePattern(s.readUTF());
+ }
ret.readLocation(context,s);
return ret;
}
}
public String toString() {
- //Thread.currentThread().dumpStack();
- return type.toString() + (includeSubtypes ? "+" : "");
+ StringBuffer buff = new StringBuffer();
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append('(');
+ if (! (annotationPattern instanceof ExactAnnotationTypePattern )) {
+ buff.append('@');
+ }
+ buff.append(annotationPattern.toString());
+ buff.append(' ');
+ }
+ buff.append(type.toString());
+ if (includeSubtypes) buff.append('+');
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append(')');
+ }
+ return buff.toString();
}
public TypePattern resolveBindings(IScope scope, Bindings bindings,
boolean allowBinding, boolean requireExactType)
}
public String toString() {
- return "!" + negatedPattern.toString();
+ return "(!" + negatedPattern.toString() + ")";
+ }
+
+ public AnnotationTypePattern getNegatedPattern() {
+ return negatedPattern;
}
}
}
public String toString() {
- return "!" + pattern;
+ StringBuffer buff = new StringBuffer();
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append('(');
+ if (! (annotationPattern instanceof ExactAnnotationTypePattern )) {
+ buff.append('@');
+ }
+ buff.append(annotationPattern.toString());
+ buff.append(' ');
+ }
+ buff.append('!');
+ buff.append(pattern);
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append(')');
+ }
+ return buff.toString();
}
}
return "(" + left.toString() + " || " + right.toString() + ")";
}
+ public AnnotationTypePattern getLeft() { return left; }
+ public AnnotationTypePattern getRight() { return right; }
+
}
}
public String toString() {
- return "(" + left.toString() + " || " + right.toString() + ")";
+ StringBuffer buff = new StringBuffer();
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append('(');
+ if (! (annotationPattern instanceof ExactAnnotationTypePattern )) {
+ buff.append('@');
+ }
+ buff.append(annotationPattern.toString());
+ buff.append(' ');
+ }
+ buff.append('(');
+ buff.append(left.toString());
+ buff.append(" || ");
+ buff.append(right.toString());
+ buff.append(')');
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buff.append(')');
+ }
+ return buff.toString();
}
-
}
}
public TypePattern parseTypePattern() {
- AnnotationTypePattern ap = null;
- TypePattern tp = null;
- PatternNode p = parseAtomicPattern();
- if (isAnnotationPattern(p)) {
- ap = completeAnnotationPattern((AnnotationTypePattern)p);
- IToken tok = tokenSource.peek();
- PatternNode typepat = parseTypePattern();
- if (isAnnotationPattern(p)) {
- throw new ParserException("Duplicate annotation pattern",tok);
- } else {
- tp = (TypePattern) typepat;
- tp.setAnnotationTypePattern(ap);
- }
- } else {
- tp = (TypePattern)p;
- }
+ TypePattern p = parseAtomicTypePattern();
if (maybeEat("&&")) {
- tp = new AndTypePattern(tp, parseNotOrTypePattern());
+ p = new AndTypePattern(p, parseNotOrTypePattern());
}
if (maybeEat("||")) {
- tp = new OrTypePattern(tp, parseTypePattern());
+ p = new OrTypePattern(p, parseTypePattern());
}
- return tp;
- }
-
- private AnnotationTypePattern completeAnnotationPattern(AnnotationTypePattern p) {
- if (maybeEat("&&")) {
- return new AndAnnotationTypePattern(p,parseNotOrAnnotationPattern());
- }
- if (maybeEat("||")) {
- return new OrAnnotationTypePattern(p,parseAnnotationTypePattern(false));
- }
- return p;
- }
-
- private AnnotationTypePattern parseNotOrAnnotationPattern() {
- AnnotationTypePattern p = parseAnnotationTypePattern(false);
- if (maybeEat("&&")) {
- p = new AndAnnotationTypePattern(p,parseAnnotationTypePattern(false));
- }
- return p;
- }
-
- private AnnotationTypePattern parseAnnotationTypePattern(boolean isOptional) {
- IToken tok = tokenSource.peek();
- PatternNode p = parseAtomicPattern();
- if (!isAnnotationPattern(p)) {
- if (isOptional) return null;
- throw new ParserException("Expecting annotation pattern",tok);
- }
- AnnotationTypePattern ap = (AnnotationTypePattern) p;
- if (maybeEat("&&")) {
- ap = new AndAnnotationTypePattern(ap, parseNotOrAnnotationPattern());
- }
-
- if (maybeEat("||")) {
- ap = new OrAnnotationTypePattern(ap, parseAnnotationTypePattern(false));
- }
- return ap;
- }
-
- private AnnotationTypePattern parseAnnotationNameOrVarTypePattern() {
- AnnotationTypePattern p = null;
- int startPos = tokenSource.peek().getStart();
- if (maybeEat(AT)) {
- StringBuffer annotationName = new StringBuffer();
- annotationName.append(parseIdentifier());
- while (maybeEat(".")) {
- annotationName.append(parseIdentifier());
- }
- TypeX type = TypeX.forName(annotationName.toString());
- p = new ExactAnnotationTypePattern(type);
- } else {
- String formal = parseIdentifier();
- p = new ExactAnnotationTypePattern(formal); // will get replaced when bindings resolved
- }
- int endPos = tokenSource.peek(-1).getEnd();
- p.setLocation(sourceContext,startPos,endPos);
return p;
}
private TypePattern parseNotOrTypePattern() {
- AnnotationTypePattern ap = null;
- TypePattern tp = null;
- PatternNode p = parseAtomicPattern();
- if (isAnnotationPattern(p)) {
- ap = completeAnnotationPattern((AnnotationTypePattern)p);
- IToken tok = tokenSource.peek();
- PatternNode typepat = parseTypePattern();
- if (isAnnotationPattern(p)) {
- throw new ParserException("Duplicate annotation pattern",tok);
- } else {
- tp = (TypePattern) typepat;
- tp.setAnnotationTypePattern(ap);
- }
- } else {
- tp = (TypePattern) p;
- }
+ TypePattern p = parseAtomicTypePattern();
if (maybeEat("&&")) {
- tp = new AndTypePattern(tp, parseTypePattern());
+ p = new AndTypePattern(p, parseTypePattern());
}
- return tp;
+ return p;
}
private TypePattern parseAtomicTypePattern() {
eat(")");
return p;
}
- int startPos = tokenSource.peek().getStart();
- TypePattern p = parseSingleTypePattern();
- int endPos = tokenSource.peek(-1).getEnd();
- p.setLocation(sourceContext, startPos, endPos);
- return p;
- }
-
- private PatternNode parseAtomicPattern() {
- if (maybeEat("!")) {
- PatternNode p = parseAtomicPattern();
- if (isAnnotationPattern(p)) {
- return new NotAnnotationTypePattern((AnnotationTypePattern)p);
+ if (maybeEat("@")) {
+ AnnotationTypePattern ap = null;
+ if (maybeEat("(")) {
+ ap = parseAnnotationTypePattern();
+ eat(")");
} else {
- return new NotTypePattern((TypePattern)p);
- }
- }
- if (maybeEat("(")) {
- TypePattern p = parseTypePattern();
- eat(")");
- return p;
- }
- if (maybeEat(AT)) {
- StringBuffer annotationName = new StringBuffer();
- annotationName.append(parseIdentifier());
- while (maybeEat(".")) {
- annotationName.append(parseIdentifier());
+ ap = parseSimpleAnnotationName();
}
- TypeX type = TypeX.forName(annotationName.toString());
- return new ExactAnnotationTypePattern(type);
+ 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();
return p;
}
- private boolean isAnnotationPattern(PatternNode p) {
- return (p instanceof AnnotationTypePattern);
- }
-
public TypePattern parseSingleTypePattern() {
List names = parseDottedNamePattern();
// new ArrayList();
return new WildTypePattern(names, includeSubtypes, dim, endPos);
}
+
+
+ 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() {
+ AnnotationTypePattern p = null;
+ int startPos = tokenSource.peek().getStart();
+ if (maybeEat(AT)) {
+ p = parseSimpleAnnotationName();
+ } else {
+ String formal = parseIdentifier();
+ p = new ExactAnnotationTypePattern(formal); // will get replaced when bindings resolved
+ }
+ int endPos = tokenSource.peek(-1).getEnd();
+ p.setLocation(sourceContext,startPos,endPos);
+ return p;
+ }
+
+
+ /**
+ * @return
+ */
+ private AnnotationTypePattern parseSimpleAnnotationName() {
+ // the @ has already been eaten...
+ AnnotationTypePattern p;
+ StringBuffer annotationName = new StringBuffer();
+ annotationName.append(parseIdentifier());
+ while (maybeEat(".")) {
+ annotationName.append('.');
+ annotationName.append(parseIdentifier());
+ }
+ TypeX type = TypeX.forName(annotationName.toString());
+ p = new ExactAnnotationTypePattern(type);
+ 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) {
+ return (p instanceof AnnotationTypePattern);
+ }
+
public List parseDottedNamePattern() {
List names = new ArrayList();
StringBuffer buf = new StringBuffer();
public AnnotationTypePattern maybeParseAnnotationPattern() {
AnnotationTypePattern ret = null;
int start = tokenSource.getIndex();
- ret = parseAnnotationTypePattern(true);
+ if (maybeEat("@")) {
+ if (maybeEat("(")) {
+ ret = parseAnnotationTypePattern();
+ eat(")");
+ } else {
+ ret = parseSimpleAnnotationName();
+ }
+ }
if (ret == null) {
// failed to find one...
tokenSource.setIndex(start);
if (throwsPattern != null) {
throwsPattern = throwsPattern.resolveBindings(scope, bindings);
}
+ if (annotationPattern != null) {
+ annotationPattern = annotationPattern.resolveBindings(scope,bindings,false);
+ }
return this;
}
}
public boolean matches(Member member, World world) {
+ return (matchesIgnoringAnnotations(member,world) &&
+ annotationPattern.matches(member).alwaysTrue());
+ }
+
+ public boolean matchesIgnoringAnnotations(Member member, World world) {
//XXX performance gains would come from matching on name before resolving
// to fail fast. ASC 30th Nov 04 => Not necessarily, it didn't make it faster for me.
// Here is the code I used:
public String toString() {
StringBuffer buf = new StringBuffer();
+
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buf.append(annotationPattern.toString());
+ buf.append(' ');
+ }
+
if (modifiers != ModifiersPattern.ANY) {
buf.append(modifiers.toString());
buf.append(' ');
&& o.returnType.equals(this.returnType)
&& o.declaringType.equals(this.declaringType)
&& o.name.equals(this.name)
- && o.parameterTypes.equals(this.parameterTypes);
+ && o.parameterTypes.equals(this.parameterTypes)
+ && o.annotationPattern.equals(this.annotationPattern);
}
public int hashCode() {
int result = 17;
result = 37*result + declaringType.hashCode();
result = 37*result + name.hashCode();
result = 37*result + parameterTypes.hashCode();
+ result = 37*result + annotationPattern.hashCode();
return result;
}
public String toString() {
StringBuffer buf = new StringBuffer();
+ if (annotationPattern != AnnotationTypePattern.ANY) {
+ buf.append(annotationPattern.toString());
+ buf.append(' ');
+ }
for (int i=0, len=namePatterns.length; i < len; i++) {
NamePattern name = namePatterns[i];
if (name == null) {
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM Corporation.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * ******************************************************************/
+package org.aspectj.weaver.patterns;
+
+import org.aspectj.weaver.AnnotatedElement;
+import org.aspectj.weaver.TypeX;
+
+import junit.framework.TestCase;
+
+public class AnnotationPatternTestCase extends TestCase {
+
+ public void testParseSimpleAnnotationPattern() {
+ PatternParser p = new PatternParser("@Foo");
+ AnnotationTypePattern foo = p.parseAnnotationTypePattern();
+ 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();
+ assertTrue("AndAnnotationTypePattern",fooAndGoo instanceof AndAnnotationTypePattern);
+ 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 testParseNotAnnotationPattern() {
+ PatternParser p = new PatternParser("!@Foo");
+ AnnotationTypePattern notFoo = p.parseAnnotationTypePattern();
+ assertTrue("NotAnnotationTypePattern",notFoo instanceof NotAnnotationTypePattern);
+ 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);
+ }
+
+ 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);
+ }
+
+ public void testParseComboPattern() {
+ PatternParser p = new PatternParser("!((@Foo || @Goo) && !@Boo)");
+ AnnotationTypePattern ap = p.parseAnnotationTypePattern();
+ NotAnnotationTypePattern ntp = (NotAnnotationTypePattern) ap;
+ AndAnnotationTypePattern atp = (AndAnnotationTypePattern) ntp.getNegatedPattern();
+ 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);
+ }
+
+ public void testParseBadPattern() {
+ PatternParser p = new PatternParser("@@Foo");
+ try {
+ AnnotationTypePattern bad = p.parseAnnotationTypePattern();
+ fail("ParserException expected");
+ } catch(ParserException pEx) {
+ assertEquals("identifier",pEx.getMessage());
+ }
+ }
+
+ public void testParseBadPattern2() {
+ PatternParser p = new PatternParser("Foo");
+ try {
+ AnnotationTypePattern bad = p.parseAnnotationTypePattern();
+ fail("ParserException expected");
+ } catch(ParserException pEx) {
+ assertEquals("@",pEx.getMessage());
+ }
+ }
+ public void testParseNameOrVarAnnotationPattern() {
+ PatternParser p = new PatternParser("@Foo");
+ AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern();
+ assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern);
+ assertEquals("Foo",TypeX.forName("Foo"),((ExactAnnotationTypePattern)foo).annotationType);
+ }
+
+ public void testParseNameOrVarAnnotationPatternWithNot() {
+ PatternParser p = new PatternParser("!@Foo");
+ try {
+ AnnotationTypePattern bad = p.parseAnnotationNameOrVarTypePattern();
+ fail("ParserException expected");
+ } catch(ParserException pEx) {
+ assertEquals("identifier",pEx.getMessage());
+ }
+ }
+
+ public void testParseNameOrVarAnnotationPatternWithOr() {
+ 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);
+ }
+
+ public void testParseNameOrVarAnnotationWithBinding() {
+ PatternParser p = new PatternParser("foo");
+ AnnotationTypePattern foo = p.parseAnnotationNameOrVarTypePattern();
+ assertTrue("ExactAnnotationTypePattern",foo instanceof ExactAnnotationTypePattern);
+ assertNull("no type pattern yet",((ExactAnnotationTypePattern)foo).annotationType);
+ assertEquals("foo",((ExactAnnotationTypePattern)foo).formalName);
+ }
+
+ public void testParseNameOrVarAnnotationPatternWithAnd() {
+ 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);
+ }
+
+ public void testMaybeParseAnnotationPattern() {
+ PatternParser p = new PatternParser("@Foo && @Boo");
+ AnnotationTypePattern a = p.maybeParseAnnotationPattern();
+ 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);
+ }
+
+ public void testParseTypePatternsWithAnnotations() {
+ 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());
+ }
+
+ public void testParseTypePatternsWithAnnotationsComplex() {
+ 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());
+ }
+
+ public void testRidiculousNotSyntax() {
+ 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());
+ }
+
+ public void testParseMethodOrConstructorSigNoAP() {
+
+ }
+
+ public void testParseMethodOrConstructorSigSimpleAP() {
+
+ }
+
+ public void testParseMethodOrConstructorSigComplexAP() {
+
+ }
+
+ public void testParseMethodFieldSigNoAP() {
+
+ }
+
+ public void testParseFieldSigSimpleAP() {
+
+ }
+
+ public void testParseFieldSigComplexAP() {
+
+ }
+
+ public void testExactAnnotationPatternMatching() {
+ // matching, non-matching
+ }
+
+ public void testBindingAnnotationPatternMatching() {
+ // matching, non-matching
+ }
+
+ public void testAndAnnotationPatternMatching() {
+
+ }
+
+ public void testOrAnnotationPatternMatching() {
+
+ }
+
+ public void testNotAnnotationPatternMatching() {
+
+ }
+
+ public void testAnyAnnotationPatternMatching() {
+
+ }
+
+ // put test cases for AnnotationPatternList matching in separate test class...
+
+ static class AnnotatedElementImpl implements AnnotatedElement {
+
+ private boolean answer;
+
+ public static final AnnotatedElementImpl YES = new AnnotatedElementImpl(true);
+ public static final AnnotatedElementImpl NO = new AnnotatedElementImpl(false);
+
+ public AnnotatedElementImpl(boolean answer) { this.answer = answer; }
+
+ public boolean hasAnnotation(TypeX ofType) {
+ return answer;
+ }
+
+ }
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM Corporation.
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * ******************************************************************/
-package org.aspectj.weaver.patterns;
-
-import junit.framework.TestCase;
-
-/**
- * @author colyer
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-public class KindedAnnotationPointcutTestCase extends TestCase {
-
- public void testParsing() {
- PatternParser p = new PatternParser("@call(@String)");
- Pointcut pc = p.parsePointcut();
- assertTrue(pc instanceof KindedAnnotationPointcut);
- }
-}
suite.addTestSuite(HandlerTestCase.class);
suite.addTestSuite(KindedTestCase.class);
suite.addTestSuite(WithinCodeTestCase.class);
+ suite.addTestSuite(AnnotationPatternTestCase.class);
//$JUnit-END$
return suite;
}
public PatternsTests(String name) { super(name); }
+
}