public class SoytreeUtils extends Object
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Class and Description |
|---|---|
static interface |
SoytreeUtils.Shortcircuiter<R>
Helper interface for
visitAllExprsShortcircuitably. |
| Modifier and Type | Method and Description |
|---|---|
static <T extends SoyNode> |
cloneListWithNewIds(List<T> origNodes,
IdGenerator nodeIdGen)
Clones the given list of nodes and then generates and sets new ids on all the cloned nodes (by
default, SoyNode.clone() creates cloned nodes with the same ids as the original nodes).
|
static <T extends SoyNode> |
cloneWithNewIds(T origNode,
IdGenerator nodeIdGen)
Clones the given node and then generates and sets new ids on all the cloned nodes (by default,
SoyNode.clone() creates cloned nodes with the same ids as the original nodes).
|
static <R> void |
execOnAllV2Exprs(SoyNode node,
AbstractExprNodeVisitor<R> exprNodeVisitor,
ErrorReporter errorReporter)
Given a Soy node and a visitor for expression trees, traverses the subtree of the node and
executes the visitor on all expressions held by nodes in the subtree.
|
static <R> void |
execOnAllV2ExprsShortcircuitably(SoyNode node,
AbstractExprNodeVisitor<R> exprNodeVisitor,
SoytreeUtils.Shortcircuiter<R> shortcircuiter,
ErrorReporter errorReporter)
Given a Soy node and a visitor for expression trees, traverses the subtree of the node and
executes the visitor on all expressions held by nodes in the subtree.
|
static <T extends SoyNode> |
getAllNodesOfType(SoyNode rootSoyNode,
Class<T> classObject)
Retrieves all nodes in a tree that are an instance of a particular class.
|
static <T extends SoyNode> |
getAllNodesOfType(SoyNode rootSoyNode,
Class<T> classObject,
boolean doSearchSubtreesOfMatchedNodes)
Retrieves all nodes in a tree that are an instance of a particular class.
|
public static <T extends SoyNode> List<T> getAllNodesOfType(SoyNode rootSoyNode, Class<T> classObject)
T - The type of node to retrieve.rootSoyNode - The parse tree to search.classObject - The class whose instances to search for, including subclasses.public static <T extends SoyNode> List<T> getAllNodesOfType(SoyNode rootSoyNode, Class<T> classObject, boolean doSearchSubtreesOfMatchedNodes)
T - The type of node to retrieve.rootSoyNode - The parse tree to search.classObject - The class whose instances to search for, including subclasses.doSearchSubtreesOfMatchedNodes - Whether to keep searching subtrees of matched nodes for
more nodes of the given type.public static <R> void execOnAllV2Exprs(SoyNode node, AbstractExprNodeVisitor<R> exprNodeVisitor, ErrorReporter errorReporter)
Only processes expressions in V2 syntax. Ignores all expressions in V1 syntax.
R - The ExprNode visitor's return type.node - The root of the subtree to visit all expressions in.exprNodeVisitor - The visitor to execute on all expressions.errorReporter - For reporting errors during the visit.public static <R> void execOnAllV2ExprsShortcircuitably(SoyNode node, AbstractExprNodeVisitor<R> exprNodeVisitor, SoytreeUtils.Shortcircuiter<R> shortcircuiter, ErrorReporter errorReporter)
Only processes expressions in V2 syntax. Ignores all expressions in V1 syntax.
Same as visitAllExprs except that this pass can be shortcircuited by providing a
SoytreeUtils.Shortcircuiter.
R - The ExprNode visitor's return type.node - The root of the subtree to visit all expressions in.exprNodeVisitor - The visitor to execute on all expressions.shortcircuiter - The Shortcircuiter to tell us when to shortcircuit the pass.errorReporter - For reporting errors during the visit.SoytreeUtils.Shortcircuiterpublic static <T extends SoyNode> T cloneWithNewIds(T origNode, IdGenerator nodeIdGen)
This function will use the original Soy tree's node id generator to generate the new node ids for the cloned nodes. Thus, the original node to be cloned must be part of a full Soy tree. However, this does not mean that the cloned node will become part of the original tree (unless it is manually attached later). The cloned node will be an independent subtree with parent set to null.
T - The type of the node being cloned.origNode - The original node to be cloned. This node must be part of a full Soy tree,
because the generator for the new node ids will be retrieved from the root (SoyFileSetNode)
of the tree.nodeIdGen - The ID generator used for the tree.public static <T extends SoyNode> List<T> cloneListWithNewIds(List<T> origNodes, IdGenerator nodeIdGen)
This function will use the original Soy tree's node id generator to generate the new node ids for the cloned nodes. Thus, the original nodes to be cloned must be part of a full Soy tree. However, this does not mean that the cloned nodes will become part of the original tree (unless they are manually attached later). The cloned nodes will be independent subtrees with parents set to null.
T - The type of the nodes being cloned.origNodes - The original nodes to be cloned. These nodes must be part of a full Soy tree,
because the generator for the new node ids will be retrieved from the root (SoyFileSetNode)
of the tree.nodeIdGen - The ID generator used for the tree.