Class NodeUtil


  • public final class NodeUtil
    extends java.lang.Object
    Utility class that manages the special access methods for node instances.
    • 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)
      • 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)