ASTMatcher (Groovy 5.0.0)

Package: org.codehaus.groovy.macro.matcher

## [Groovy] Class ASTMatcher

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

-     @AutoFinal
      @CompileStatic
      class ASTMatcher
      extends ContextualClassCodeVisitor

- - ### Field Summary

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

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `static List<TreeContext>` | `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<T> 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<? extends Expression> 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, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, 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

  - ### Method Detail

    - #### static List<TreeContext> 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.

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

    - #### <T> T ifConstraint(T defaultValue, @DelegatesTo(value: MatchingConstraints, strategy: Closure.DELEGATE_FIRST)
      Closure<T> 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

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

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

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

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

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

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

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

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

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

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

    - #### @Override
      @CompileDynamic
      void visitClassExpression(ClassExpression expression)

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

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

    - #### @Override
      @CompileDynamic
      void visitConstantExpression(ConstantExpression expression)

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

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

    - #### @Override
      @CompileDynamic
      void visitDeclarationExpression(DeclarationExpression expression)

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

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

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

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

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

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

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

    - #### @Override
      void visitListOfExpressions(List<? extends Expression> list)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    - #### static ASTNode withConstraints(ASTNode pattern, @DelegatesTo(value: MatchingConstraintsBuilder, strategy: Closure.DELEGATE_ONLY)
      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