Package: org.codehaus.groovy.macro.matcher

## [Groovy] Class ASTMatcher

- org.codehaus.groovy.macro.matcher.ASTMatcher

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `WILDCARD` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ASTMatcher ()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `static List` | `find(ASTNode node, ASTNode pattern)` Locates all nodes in the given AST which match the pattern AST.
    `` | `protected SourceUnit` | `getSourceUnit()`
    `<T>` | `T` | `ifConstraint(T defaultValue, Closure code)`
    `` | `static boolean` | `matches(ASTNode node, ASTNode pattern)` Matches an AST with another AST (pattern).
    `` | `void` | `visitAnnotations(AnnotatedNode node)`
    `` | `void` | `visitArrayExpression(ArrayExpression expression)`
    `` | `void` | `visitAttributeExpression(AttributeExpression expression)`
    `` | `void` | `visitBinaryExpression(BinaryExpression expression)`
    `` | `void` | `visitBitwiseNegationExpression(BitwiseNegationExpression expression)`
    `` | `void` | `visitBlockStatement(BlockStatement block)`
    `` | `void` | `visitBooleanExpression(BooleanExpression expression)`
    `` | `void` | `visitCastExpression(CastExpression expression)`
    `` | `void` | `visitClass(ClassNode node)`
    `` | `protected void` | `visitClassCodeContainer(Statement code)`
    `` | `void` | `visitClassExpression(ClassExpression expression)`
    `` | `void` | `visitClosureExpression(ClosureExpression expression)`
    `` | `void` | `visitClosureListExpression(ClosureListExpression cle)`
    `` | `void` | `visitConstantExpression(ConstantExpression expression)`
    `` | `void` | `visitConstructorCallExpression(ConstructorCallExpression call)`
    `` | `protected void` | `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
    `` | `void` | `visitDeclarationExpression(DeclarationExpression expression)`
    `` | `void` | `visitExpressionStatement(ExpressionStatement statement)`
    `` | `void` | `visitField(FieldNode node)`
    `` | `void` | `visitForLoop(ForStatement forLoop)`
    `` | `void` | `visitGStringExpression(GStringExpression expression)`
    `` | `void` | `visitIfElse(IfStatement ifElse)`
    `` | `void` | `visitImports(ModuleNode node)`
    `` | `void` | `visitListExpression(ListExpression expression)`
    `` | `void` | `visitListOfExpressions(List list)`
    `` | `void` | `visitMapEntryExpression(MapEntryExpression expression)`
    `` | `void` | `visitMapExpression(MapExpression expression)`
    `` | `void` | `visitMethodCallExpression(MethodCallExpression call)`
    `` | `void` | `visitMethodPointerExpression(MethodPointerExpression expression)`
    `` | `void` | `visitNotExpression(NotExpression expression)`
    `` | `protected void` | `visitObjectInitializerStatements(ClassNode node)`
    `` | `void` | `visitPackage(PackageNode node)`
    `` | `void` | `visitPostfixExpression(PostfixExpression expression)`
    `` | `void` | `visitPrefixExpression(PrefixExpression expression)`
    `` | `void` | `visitProperty(PropertyNode node)`
    `` | `void` | `visitPropertyExpression(PropertyExpression expression)`
    `` | `void` | `visitRangeExpression(RangeExpression expression)`
    `` | `void` | `visitSpreadExpression(SpreadExpression expression)`
    `` | `void` | `visitTernaryExpression(TernaryExpression expression)`
    `` | `void` | `visitTupleExpression(TupleExpression expression)`
    `` | `void` | `visitUnaryMinusExpression(UnaryMinusExpression expression)`
    `` | `void` | `visitUnaryPlusExpression(UnaryPlusExpression expression)`
    `` | `void` | `visitVariableExpression(VariableExpression expression)`
    `` | `void` | `visitWhileLoop(WhileStatement loop)`
    `` | `static ASTNode` | `withConstraints(ASTNode pattern, Closure constraintsSpec)` TODO: experimental!

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ContextualClassCodeVisitor` | `getLastContext, getSourceUnit, getTreeContext, getTreePath, matchByClass, pathMatches, pathUpTo, pathUpTo, pathUpTo, popContext, pushContext, pushContext, transform, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClass, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitConstructorOrMethod, visitContinueStatement, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitField, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitImports, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitNotExpression, visitPackage, visitPostfixExpression, visitPrefixExpression, visitProperty, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

- - ### Field Detail

    - #### public static final String WILDCARD

  - ### Constructor Detail

    - #### ASTMatcher()

  - ### Method Detail

    - #### static List find(ASTNode node, ASTNode pattern)

      Locates all nodes in the given AST which match the pattern AST. This operation can cost a lot, because it tries to match a sub-tree to every node of the AST.

      Parameters:
        `node` - an AST Node
        `pattern` - a pattern to be found somewhere in the AST
      Returns:
        a list of TreeContext, always not null.

    - #### @OverrideOverride protected SourceUnit getSourceUnit()

    - #### <T> T ifConstraint(T defaultValue, @DelegatesToDelegatesTo Closure code)

    - #### static boolean matches(ASTNode node, ASTNode pattern)

      Matches an AST with another AST (pattern). It will return true if the AST matches all the nodes from the pattern AST.

      Parameters:
        `node` - the AST we want to match with
        `pattern` - the pattern AST we want to match to
      Returns:
        true if this AST matches the pattern

    - #### @OverrideOverride void visitAnnotations(AnnotatedNode node)

    - #### @OverrideOverride void visitArrayExpression(ArrayExpression expression)

    - #### @OverrideOverride void visitAttributeExpression(AttributeExpression expression)

    - #### @OverrideOverride void visitBinaryExpression(BinaryExpression expression)

    - #### @OverrideOverride void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

    - #### @OverrideOverride void visitBlockStatement(BlockStatement block)

    - #### @OverrideOverride void visitBooleanExpression(BooleanExpression expression)

    - #### @OverrideOverride void visitCastExpression(CastExpression expression)

    - #### @OverrideOverride void visitClass(ClassNode node)

    - #### @OverrideOverride protected void visitClassCodeContainer(Statement code)

    - #### @OverrideOverride @CompileDynamicCompileDynamic void visitClassExpression(ClassExpression expression)

    - #### @OverrideOverride void visitClosureExpression(ClosureExpression expression)

    - #### @OverrideOverride void visitClosureListExpression(ClosureListExpression cle)

    - #### @OverrideOverride @CompileDynamicCompileDynamic void visitConstantExpression(ConstantExpression expression)

    - #### @OverrideOverride void visitConstructorCallExpression(ConstructorCallExpression call)

    - #### @OverrideOverride protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

    - #### @OverrideOverride @CompileDynamicCompileDynamic void visitDeclarationExpression(DeclarationExpression expression)

    - #### @OverrideOverride void visitExpressionStatement(ExpressionStatement statement)

    - #### @OverrideOverride void visitField(FieldNode node)

    - #### @OverrideOverride void visitForLoop(ForStatement forLoop)

    - #### @OverrideOverride void visitGStringExpression(GStringExpression expression)

    - #### @OverrideOverride void visitIfElse(IfStatement ifElse)

    - #### @OverrideOverride void visitImports(ModuleNode node)

    - #### @OverrideOverride void visitListExpression(ListExpression expression)

    - #### @OverrideOverride void visitListOfExpressions(List list)

    - #### @OverrideOverride void visitMapEntryExpression(MapEntryExpression expression)

    - #### @OverrideOverride void visitMapExpression(MapExpression expression)

    - #### @OverrideOverride void visitMethodCallExpression(MethodCallExpression call)

    - #### @OverrideOverride void visitMethodPointerExpression(MethodPointerExpression expression)

    - #### @OverrideOverride void visitNotExpression(NotExpression expression)

    - #### @OverrideOverride protected void visitObjectInitializerStatements(ClassNode node)

    - #### @OverrideOverride void visitPackage(PackageNode node)

    - #### @OverrideOverride void visitPostfixExpression(PostfixExpression expression)

    - #### @OverrideOverride void visitPrefixExpression(PrefixExpression expression)

    - #### @OverrideOverride void visitProperty(PropertyNode node)

    - #### @OverrideOverride void visitPropertyExpression(PropertyExpression expression)

    - #### @OverrideOverride void visitRangeExpression(RangeExpression expression)

    - #### @OverrideOverride void visitSpreadExpression(SpreadExpression expression)

    - #### @OverrideOverride void visitTernaryExpression(TernaryExpression expression)

    - #### @OverrideOverride void visitTupleExpression(TupleExpression expression)

    - #### @OverrideOverride void visitUnaryMinusExpression(UnaryMinusExpression expression)

    - #### @OverrideOverride void visitUnaryPlusExpression(UnaryPlusExpression expression)

    - #### @OverrideOverride void visitVariableExpression(VariableExpression expression)

    - #### @OverrideOverride void visitWhileLoop(WhileStatement loop)

    - #### static ASTNode withConstraints(ASTNode pattern, @DelegatesToDelegatesTo Closure constraintsSpec)

      TODO: experimental! Annotates an AST node with matching contraints. This method should be called on an AST intended to be used as a pattern only. It will put node metadata on the AST node allowing customized behavior in pattern matching.

      Parameters:
        `pattern` - a pattern AST
        `constraintsSpec` - a closure specification of matching constraints
      Returns:
        the same pattern, annotated with constraints