@SuppressWarnings("unchecked") protected <T extends Node> T toStringTemplateGraph(final T node, final Map<Node, Node> clonedNodes) { T clone = (T) clonedNodes.get(node); if (clone == null) { clone = toStringTemplateNode(node, clonedNodes); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) clone.astAddNode(toStringTemplateGraph(subNode, clonedNodes)); } } clonedNodes.put(node, clone); // Add the clone itself in the clonedNodes map to avoid to re-clone it in // case of a NodeContainerDecoration that is shared by different nodes. clonedNodes.put(clone, clone); } return clone; }
@SuppressWarnings("unchecked") private static <T extends Node> T cloneGraph(final T node, final Map<Node, Node> clonedNodes) { T clone = (T) clonedNodes.get(node); if (clone == null) { clone = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) clone.astAddNode(cloneGraph(subNode, clonedNodes)); } } clonedNodes.put(node, clone); } return clone; }
/** * Clone the given {@link Node}. Sub nodes of the given node are not * recursively cloned. This imply that the returned node has the same sub * nodes as the given node. * * @param <T> The type of the node. * @param node the node to clone. * @return a clone of the given node. */ public static <T extends Node> T cloneNode(final T node) { final T newNode = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) newNode.astAddNode(subNode); } } return newNode; }
result.astAddNode(initMergedNodes(subNodeInfo, infos));
/** * Clone the given {@link Node} and its sub nodes recursively. <br> * <b>Warning</b>: this method consider that the given node is the root of a * <b>tree graph</b> (i.e. any transitive sub node of the given node is the * sub node of one and only one node). Use {@link #cloneGraph(Node)} method if * this condition is not true. * * @param <T> The type of the node. * @param node the root of the tree to clone. * @return a clone of the given tree of node. * @see #cloneGraph(Node) */ public static <T extends Node> T cloneTree(final T node) { final T newNode = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) newNode.astAddNode(cloneTree(subNode)); } } return newNode; }