public class NodeTransformer extends java.lang.Object implements ExprTreeVisitor
ExprTreeVisitor.Status| Constructor and Description |
|---|
NodeTransformer()
Create new transformer instance containing no substitution rules.
|
NodeTransformer(java.util.Map<java.lang.Enum<?>,TransformerRule> rules)
Create new transformer instance with given substitutions rules.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRule(java.lang.Enum<?> opId,
TransformerRule rule)
Add substitution rule.
|
int[] |
getOperandOrder()
Returns an array of operand indexes that specify in which order the operands of
the currently visited operator should be visited.
|
java.util.List<Node> |
getResult()
Get collection of expression trees resulting from substitutions done during traversals.
|
ExprTreeVisitor.Status |
getStatus()
Returns the current status of the visitor.
|
void |
onBindingBegin(NodeBinding node)
Starts visiting a binding node.
|
void |
onBindingEnd(NodeBinding node)
Finishes visiting a binding node.
|
void |
onBindingListEnd(NodeBinding node)
Notifies that visiting a bound variables list finished.
|
void |
onBoundVariableBegin(NodeBinding node,
NodeVariable variable,
Node value)
Notifies that visiting a bound variable has started.
|
void |
onBoundVariableEnd(NodeBinding node,
NodeVariable variable,
Node value)
Notifies that visiting a bound variable has finished.
|
void |
onOperandBegin(NodeOperation expr,
Node operand,
int index)
Notifies that visiting an expression operand has started.
|
void |
onOperandEnd(NodeOperation expr,
Node operand,
int index)
Notifies that visiting an expression operand has finished.
|
void |
onOperationBegin(NodeOperation expr)
Starts visiting an operation node.
|
void |
onOperationEnd(NodeOperation expr)
Finishes visiting an operation node.
|
void |
onRootBegin()
Notifies that processing of an expression tree has been started.
|
void |
onRootEnd()
Notifies that processing of an expression tree has been finished.
|
void |
onValue(NodeValue value)
Notifies that a value node has been visited.
|
void |
onVariable(NodeVariable variable)
Notifies that a variable node has been visited.
|
void |
reset()
Reset transformer to initial state keeping all rules.
|
void |
walk(java.util.Collection<? extends Node> trees)
Traverse and apply substitutions to expression forest.
|
void |
walk(Node root)
Traverse and apply substitutions to single expression tree.
|
public NodeTransformer()
public NodeTransformer(java.util.Map<java.lang.Enum<?>,TransformerRule> rules)
rules - Map of rules. See addRule() for details.public void walk(Node root)
getResult().root - Root of a tree to be traversed.public void walk(java.util.Collection<? extends Node> trees)
getResult().trees - Collection of root nodes of trees to be traversed.public void reset()
public void addRule(java.lang.Enum<?> opId,
TransformerRule rule)
opId - Target node kind identifier.rule - Rule to be added.java.lang.IllegalArgumentException - if any of the parameters is null.public java.util.List<Node> getResult()
public ExprTreeVisitor.Status getStatus()
ExprTreeVisitorgetStatus in interface ExprTreeVisitorpublic void onRootBegin()
ExprTreeVisitoronRootBegin in interface ExprTreeVisitorpublic void onRootEnd()
ExprTreeVisitoronRootEnd in interface ExprTreeVisitorpublic void onOperationBegin(NodeOperation expr)
ExprTreeVisitoronOperationBegin in interface ExprTreeVisitorexpr - Operation node.public void onOperationEnd(NodeOperation expr)
ExprTreeVisitoronOperationEnd in interface ExprTreeVisitorexpr - Operation node.public int[] getOperandOrder()
ExprTreeVisitornull is returned.getOperandOrder in interface ExprTreeVisitornull for the standard order.public void onOperandBegin(NodeOperation expr, Node operand, int index)
ExprTreeVisitoronOperandBegin in interface ExprTreeVisitorexpr - Operation node.operand - Operand node.index - Operand index.public void onOperandEnd(NodeOperation expr, Node operand, int index)
ExprTreeVisitoronOperandEnd in interface ExprTreeVisitorexpr - Operation node.operand - Operand node.index - Operand index.public void onValue(NodeValue value)
ExprTreeVisitoronValue in interface ExprTreeVisitorvalue - Value node.public void onVariable(NodeVariable variable)
ExprTreeVisitoronVariable in interface ExprTreeVisitorvariable - Variable node.public void onBindingBegin(NodeBinding node)
ExprTreeVisitoronBindingBegin in interface ExprTreeVisitornode - Binding node.public void onBindingListEnd(NodeBinding node)
ExprTreeVisitoronBindingListEnd in interface ExprTreeVisitornode - Bounding node.public void onBindingEnd(NodeBinding node)
ExprTreeVisitoronBindingEnd in interface ExprTreeVisitornode - Binding node.public void onBoundVariableBegin(NodeBinding node, NodeVariable variable, Node value)
ExprTreeVisitoronBoundVariableBegin in interface ExprTreeVisitornode - Binding node.variable - Bound variable reference.value - Bound value expression.public void onBoundVariableEnd(NodeBinding node, NodeVariable variable, Node value)
ExprTreeVisitoronBoundVariableEnd in interface ExprTreeVisitornode - Binding node.variable - Bound variable reference.value - Bound value expression.