use of com.google.template.soy.soytree.SoyNode.ExprHolderNode in project closure-templates by google.
the class SoyTreeUtils method visitAllNodes.
/**
* Runs the visitor on all nodes (including {@link ExprNode expr nodes}) reachable from the given
* node. The order of visiting is breadth first.
*
* <p>If the visitor return {@code false} from {@link NodeVisitor#exec(Node)} we will short
* circuit visiting.
*/
public static void visitAllNodes(Node node, NodeVisitor<? super Node, VisitDirective> visitor) {
ArrayDeque<Node> queue = new ArrayDeque<>();
queue.add(node);
Node current;
while ((current = queue.poll()) != null) {
switch(visitor.exec(current)) {
case ABORT:
return;
case CONTINUE:
if (current instanceof ParentNode<?>) {
queue.addAll(((ParentNode<?>) current).getChildren());
}
if (current instanceof ExprHolderNode) {
queue.addAll(((ExprHolderNode) current).getExprList());
}
continue;
case SKIP_CHILDREN:
continue;
default:
throw new AssertionError();
}
}
}
Aggregations