Class NodeUtil

java.lang.Object
com.oracle.truffle.api.nodes.NodeUtil

public final class NodeUtil extends Object
Utility class that manages the special access methods for node instances.
Since:
0.8 or earlier
  • Method Details

    • cloneNode

      public static <T extends Node> T cloneNode(T orig)
      Since:
      0.8 or earlier
    • assertAdopted

      public static boolean assertAdopted(Node node)
      Asserts that a node is adopted by a RootNode and prints a formatted error message with the error path if it is not adopted. Provided node must be not null. Throws an AssertionError if it fails and always returns true otherwise for convenient usage with the assert statement.
      Since:
      23.1
    • findNodeChildren

      public static List<Node> findNodeChildren(Node node)
      Since:
      0.8 or earlier
    • nonAtomicReplace

      public static <T extends Node> T nonAtomicReplace(Node oldNode, T newNode, CharSequence reason)
      Since:
      0.8 or earlier
    • replaceChild

      public static boolean replaceChild(Node parent, Node oldChild, Node newChild)
      Since:
      0.8 or earlier
    • findChildFieldName

      public static String findChildFieldName(Node parent, Node child)
      Finds the field in a parent node and returns its name. Utility for debugging and tracing purposes.
      Since:
      22.2
    • collectFieldNames

      public static List<String> collectFieldNames(Class<? extends Node> clazz)
      Finds and retrieves all field names of a node class. This is a utility intended for debugging and tracing purposes.
      Since:
      22.2
    • collectNodeChildren

      public static Map<String,Node> collectNodeChildren(Node node)
      Finds and retrieves all Node.Child and Node.Children annotated field names and values. This is a utility intended for debugging and tracing purposes.
      Since:
      22.2
    • collectNodeProperties

      public static Map<String,Object> collectNodeProperties(Node node)
      Finds and retrieves all properties of a node. Properties of a node are all fields not annotated with Node.Child or Node.Children. This is a utility intended for debugging and tracing purposes.
      Since:
      22.2
    • isReplacementSafe

      public static boolean isReplacementSafe(Node parent, Node oldChild, Node newChild)
      Determines whether a proposed child replacement would be safe: structurally and type.
      Since:
      0.8 or earlier
    • forEachChild

      public static boolean forEachChild(Node parent, NodeVisitor visitor)
      Executes a closure for every non-null child of the parent node.
      Returns:
      true if all children were visited, false otherwise
      Since:
      0.8 or earlier
    • concat

      public static <T> T[] concat(T[] first, T[] second)
      Since:
      0.8 or earlier
    • getNthParent

      public static Node getNthParent(Node node, int n)
      Get the nth parent of a node, where the 0th parent is the node itself. Returns null if there are less than n ancestors.
      Since:
      0.8 or earlier
    • findAnnotation

      public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass)
      Find annotation in class/interface hierarchy.
      Since:
      0.8 or earlier
    • findParent

      public static <T> T findParent(Node start, Class<T> clazz)
      Since:
      0.8 or earlier
    • findAllParents

      public static <T> List<T> findAllParents(Node start, Class<T> clazz)
      Since:
      0.8 or earlier
    • collectNodes

      public static List<Node> collectNodes(Node parent, Node child)
      Since:
      0.8 or earlier
    • findFirstNodeInstance

      public static <T> T findFirstNodeInstance(Node root, Class<T> clazz)
      Since:
      0.8 or earlier
    • findAllNodeInstances

      public static <T> List<T> findAllNodeInstances(Node root, Class<T> clazz)
      Since:
      0.8 or earlier
    • countNodes

      public static int countNodes(Node root)
      Since:
      0.8 or earlier
    • countNodes

      public static int countNodes(Node root, NodeUtil.NodeCountFilter filter)
      Since:
      0.8 or earlier
    • printCompactTreeToString

      public static String printCompactTreeToString(Node node)
      Since:
      0.8 or earlier
    • printCompactTree

      public static void printCompactTree(OutputStream out, Node node)
      Since:
      0.8 or earlier
    • printSourceAttributionTree

      public static String printSourceAttributionTree(Node node)
      Since:
      0.8 or earlier
    • printSourceAttributionTree

      public static void printSourceAttributionTree(OutputStream out, Node node)
      Since:
      0.8 or earlier
    • printSourceAttributionTree

      public static void printSourceAttributionTree(PrintWriter out, Node node)
      Since:
      0.8 or earlier
    • printSyntaxTags

      public static String printSyntaxTags(Object node)
      Originally returned the tags if any, associated with a node; now unsupported.
      Since:
      0.8 or earlier
    • printTree

      public static void printTree(OutputStream out, Node node)
      Prints a human readable form of a Node AST to the given PrintStream. This print method does not check for cycles in the node structure.
      Parameters:
      out - the stream to print to.
      node - the root node to write
      Since:
      0.8 or earlier
    • printTreeToString

      public static String printTreeToString(Node node)
      Since:
      0.8 or earlier
    • printTree

      public static void printTree(PrintWriter p, Node node)
      Since:
      0.8 or earlier
    • verify

      public static boolean verify(Node root)
      Since:
      0.8 or earlier
    • assertRecursion

      public static boolean assertRecursion(Node node, int maxRecursion)
      Fails with an assertion if the exact node type is used as a parent. Returns true if the node is null.
      Since:
      21.2