/** * 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; }