Class ASTMutations


  • public final class ASTMutations
    extends Object
    Deep clone, replace and remove operations over AST nodes.
    • Method Detail

      • deepClone

        public static <T extends ASTNode> T deepClone​(T node)
        Copies a node and its whole subtree, leaving the copy parentless as the root of a new tree.
        Type Parameters:
        T - the node type
        Parameters:
        node - the subtree root to copy, or null
        Returns:
        the copied subtree, or null if node was null
      • replace

        public static boolean replace​(ASTNode oldNode,
                                      ASTNode newNode)
        Swaps a node for another in whichever slot of its parent holds it.
        Parameters:
        oldNode - the node to replace, which must already be attached to a parent
        newNode - the replacement, which must fit the slot's kind
        Returns:
        true if the slot was found and updated
      • remove

        public static boolean remove​(ASTNode node)
        Detaches a node from the list slot of its parent that holds it - block statements, call arguments, loop init and update entries and the like.
        Parameters:
        node - the node to detach
        Returns:
        true if the parent held it in a list slot and it was removed