Package com.oracle.truffle.api.nodes

## Class NodeUtil

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

    public final class NodeUtil
    extends java.lang.Object

Utility class that manages the special access methods for node instances.

### Nested Class Summary

Nested Classes
`static interface` `NodeUtil.FieldOffsetProvider` Interface that allows the customization of field offsets used for `Unsafe` field accesses.
`static class` `NodeUtil.NodeClass` Information about a `Node` class.
`static interface` `NodeUtil.NodeCountFilter`
`static class` `NodeUtil.NodeField` Information about a field in a `Node` class.
`static class` `NodeUtil.NodeFieldKind`

### Constructor Summary

Constructors
`NodeUtil()`

### Method Summary

All Methods Static Methods Concrete Methods
`static <T extends Node> T` `cloneNode​(T orig)`
`static java.util.List<Node>` `collectNodes​(Node parent, Node child)`
`static <T> T[]` `concat​(T[] first, T[] second)`
`static int` `countNodes​(Node root)`
`static int` `countNodes​(Node root, NodeUtil.NodeCountFilter filter)`
`static <T> java.util.List<T>` `findAllNodeInstances​(Node root, java.lang.Class<T> clazz)`
`static <T> java.util.List<T>` `findAllParents​(Node start, java.lang.Class<T> clazz)`
`static <T extends java.lang.annotation.Annotation> T` `findAnnotation​(java.lang.Class<?> clazz, java.lang.Class<T> annotationClass)` find annotation in class/interface hierarchy.
`static <T> T` `findFirstNodeInstance​(Node root, java.lang.Class<T> clazz)`
`static java.util.List<Node>` `findNodeChildren​(Node node)`
`static <T> java.util.List<T>` `findNodeInstancesShallow​(Node root, java.lang.Class<T> clazz)` Like `findAllNodeInstances(Node, Class)` but do not visit children of found nodes.
`static <T> T` `findParent​(Node start, java.lang.Class<T> clazz)`
`static Node` `getNthParent​(Node node, int n)` Get the nth parent of a node, where the 0th parent is the node itself.
`static java.util.Iterator<Node>` `makeRecursiveIterator​(Node node)`
`static void` `printCompactTree​(java.io.OutputStream out, Node node)`
`static java.lang.String` `printCompactTreeToString​(Node node)`
`static java.lang.String` `printSourceAttributionTree​(Node node)`
`static void` `printSourceAttributionTree​(java.io.OutputStream out, Node node)`
`static java.lang.String` `printSyntaxTags​(java.lang.Object node)` Returns a string listing the syntax tags, if any, associated with a node: "[STATEMENT, ASSIGNMENT]" if tags have been applied; "[]" if the node supports tags, but none are present; and "" if the node does not support tags.
`static void` `printTree​(java.io.OutputStream out, Node node)` Prints a human readable form of a `Node` AST to the given `PrintStream`.
`static void` `printTree​(java.io.PrintWriter p, Node node)`
`static java.lang.String` `printTreeToString​(Node node)`
`static boolean` `replaceChild​(Node parent, Node oldChild, Node newChild)`
`static boolean` `verify​(Node root)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### NodeUtil

    public NodeUtil()

### Method Detail

#### makeRecursiveIterator

    public static java.util.Iterator<Node> makeRecursiveIterator​(Node node)

#### cloneNode

    public static <T extends Node> T cloneNode​(T orig)

#### findNodeChildren

    public static java.util.List<Node> findNodeChildren​(Node node)

#### replaceChild

    public static boolean replaceChild​(Node parent,
                                       Node oldChild,
                                       Node newChild)

#### concat

    public static <T> T[] concat​(T[] first,
                                 T[] second)

#### 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.

#### findAnnotation

    public static <T extends java.lang.annotation.Annotation> T findAnnotation​(java.lang.Class<?> clazz,
                                                                               java.lang.Class<T> annotationClass)

find annotation in class/interface hierarchy.

#### findParent

    public static <T> T findParent​(Node start,
                                   java.lang.Class<T> clazz)

#### findAllParents

    public static <T> java.util.List<T> findAllParents​(Node start,
                                                       java.lang.Class<T> clazz)

#### collectNodes

    public static java.util.List<Node> collectNodes​(Node parent,
                                                    Node child)

#### findFirstNodeInstance

    public static <T> T findFirstNodeInstance​(Node root,
                                              java.lang.Class<T> clazz)

#### findAllNodeInstances

    public static <T> java.util.List<T> findAllNodeInstances​(Node root,
                                                             java.lang.Class<T> clazz)

#### findNodeInstancesShallow

    public static <T> java.util.List<T> findNodeInstancesShallow​(Node root,
                                                                 java.lang.Class<T> clazz)

Like `findAllNodeInstances(Node, Class)` but do not visit children of found nodes.

#### countNodes

    public static int countNodes​(Node root)

#### countNodes

    public static int countNodes​(Node root,
                                 NodeUtil.NodeCountFilter filter)

#### printCompactTreeToString

    public static java.lang.String printCompactTreeToString​(Node node)

#### printCompactTree

    public static void printCompactTree​(java.io.OutputStream out,
                                        Node node)

#### printSourceAttributionTree

    public static java.lang.String printSourceAttributionTree​(Node node)

#### printSourceAttributionTree

    public static void printSourceAttributionTree​(java.io.OutputStream out,
                                                  Node node)

#### printSyntaxTags

    public static java.lang.String printSyntaxTags​(java.lang.Object node)

Returns a string listing the syntax tags, if any, associated with a node:

- "[STATEMENT, ASSIGNMENT]" if tags have been applied;
- "[]" if the node supports tags, but none are present; and
- "" if the node does not support tags.

#### printTree

    public static void printTree​(java.io.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

#### printTreeToString

    public static java.lang.String printTreeToString​(Node node)

#### printTree

    public static void printTree​(java.io.PrintWriter p,
                                 Node node)

#### verify

    public static boolean verify​(Node root)