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.lang.Iterable<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.lang.Iterable<? 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.lang.Iterable<? extends Node> trees)
getResult()
.trees
- Collections 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.lang.Iterable<Node> getResult()
public ExprTreeVisitor.Status getStatus()
ExprTreeVisitor
getStatus
in interface ExprTreeVisitor
public void onRootBegin()
ExprTreeVisitor
onRootBegin
in interface ExprTreeVisitor
public void onRootEnd()
ExprTreeVisitor
onRootEnd
in interface ExprTreeVisitor
public void onOperationBegin(NodeOperation expr)
ExprTreeVisitor
onOperationBegin
in interface ExprTreeVisitor
expr
- Operation node.public void onOperationEnd(NodeOperation expr)
ExprTreeVisitor
onOperationEnd
in interface ExprTreeVisitor
expr
- Operation node.public int[] getOperandOrder()
ExprTreeVisitor
null
is returned.getOperandOrder
in interface ExprTreeVisitor
null
for the standard order.public void onOperandBegin(NodeOperation expr, Node operand, int index)
ExprTreeVisitor
onOperandBegin
in interface ExprTreeVisitor
expr
- Operation node.operand
- Operand node.index
- Operand index.public void onOperandEnd(NodeOperation expr, Node operand, int index)
ExprTreeVisitor
onOperandEnd
in interface ExprTreeVisitor
expr
- Operation node.operand
- Operand node.index
- Operand index.public void onValue(NodeValue value)
ExprTreeVisitor
onValue
in interface ExprTreeVisitor
value
- Value node.public void onVariable(NodeVariable variable)
ExprTreeVisitor
onVariable
in interface ExprTreeVisitor
variable
- Variable node.public void onBindingBegin(NodeBinding node)
ExprTreeVisitor
onBindingBegin
in interface ExprTreeVisitor
node
- Binding node.public void onBindingListEnd(NodeBinding node)
ExprTreeVisitor
onBindingListEnd
in interface ExprTreeVisitor
node
- Bounding node.public void onBindingEnd(NodeBinding node)
ExprTreeVisitor
onBindingEnd
in interface ExprTreeVisitor
node
- Binding node.public void onBoundVariableBegin(NodeBinding node, NodeVariable variable, Node value)
ExprTreeVisitor
onBoundVariableBegin
in interface ExprTreeVisitor
node
- Binding node.variable
- Bound variable reference.value
- Bound value expression.public void onBoundVariableEnd(NodeBinding node, NodeVariable variable, Node value)
ExprTreeVisitor
onBoundVariableEnd
in interface ExprTreeVisitor
node
- Binding node.variable
- Bound variable reference.value
- Bound value expression.