Search in sources :

Example 1 with ExprHolderNode

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();
        }
    }
}
Also used : ParentNode(com.google.template.soy.basetree.ParentNode) Node(com.google.template.soy.basetree.Node) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode) ParentSoyNode(com.google.template.soy.soytree.SoyNode.ParentSoyNode) ExprHolderNode(com.google.template.soy.soytree.SoyNode.ExprHolderNode) ParentNode(com.google.template.soy.basetree.ParentNode) ExprNode(com.google.template.soy.exprtree.ExprNode) ExprHolderNode(com.google.template.soy.soytree.SoyNode.ExprHolderNode) ArrayDeque(java.util.ArrayDeque)

Aggregations

Node (com.google.template.soy.basetree.Node)1 ParentNode (com.google.template.soy.basetree.ParentNode)1 ExprNode (com.google.template.soy.exprtree.ExprNode)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 ExprHolderNode (com.google.template.soy.soytree.SoyNode.ExprHolderNode)1 ParentSoyNode (com.google.template.soy.soytree.SoyNode.ParentSoyNode)1 ArrayDeque (java.util.ArrayDeque)1