diff options
author | aclement <aclement> | 2009-10-06 21:07:23 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-10-06 21:07:23 +0000 |
commit | 9e7994865033f0e80b948e94f1ad761c54c5db2b (patch) | |
tree | 22f9772758c87fabac7ef2583bd3ae651dc04ad6 /org.aspectj.matcher/testsrc/org/aspectj/weaver | |
parent | 8808125e1f90ef9c7ca813858d291ecb973d651d (diff) | |
download | aspectj-9e7994865033f0e80b948e94f1ad761c54c5db2b.tar.gz aspectj-9e7994865033f0e80b948e94f1ad761c54c5db2b.zip |
291523: annotation pattern parsing changes for (@a.b.c.Foo *)
Diffstat (limited to 'org.aspectj.matcher/testsrc/org/aspectj/weaver')
-rw-r--r-- | org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/DumpPointcutVisitor.java | 1056 | ||||
-rw-r--r-- | org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java | 26 |
2 files changed, 516 insertions, 566 deletions
diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/DumpPointcutVisitor.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/DumpPointcutVisitor.java index ab3fddab0..621e5f30e 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/DumpPointcutVisitor.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/DumpPointcutVisitor.java @@ -12,532 +12,496 @@ package org.aspectj.weaver.patterns; import org.aspectj.weaver.Member; -import org.aspectj.weaver.patterns.AndAnnotationTypePattern; -import org.aspectj.weaver.patterns.AndPointcut; -import org.aspectj.weaver.patterns.AndTypePattern; -import org.aspectj.weaver.patterns.AnnotationPatternList; -import org.aspectj.weaver.patterns.AnnotationPointcut; -import org.aspectj.weaver.patterns.AnnotationTypePattern; -import org.aspectj.weaver.patterns.AnyAnnotationTypePattern; -import org.aspectj.weaver.patterns.AnyTypePattern; -import org.aspectj.weaver.patterns.AnyWithAnnotationTypePattern; -import org.aspectj.weaver.patterns.ArgsAnnotationPointcut; -import org.aspectj.weaver.patterns.ArgsPointcut; -import org.aspectj.weaver.patterns.BindingAnnotationTypePattern; -import org.aspectj.weaver.patterns.BindingTypePattern; -import org.aspectj.weaver.patterns.CflowPointcut; -import org.aspectj.weaver.patterns.ConcreteCflowPointcut; -import org.aspectj.weaver.patterns.DeclareAnnotation; -import org.aspectj.weaver.patterns.DeclareErrorOrWarning; -import org.aspectj.weaver.patterns.DeclareParents; -import org.aspectj.weaver.patterns.DeclarePrecedence; -import org.aspectj.weaver.patterns.DeclareSoft; -import org.aspectj.weaver.patterns.DumpPointcutVisitor; -import org.aspectj.weaver.patterns.EllipsisAnnotationTypePattern; -import org.aspectj.weaver.patterns.EllipsisTypePattern; -import org.aspectj.weaver.patterns.ExactAnnotationTypePattern; -import org.aspectj.weaver.patterns.ExactTypePattern; -import org.aspectj.weaver.patterns.HandlerPointcut; -import org.aspectj.weaver.patterns.HasMemberTypePattern; -import org.aspectj.weaver.patterns.IfPointcut; -import org.aspectj.weaver.patterns.KindedPointcut; -import org.aspectj.weaver.patterns.ModifiersPattern; -import org.aspectj.weaver.patterns.NamePattern; -import org.aspectj.weaver.patterns.NoTypePattern; -import org.aspectj.weaver.patterns.NotAnnotationTypePattern; -import org.aspectj.weaver.patterns.NotPointcut; -import org.aspectj.weaver.patterns.NotTypePattern; -import org.aspectj.weaver.patterns.OrAnnotationTypePattern; -import org.aspectj.weaver.patterns.OrPointcut; -import org.aspectj.weaver.patterns.OrTypePattern; -import org.aspectj.weaver.patterns.ParserException; -import org.aspectj.weaver.patterns.PatternNode; -import org.aspectj.weaver.patterns.PatternNodeVisitor; -import org.aspectj.weaver.patterns.PatternParser; -import org.aspectj.weaver.patterns.PerCflow; -import org.aspectj.weaver.patterns.PerFromSuper; -import org.aspectj.weaver.patterns.PerObject; -import org.aspectj.weaver.patterns.PerSingleton; -import org.aspectj.weaver.patterns.PerTypeWithin; -import org.aspectj.weaver.patterns.Pointcut; -import org.aspectj.weaver.patterns.ReferencePointcut; -import org.aspectj.weaver.patterns.SignaturePattern; -import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut; -import org.aspectj.weaver.patterns.ThisOrTargetPointcut; -import org.aspectj.weaver.patterns.ThrowsPattern; -import org.aspectj.weaver.patterns.TypePattern; -import org.aspectj.weaver.patterns.TypePatternList; -import org.aspectj.weaver.patterns.TypeVariablePattern; -import org.aspectj.weaver.patterns.TypeVariablePatternList; -import org.aspectj.weaver.patterns.WildAnnotationTypePattern; -import org.aspectj.weaver.patterns.WildTypePattern; -import org.aspectj.weaver.patterns.WithinAnnotationPointcut; -import org.aspectj.weaver.patterns.WithinCodeAnnotationPointcut; -import org.aspectj.weaver.patterns.WithinPointcut; -import org.aspectj.weaver.patterns.WithincodePointcut; /** * A sample toString like visitor that helps understanding the AST tree structure organization - * + * * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> */ public class DumpPointcutVisitor implements PatternNodeVisitor { - private StringBuffer sb = new StringBuffer(); - public String get() { - return sb.toString(); - } + private StringBuffer sb = new StringBuffer(); + + public String get() { + return sb.toString(); + } + + private void append(Object o) { + sb.append(o.toString()); + } - private void append(Object o) { - sb.append(o.toString()); - } - private void append(char c) { sb.append(c); } - /** - * This method helps maintaining the API and raises warning when PatternNode subclasses do not - * implement the visitor pattern - * - * @param node - * @param data - * @return - */ - public Object visit(PatternNode node, Object data) { - System.err.println("Should implement: " + node.getClass()); - return null; - } - - public Object visit(AnyTypePattern node, Object data) { - append('*'); - return null; - } - - public Object visit(NoTypePattern node, Object data) { - append(node.toString());//TODO no idea when this one is used - return null; - } - - public Object visit(EllipsisTypePattern node, Object data) { - append(node.toString()); - return null; - } - - public Object visit(AnyWithAnnotationTypePattern node, Object data) { - node.annotationPattern.accept(this, data); - append(" *"); - return null; - } - - public Object visit(AnyAnnotationTypePattern node, Object data) { - //@ANY : ignore - append('*'); - return null; - } - - public Object visit(EllipsisAnnotationTypePattern node, Object data) { - append(".."); - return null; - } - - public Object visit(AndAnnotationTypePattern node, Object data) { - node.getLeft().accept(this, data); - append(' '); - node.getRight().accept(this, data); - return null; - } - - public Object visit(AndPointcut node, Object data) { - append('('); - node.getLeft().accept(this, data); - append(" && "); - node.getRight().accept(this, data); - append(')'); - return null; - } - - public Object visit(AndTypePattern node, Object data) { - append('('); - node.getLeft().accept(this, data); - append(" && "); - node.getRight().accept(this, data); - append(')'); - return null; - } - - public Object visit(AnnotationPatternList node, Object data) { - AnnotationTypePattern[] annotations = node.getAnnotationPatterns(); - for (int i = 0; i < annotations.length; i++) { - if (i>0) append(", ");//Note: list is ",", and is " " separated for annotations - annotations[i].accept(this, data); - } - return null; - } - - public Object visit(AnnotationPointcut node, Object data) { - append("@annotation("); - node.getAnnotationTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(ArgsAnnotationPointcut node, Object data) { - append("@args("); - node.getArguments().accept(this, data); - append(')'); - return null; - } - - public Object visit(ArgsPointcut node, Object data) { - append("args("); - node.getArguments().accept(this, data); - append(')'); - return null; - } - - public Object visit(BindingAnnotationTypePattern node, Object data) { - append(node); - return null; - } - - public Object visit(BindingTypePattern node, Object data) { - append(node); - return null; - } - - public Object visit(CflowPointcut node, Object data) { - append(node.isCflowBelow()?"cflowbelow(":"cflow("); - node.getEntry().accept(this, data); - append(')'); - return null; - } - - public Object visit(ExactAnnotationTypePattern node, Object data) { - //append('@'); // since @annotation(@someAnno) cannot be parsed anymore - append(node.getAnnotationType().getName()); - return null; - } - - public Object visit(ExactTypePattern node, Object data) { - if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { - append('('); - node.getAnnotationPattern().accept(this, data); - append(' '); - } - - String typeString = node.getType().toString(); - if (node.isVarArgs()) typeString = typeString.substring(0, typeString.lastIndexOf('['));//TODO AV - ugly - append(typeString); - if (node.isIncludeSubtypes()) append('+'); - if (node.isVarArgs()) append("..."); - if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { - append(')'); - } - return null; - } - - public Object visit(KindedPointcut node, Object data) { - append(node.getKind().getSimpleName()); - append('('); - node.getSignature().accept(this, data); - append(')'); - return null; - } - - public Object visit(ModifiersPattern node, Object data) { - append(node.toString());//note: node takes care of forbidden mods - return null; - } - - public Object visit(NamePattern node, Object data) { - append(node.toString()); - return null; - } - - public Object visit(NotAnnotationTypePattern node, Object data) { - append("!"); - node.getNegatedPattern().accept(this, data); - return null; - } - - public Object visit(NotPointcut node, Object data) { - append("!("); - node.getNegatedPointcut().accept(this, data); - append(')'); - return null; - } - - public Object visit(NotTypePattern node, Object data) { - append("!("); - node.getNegatedPattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(OrAnnotationTypePattern node, Object data) { - append('('); - node.getLeft().accept(this, data); - append(" || "); - node.getRight().accept(this, data); - append(')'); - return null; - } - - public Object visit(OrPointcut node, Object data) { - append('('); - node.getLeft().accept(this, data); - append(" || "); - node.getRight().accept(this, data); - append(')'); - return null; - } - - public Object visit(OrTypePattern node, Object data) { - append('('); - node.getLeft().accept(this, data); - append(" || "); - node.getRight().accept(this, data); - append(')'); - return null; - } - - public Object visit(ReferencePointcut node, Object data) { - append(node.toString()); - return null; - } - - public Object visit(SignaturePattern node, Object data) { - if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { - node.getAnnotationPattern().accept(this, data); - append(' '); - } - - if (node.getModifiers() != ModifiersPattern.ANY) { - node.getModifiers().accept(this, data); - append(' '); - } - - if (node.getKind() == Member.STATIC_INITIALIZATION) { - node.getDeclaringType().accept(this, data); - } else if (node.getKind() == Member.HANDLER) { - append("handler("); - node.getParameterTypes().get(0).accept(this, data);//Note: we know we have 1 child - append(')'); - } else { - if (!(node.getKind() == Member.CONSTRUCTOR)) { - node.getReturnType().accept(this, data); - append(' '); - } - if (node.getDeclaringType() != TypePattern.ANY) { - node.getDeclaringType().accept(this, data); - append('.'); - } - if (node.getKind() == Member.CONSTRUCTOR) { - append("new"); - } else { - node.getName().accept(this, data); - } - if (node.getKind() == Member.METHOD || node.getKind() == Member.CONSTRUCTOR) { - append('('); - node.getParameterTypes().accept(this, data); - append(')'); - } - if (node.getThrowsPattern() != null) { - append(' '); - node.getThrowsPattern().accept(this, data); - } - } - return null; - } - - public Object visit(ThisOrTargetAnnotationPointcut node, Object data) { - append(node.isThis() ? "@this(" : "@target("); - node.getAnnotationTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(ThisOrTargetPointcut node, Object data) { - append(node.isThis() ? "this(" : "target("); - node.getType().accept(this, data); - append(')'); - return null; - } - - // Note: a visitor instance is not thread safe so should not be shared - private boolean inThrowsForbidden = false; - - public Object visit(ThrowsPattern node, Object data) { - if (node == ThrowsPattern.ANY) return null; - - append("throws "); - node.getRequired().accept(this, data); - if (node.getForbidden().size() > 0) { - // a hack since throws !(A, B) cannot be parsed - try { - inThrowsForbidden = true; - node.getForbidden().accept(this, data); - } finally { - inThrowsForbidden = false; - } - } - return null; - } - - public Object visit(TypePatternList node, Object data) { - if (node.getTypePatterns().length == 0) return null; - - TypePattern[] typePatterns = node.getTypePatterns(); - for (int i = 0; i < typePatterns.length; i++) { - TypePattern typePattern = typePatterns[i]; - if (i > 0) append(", "); - if (inThrowsForbidden) append('!'); - typePattern.accept(this, data); - } - return null; - } - - public Object visit(WildAnnotationTypePattern node, Object data) { - append("@("); - node.getTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(WildTypePattern node, Object data) { - if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { - append('('); - node.getAnnotationPattern().accept(this, data); - append(' '); - } - NamePattern[] namePatterns = node.getNamePatterns(); - for (int i=0; i < namePatterns.length; i++) { - if (namePatterns[i] == null) { - append('.');//FIXME mh, error prone, can't we have a nullNamePattern ? - } else { - if (i > 0) append('.'); - namePatterns[i].accept(this, data); - } - } - if (node.isIncludeSubtypes()) append('+'); - if (node.isVarArgs()) append("..."); - if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { - append(')'); - } - return null; - } - - public Object visit(WithinAnnotationPointcut node, Object data) { - append("@within("); - node.getAnnotationTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(WithinCodeAnnotationPointcut node, Object data) { - append("@withincode("); - node.getAnnotationTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(WithinPointcut node, Object data) { - append("within("); - node.getTypePattern().accept(this, data); - append(')'); - return null; - } - - public Object visit(WithincodePointcut node, Object data) { - append("withincode("); - node.getSignature().accept(this, data); - append(')'); - return null; - } - - public Object visit(Pointcut.MatchesNothingPointcut node, Object data) { - append("");//TODO shouldn't that be a "false" ? - return null; - } - - - //-------------- perX - - public Object visit(PerCflow node, Object data) { - append(node); - return null; - } - - public Object visit(PerFromSuper node, Object data) { - append(node); - return null; - } - - public Object visit(PerObject node, Object data) { - append(node); - return null; - } - - public Object visit(PerSingleton node, Object data) { - append(node); - return null; - } - - public Object visit(PerTypeWithin node, Object data) { - append(node); - return null; - } - - // ------------- declare X - - public Object visit(DeclareAnnotation node, Object data) { - append(node); - return null; - } - - public Object visit(DeclareErrorOrWarning node, Object data) { - append(node); - return null; - } - - public Object visit(DeclareParents node, Object data) { - append(node); - return null; - } - - public Object visit(DeclarePrecedence node, Object data) { - append(node); - return null; - } - - public Object visit(DeclareSoft node, Object data) { - append(node); - return null; - } - - // ----------- misc - - public Object visit(ConcreteCflowPointcut node, Object data) { - append(node); - return null; - } - - public Object visit(HandlerPointcut node, Object data) { - append(node); - return null; - } - - public Object visit(IfPointcut node, Object data) { - append(node); - return null; - } - + /** + * This method helps maintaining the API and raises warning when PatternNode subclasses do not implement the visitor pattern + * + * @param node + * @param data + * @return + */ + public Object visit(PatternNode node, Object data) { + System.err.println("Should implement: " + node.getClass()); + return null; + } + + public Object visit(AnyTypePattern node, Object data) { + append('*'); + return null; + } + + public Object visit(NoTypePattern node, Object data) { + append(node.toString());// TODO no idea when this one is used + return null; + } + + public Object visit(EllipsisTypePattern node, Object data) { + append(node.toString()); + return null; + } + + public Object visit(AnyWithAnnotationTypePattern node, Object data) { + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append('('); + } + node.annotationPattern.accept(this, data); + append(" *"); + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append(')'); + } + return null; + } + + public Object visit(AnyAnnotationTypePattern node, Object data) { + // @ANY : ignore + append('*'); + return null; + } + + public Object visit(EllipsisAnnotationTypePattern node, Object data) { + append(".."); + return null; + } + + public Object visit(AndAnnotationTypePattern node, Object data) { + node.getLeft().accept(this, data); + append(' '); + node.getRight().accept(this, data); + return null; + } + + public Object visit(AndPointcut node, Object data) { + append('('); + node.getLeft().accept(this, data); + append(" && "); + node.getRight().accept(this, data); + append(')'); + return null; + } + + public Object visit(AndTypePattern node, Object data) { + append('('); + node.getLeft().accept(this, data); + append(" && "); + node.getRight().accept(this, data); + append(')'); + return null; + } + + public Object visit(AnnotationPatternList node, Object data) { + AnnotationTypePattern[] annotations = node.getAnnotationPatterns(); + for (int i = 0; i < annotations.length; i++) { + if (i > 0) { + append(", ");// Note: list is ",", and is " " separated for annotations + } + annotations[i].accept(this, data); + } + return null; + } + + public Object visit(AnnotationPointcut node, Object data) { + append("@annotation("); + node.getAnnotationTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(ArgsAnnotationPointcut node, Object data) { + append("@args("); + node.getArguments().accept(this, data); + append(')'); + return null; + } + + public Object visit(ArgsPointcut node, Object data) { + append("args("); + node.getArguments().accept(this, data); + append(')'); + return null; + } + + public Object visit(BindingAnnotationTypePattern node, Object data) { + append(node); + return null; + } + + public Object visit(BindingTypePattern node, Object data) { + append(node); + return null; + } + + public Object visit(CflowPointcut node, Object data) { + append(node.isCflowBelow() ? "cflowbelow(" : "cflow("); + node.getEntry().accept(this, data); + append(')'); + return null; + } + + public Object visit(ExactAnnotationTypePattern node, Object data) { + // append('@'); // since @annotation(@someAnno) cannot be parsed anymore + append(node.getAnnotationType().getName()); + return null; + } + + public Object visit(ExactTypePattern node, Object data) { + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append('('); + node.getAnnotationPattern().accept(this, data); + append(' '); + } + + String typeString = node.getType().toString(); + if (node.isVarArgs()) { + typeString = typeString.substring(0, typeString.lastIndexOf('['));// TODO AV - ugly + } + append(typeString); + if (node.isIncludeSubtypes()) { + append('+'); + } + if (node.isVarArgs()) { + append("..."); + } + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append(')'); + } + return null; + } + + public Object visit(KindedPointcut node, Object data) { + append(node.getKind().getSimpleName()); + append('('); + node.getSignature().accept(this, data); + append(')'); + return null; + } + + public Object visit(ModifiersPattern node, Object data) { + append(node.toString());// note: node takes care of forbidden mods + return null; + } + + public Object visit(NamePattern node, Object data) { + append(node.toString()); + return null; + } + + public Object visit(NotAnnotationTypePattern node, Object data) { + append("!"); + node.getNegatedPattern().accept(this, data); + return null; + } + + public Object visit(NotPointcut node, Object data) { + append("!("); + node.getNegatedPointcut().accept(this, data); + append(')'); + return null; + } + + public Object visit(NotTypePattern node, Object data) { + append("!("); + node.getNegatedPattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(OrAnnotationTypePattern node, Object data) { + append('('); + node.getLeft().accept(this, data); + append(" || "); + node.getRight().accept(this, data); + append(')'); + return null; + } + + public Object visit(OrPointcut node, Object data) { + append('('); + node.getLeft().accept(this, data); + append(" || "); + node.getRight().accept(this, data); + append(')'); + return null; + } + + public Object visit(OrTypePattern node, Object data) { + append('('); + node.getLeft().accept(this, data); + append(" || "); + node.getRight().accept(this, data); + append(')'); + return null; + } + + public Object visit(ReferencePointcut node, Object data) { + append(node.toString()); + return null; + } + + public Object visit(SignaturePattern node, Object data) { + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + node.getAnnotationPattern().accept(this, data); + append(' '); + } + + if (node.getModifiers() != ModifiersPattern.ANY) { + node.getModifiers().accept(this, data); + append(' '); + } + + if (node.getKind() == Member.STATIC_INITIALIZATION) { + node.getDeclaringType().accept(this, data); + } else if (node.getKind() == Member.HANDLER) { + append("handler("); + node.getParameterTypes().get(0).accept(this, data);// Note: we know we have 1 child + append(')'); + } else { + if (!(node.getKind() == Member.CONSTRUCTOR)) { + node.getReturnType().accept(this, data); + append(' '); + } + if (node.getDeclaringType() != TypePattern.ANY) { + node.getDeclaringType().accept(this, data); + append('.'); + } + if (node.getKind() == Member.CONSTRUCTOR) { + append("new"); + } else { + node.getName().accept(this, data); + } + if (node.getKind() == Member.METHOD || node.getKind() == Member.CONSTRUCTOR) { + append('('); + node.getParameterTypes().accept(this, data); + append(')'); + } + if (node.getThrowsPattern() != null) { + append(' '); + node.getThrowsPattern().accept(this, data); + } + } + return null; + } + + public Object visit(ThisOrTargetAnnotationPointcut node, Object data) { + append(node.isThis() ? "@this(" : "@target("); + node.getAnnotationTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(ThisOrTargetPointcut node, Object data) { + append(node.isThis() ? "this(" : "target("); + node.getType().accept(this, data); + append(')'); + return null; + } + + // Note: a visitor instance is not thread safe so should not be shared + private boolean inThrowsForbidden = false; + + public Object visit(ThrowsPattern node, Object data) { + if (node == ThrowsPattern.ANY) { + return null; + } + + append("throws "); + node.getRequired().accept(this, data); + if (node.getForbidden().size() > 0) { + // a hack since throws !(A, B) cannot be parsed + try { + inThrowsForbidden = true; + node.getForbidden().accept(this, data); + } finally { + inThrowsForbidden = false; + } + } + return null; + } + + public Object visit(TypePatternList node, Object data) { + if (node.getTypePatterns().length == 0) { + return null; + } + + TypePattern[] typePatterns = node.getTypePatterns(); + for (int i = 0; i < typePatterns.length; i++) { + TypePattern typePattern = typePatterns[i]; + if (i > 0) { + append(", "); + } + if (inThrowsForbidden) { + append('!'); + } + typePattern.accept(this, data); + } + return null; + } + + public Object visit(WildAnnotationTypePattern node, Object data) { + append("@("); + node.getTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(WildTypePattern node, Object data) { + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append('('); + node.getAnnotationPattern().accept(this, data); + append(' '); + } + NamePattern[] namePatterns = node.getNamePatterns(); + for (int i = 0; i < namePatterns.length; i++) { + if (namePatterns[i] == null) { + append('.');// FIXME mh, error prone, can't we have a nullNamePattern ? + } else { + if (i > 0) { + append('.'); + } + namePatterns[i].accept(this, data); + } + } + if (node.isIncludeSubtypes()) { + append('+'); + } + if (node.isVarArgs()) { + append("..."); + } + if (node.getAnnotationPattern() != AnnotationTypePattern.ANY) { + append(')'); + } + return null; + } + + public Object visit(WithinAnnotationPointcut node, Object data) { + append("@within("); + node.getAnnotationTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(WithinCodeAnnotationPointcut node, Object data) { + append("@withincode("); + node.getAnnotationTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(WithinPointcut node, Object data) { + append("within("); + node.getTypePattern().accept(this, data); + append(')'); + return null; + } + + public Object visit(WithincodePointcut node, Object data) { + append("withincode("); + node.getSignature().accept(this, data); + append(')'); + return null; + } + + public Object visit(Pointcut.MatchesNothingPointcut node, Object data) { + append("");// TODO shouldn't that be a "false" ? + return null; + } + + // -------------- perX + + public Object visit(PerCflow node, Object data) { + append(node); + return null; + } + + public Object visit(PerFromSuper node, Object data) { + append(node); + return null; + } + + public Object visit(PerObject node, Object data) { + append(node); + return null; + } + + public Object visit(PerSingleton node, Object data) { + append(node); + return null; + } + + public Object visit(PerTypeWithin node, Object data) { + append(node); + return null; + } + + // ------------- declare X + + public Object visit(DeclareAnnotation node, Object data) { + append(node); + return null; + } + + public Object visit(DeclareErrorOrWarning node, Object data) { + append(node); + return null; + } + + public Object visit(DeclareParents node, Object data) { + append(node); + return null; + } + + public Object visit(DeclarePrecedence node, Object data) { + append(node); + return null; + } + + public Object visit(DeclareSoft node, Object data) { + append(node); + return null; + } + + // ----------- misc + + public Object visit(ConcreteCflowPointcut node, Object data) { + append(node); + return null; + } + + public Object visit(HandlerPointcut node, Object data) { + append(node); + return null; + } + + public Object visit(IfPointcut node, Object data) { + append(node); + return null; + } + public Object visit(TypeVariablePattern node, Object data) { append(node); return null; } - + public Object visit(TypeVariablePatternList node, Object data) { append(node); return null; @@ -548,41 +512,41 @@ public class DumpPointcutVisitor implements PatternNodeVisitor { return null; } - public static void check(String s) { - check(Pointcut.fromString(s), false); - } - - public static void check(PatternNode pc, boolean isTypePattern) { - DumpPointcutVisitor v1 = new DumpPointcutVisitor(); - pc.accept(v1, null); - - DumpPointcutVisitor v2 = new DumpPointcutVisitor(); - final PatternNode pc2; - if (isTypePattern) { - pc2 = new PatternParser(v1.get()).parseTypePattern(); - } else { - pc2 = Pointcut.fromString(v1.get()); - } - pc2.accept(v2, null); - - // at second parsing, the String form stay stable when parsed and parsed again - if (! v1.get().equals(v2.get())) { - throw new ParserException("Unstable back parsing for '"+pc+"', got '" + v1.get() + "' and '" + v2.get() + "'", null); - } - } - - public static void main(String args[]) throws Throwable { - String[] s = new String[]{ - //"@args(Foo, Goo, *, .., Moo)", - //"execution(* *())", - //"call(* *(int, Integer...))", - //"staticinitialization(@(Foo) @(Boo) @(Goo) Moo)", - "(if(true) && set(int BaseApp.i))" - - }; - for (int i = 0; i < s.length; i++) { - check(s[i]); - } - } + public static void check(String s) { + check(Pointcut.fromString(s), false); + } + + public static void check(PatternNode pc, boolean isTypePattern) { + DumpPointcutVisitor v1 = new DumpPointcutVisitor(); + pc.accept(v1, null); + + DumpPointcutVisitor v2 = new DumpPointcutVisitor(); + final PatternNode pc2; + if (isTypePattern) { + pc2 = new PatternParser(v1.get()).parseTypePattern(); + } else { + pc2 = Pointcut.fromString(v1.get()); + } + pc2.accept(v2, null); + + // at second parsing, the String form stay stable when parsed and parsed again + if (!v1.get().equals(v2.get())) { + throw new ParserException("Unstable back parsing for '" + pc + "', got '" + v1.get() + "' and '" + v2.get() + "'", null); + } + } + + public static void main(String args[]) throws Throwable { + String[] s = new String[] { + // "@args(Foo, Goo, *, .., Moo)", + // "execution(* *())", + // "call(* *(int, Integer...))", + // "staticinitialization(@(Foo) @(Boo) @(Goo) Moo)", + "(if(true) && set(int BaseApp.i))" + + }; + for (int i = 0; i < s.length; i++) { + check(s[i]); + } + } }
\ No newline at end of file diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java index 27e3c8a22..902e41c24 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java @@ -22,23 +22,6 @@ import java.util.Set; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; -import org.aspectj.weaver.patterns.AnnotationPointcut; -import org.aspectj.weaver.patterns.AnnotationTypePattern; -import org.aspectj.weaver.patterns.ExactTypePattern; -import org.aspectj.weaver.patterns.KindedPointcut; -import org.aspectj.weaver.patterns.ParserException; -import org.aspectj.weaver.patterns.PatternParser; -import org.aspectj.weaver.patterns.Pointcut; -import org.aspectj.weaver.patterns.TestScope; -import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut; -import org.aspectj.weaver.patterns.TypePattern; -import org.aspectj.weaver.patterns.TypePatternList; -import org.aspectj.weaver.patterns.TypeVariablePattern; -import org.aspectj.weaver.patterns.TypeVariablePatternList; -import org.aspectj.weaver.patterns.WildAnnotationTypePattern; -import org.aspectj.weaver.patterns.WildTypePattern; -import org.aspectj.weaver.patterns.WithinAnnotationPointcut; -import org.aspectj.weaver.patterns.WithinCodeAnnotationPointcut; import org.aspectj.weaver.reflect.ReflectionWorld; /** @@ -706,12 +689,14 @@ public class ParserTestCase extends PatternsTestCase { } private String getValueString(Pointcut pc) { - if (!(pc instanceof KindedPointcut)) + if (!(pc instanceof KindedPointcut)) { fail("Expected KindedPointcut but was " + pc.getClass()); + } KindedPointcut kpc = (KindedPointcut) pc; AnnotationTypePattern atp = kpc.getSignature().getAnnotationPattern(); - if (!(atp instanceof WildAnnotationTypePattern)) + if (!(atp instanceof WildAnnotationTypePattern)) { fail("Expected WildAnnotationTypePattern but was " + atp.getClass()); + } WildAnnotationTypePattern watp = (WildAnnotationTypePattern) atp; Map m = watp.annotationValues; Set keys = m.keySet(); @@ -722,8 +707,9 @@ public class ParserTestCase extends PatternsTestCase { for (Iterator iterator = orderedKeys.iterator(); iterator.hasNext();) { String object = (String) iterator.next(); sb.append(object).append("=").append(m.get(object)); - if (iterator.hasNext()) + if (iterator.hasNext()) { sb.append(","); + } } return sb.toString(); } |