public final class SoytreeUtils extends Object
Important: Do not use outside of Soy code (treat as superpackage-private).
| 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.copy(copyState) creates cloned nodes with the same ids as the original nodes).
|
static <T extends SoyNode> |
cloneNode(T original)
Clones a SoyNode but unlike SoyNode.copy(copyState) keeps
VarRefNode.getDefnDecl()
pointing at the correct tree. |
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.copy(copyState) creates cloned nodes with the same ids as the original nodes).
|
static <R> void |
execOnAllV2Exprs(SoyNode node,
AbstractNodeVisitor<ExprNode,R> exprNodeVisitor)
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 Node> |
getAllNodesOfType(SoyNode rootSoyNode,
Class<T> classObject)
Retrieves all nodes in a tree that are an instance of a particular class.
|
static <T extends Node> |
getAllNodesOfType(SoyNode rootSoyNode,
Class<T> classObject,
boolean doSearchSubtreesOfMatchedNodes)
Retrieves all nodes in a tree that are an instance of a particular class.
|
static boolean |
hasNodesOfType(Node node,
Class<? extends Node>... types)
Returns true if the given
node contains any children of the given types. |
static boolean |
isDescendantOf(SoyNode node,
SoyNode ancestor)
Returns true if
node is a descendant of ancestor. |
static void |
visitAllNodes(Node node,
NodeVisitor<? super Node,Boolean> visitor)
Runs the visitor on all nodes (including
expr nodes) reachable from the given
node. |
@SafeVarargs public static boolean hasNodesOfType(Node node, Class<? extends Node>... types)
node contains any children of the given types.public static void visitAllNodes(Node node, NodeVisitor<? super Node,Boolean> visitor)
expr nodes) reachable from the given
node. The order of visiting is undefined.
If the visitor return false from NodeVisitor.exec(Node) we will short
circuit visiting.
public static <T extends Node> 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 Node> 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, AbstractNodeVisitor<ExprNode,R> exprNodeVisitor)
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.public 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.public static <T extends SoyNode> T cloneNode(T original)
VarRefNode.getDefnDecl()
pointing at the correct tree.