Class TreeContext

java.lang.Object
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
  • Method Details

    • getUserdata

      public Map<Object,List<Object>> getUserdata()
      Returns the user data attached to this context.
      Returns:
      the user data map
    • putUserdata

      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
    • getUserdata

      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
    • getUserdata

      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
    • getParent

      public TreeContext getParent()
      Returns the parent traversal context.
      Returns:
      the parent context, or null
    • getNode

      public ASTNode getNode()
      Returns the AST node represented by this context.
      Returns:
      the current AST node
    • fork

      public TreeContext fork(ASTNode node)
      Creates a child context for the supplied node.
      Parameters:
      node - the child node
      Returns:
      the child context
    • matches

      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
    • matches

      public boolean matches(@DelegatesTo(value=ASTNode.class,strategy=1) Closure<Boolean> predicate)
      Tests the current node with the supplied closure predicate.
      Parameters:
      predicate - the predicate to apply
      Returns:
      true if the predicate matches
    • getSiblings

      public List<TreeContext> getSiblings()
      Returns the child contexts created from this node.
      Returns:
      the sibling list
    • getOnPopHandlers

      public List<TreeContextAction> getOnPopHandlers()
      Returns handlers invoked when this context is popped.
      Returns:
      the registered handlers
    • afterVisit

      public void afterVisit(TreeContextAction action)
      Registers a handler to invoke after the node is visited.
      Parameters:
      action - the handler to register
    • afterVisit

      public void afterVisit(@DelegatesTo(value=TreeContext.class,strategy=1) Closure<?> action)
      Registers a closure to invoke after the node is visited.
      Parameters:
      action - the handler to register
    • setReplacement

      public void setReplacement(Expression replacement)
      Replaces the current expression node when this context is popped.
      Parameters:
      replacement - the replacement expression
    • getReplacement

      public Expression getReplacement()
      Returns the replacement expression for this context.
      Returns:
      the replacement expression, or null
    • toString

      public String toString()
      Returns a string form containing the current node and its parent path.
      Overrides:
      toString in class Object
      Returns:
      the context description