Package: org.codehaus.groovy.macro.matcher

## [Java] Class TreeContext

- org.codehaus.groovy.macro.matcher.TreeContext

-     public class TreeContext
      extends Object

  Holds the current AST node together with its traversal context.

  Since:
    2.5.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `afterVisit(TreeContextAction action)` Registers a handler to invoke after the node is visited.
    `` | `public void` | `afterVisit(Closure<?> action)` Registers a closure to invoke after the node is visited.
    `` | `public TreeContext` | `fork(ASTNode node)` Creates a child context for the supplied node.
    `` | `public ASTNode` | `getNode()` Returns the AST node represented by this context.
    `` | `public List<TreeContextAction>` | `getOnPopHandlers()` Returns handlers invoked when this context is popped.
    `` | `public TreeContext` | `getParent()` Returns the parent traversal context.
    `` | `public Expression` | `getReplacement()` Returns the replacement expression for this context.
    `` | `public List<TreeContext>` | `getSiblings()` Returns the child contexts created from this node.
    `` | `public Map<Object, List<Object>>` | `getUserdata()` Returns the user data attached to this context.
    `` | `public List<Object>` | `getUserdata(Object key)` Returns user data for the supplied key, searching parent contexts by default.
    `` | `public List<Object>` | `getUserdata(Object key, boolean searchParent)` Returns user data for the supplied key.
    `` | `public boolean` | `matches(ASTNodePredicate predicate)` Tests the current node with the supplied predicate.
    `` | `public boolean` | `matches(Closure<Boolean> predicate)` Tests the current node with the supplied closure predicate.
    `` | `public void` | `putUserdata(Object key, Object value)` Appends a user data value for the supplied key.
    `` | `public void` | `setReplacement(Expression replacement)` Replaces the current expression node when this context is popped.
    `` | `public String` | `toString()` Returns a string form containing the current node and its parent path.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public void afterVisit(TreeContextAction action)

      Registers a handler to invoke after the node is visited.

      Parameters:
        `action` - the handler to register

    - #### public void afterVisit(@DelegatesTo(value=TreeContext.class, strategy=Closure.DELEGATE_FIRST)
      Closure<?> action)

      Registers a closure to invoke after the node is visited.

      Parameters:
        `action` - the handler to register

    - #### public TreeContext fork(ASTNode node)

      Creates a child context for the supplied node.

      Parameters:
        `node` - the child node
      Returns:
        the child context

    - #### public ASTNode getNode()

      Returns the AST node represented by this context.

      Returns:
        the current AST node

    - #### public List<TreeContextAction> getOnPopHandlers()

      Returns handlers invoked when this context is popped.

      Returns:
        the registered handlers

    - #### public TreeContext getParent()

      Returns the parent traversal context.

      Returns:
        the parent context, or `null`

    - #### public Expression getReplacement()

      Returns the replacement expression for this context.

      Returns:
        the replacement expression, or `null`

    - #### public List<TreeContext> getSiblings()

      Returns the child contexts created from this node.

      Returns:
        the sibling list

    - #### public Map<Object, List<Object>> getUserdata()

      Returns the user data attached to this context.

      Returns:
        the user data map

    - #### public List<Object> getUserdata(Object key)

      Returns user data for the supplied key, searching parent contexts by default.

      Parameters:
        `key` - the user data key
      Returns:
        the associated values, or `null`

    - #### public List<Object> getUserdata(Object key, boolean searchParent)

      Returns user data for the supplied key.

      Parameters:
        `key` - the user data key
        `searchParent` - whether to search parent contexts
      Returns:
        the associated values, or `null`

    - #### public boolean matches(ASTNodePredicate predicate)

      Tests the current node with the supplied predicate.

      Parameters:
        `predicate` - the predicate to apply
      Returns:
        `true` if the predicate matches

    - #### public boolean matches(@DelegatesTo(value=ASTNode.class, strategy=Closure.DELEGATE_FIRST)
      Closure<Boolean> predicate)

      Tests the current node with the supplied closure predicate.

      Parameters:
        `predicate` - the predicate to apply
      Returns:
        `true` if the predicate matches

    - #### public void putUserdata(Object key, Object value)

      Appends a user data value for the supplied key.

      Parameters:
        `key` - the user data key
        `value` - the value to add

    - #### public void setReplacement(Expression replacement)

      Replaces the current expression node when this context is popped.

      Parameters:
        `replacement` - the replacement expression

    - #### public String toString()

      Returns a string form containing the current node and its parent path.

      Returns:
        the context description