Class TreeContext
java.lang.Object
org.codehaus.groovy.macro.matcher.TreeContext
Holds the current AST node together with its traversal context.
- Since:
- 2.5.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidafterVisit(Closure<?> action) Registers a closure to invoke after the node is visited.voidafterVisit(TreeContextAction action) Registers a handler to invoke after the node is visited.Creates a child context for the supplied node.getNode()Returns the AST node represented by this context.Returns handlers invoked when this context is popped.Returns the parent traversal context.Returns the replacement expression for this context.Returns the child contexts created from this node.Returns the user data attached to this context.getUserdata(Object key) Returns user data for the supplied key, searching parent contexts by default.getUserdata(Object key, boolean searchParent) Returns user data for the supplied key.booleanTests the current node with the supplied closure predicate.booleanmatches(ASTNodePredicate predicate) Tests the current node with the supplied predicate.voidputUserdata(Object key, Object value) Appends a user data value for the supplied key.voidsetReplacement(Expression replacement) Replaces the current expression node when this context is popped.toString()Returns a string form containing the current node and its parent path.
-
Method Details
-
getUserdata
Returns the user data attached to this context.- Returns:
- the user data map
-
putUserdata
Appends a user data value for the supplied key.- Parameters:
key- the user data keyvalue- the value to add
-
getUserdata
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
Returns user data for the supplied key.- Parameters:
key- the user data keysearchParent- whether to search parent contexts- Returns:
- the associated values, or
null
-
getParent
Returns the parent traversal context.- Returns:
- the parent context, or
null
-
getNode
Returns the AST node represented by this context.- Returns:
- the current AST node
-
fork
Creates a child context for the supplied node.- Parameters:
node- the child node- Returns:
- the child context
-
matches
Tests the current node with the supplied predicate.- Parameters:
predicate- the predicate to apply- Returns:
trueif the predicate matches
-
matches
Tests the current node with the supplied closure predicate.- Parameters:
predicate- the predicate to apply- Returns:
trueif the predicate matches
-
getSiblings
Returns the child contexts created from this node.- Returns:
- the sibling list
-
getOnPopHandlers
Returns handlers invoked when this context is popped.- Returns:
- the registered handlers
-
afterVisit
Registers a handler to invoke after the node is visited.- Parameters:
action- the handler to register
-
afterVisit
Registers a closure to invoke after the node is visited.- Parameters:
action- the handler to register
-
setReplacement
Replaces the current expression node when this context is popped.- Parameters:
replacement- the replacement expression
-
getReplacement
Returns the replacement expression for this context.- Returns:
- the replacement expression, or
null
-
toString
Returns a string form containing the current node and its parent path.
-