public final class NodeUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
NodeUtil.NodeCountFilter |
Modifier and Type | Method and Description |
---|---|
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. |
static boolean |
assertRecursion(Node node,
int maxRecursion)
Fails with an assertion if the exact
node type is used as a parent. |
static <T extends Node> |
cloneNode(T orig) |
static List<String> |
collectFieldNames(Class<? extends Node> clazz)
Finds and retrieves all field names of a node class.
|
static Map<String,Node> |
collectNodeChildren(Node node)
Finds and retrieves all
Node.Child and Node.Children annotated field names and values. |
static Map<String,Object> |
collectNodeProperties(Node node)
Finds and retrieves all properties of a node.
|
static 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> List<T> |
findAllNodeInstances(Node root,
Class<T> clazz) |
static <T> List<T> |
findAllParents(Node start,
Class<T> clazz) |
static <T extends Annotation> |
findAnnotation(Class<?> clazz,
Class<T> annotationClass)
Find annotation in class/interface hierarchy.
|
static String |
findChildFieldName(Node parent,
Node child)
Finds the field in a parent node and returns its name.
|
static <T> T |
findFirstNodeInstance(Node root,
Class<T> clazz) |
static List<Node> |
findNodeChildren(Node node) |
static <T> T |
findParent(Node start,
Class<T> clazz) |
static boolean |
forEachChild(Node parent,
NodeVisitor visitor)
Executes a closure for every non-null child of the parent node.
|
static Node |
getNthParent(Node node,
int n)
Get the nth parent of a node, where the 0th parent is the node itself.
|
static boolean |
isReplacementSafe(Node parent,
Node oldChild,
Node newChild)
Determines whether a proposed child replacement would be safe: structurally and type.
|
static <T extends Node> |
nonAtomicReplace(Node oldNode,
T newNode,
CharSequence reason) |
static void |
printCompactTree(OutputStream out,
Node node) |
static String |
printCompactTreeToString(Node node) |
static String |
printSourceAttributionTree(Node node) |
static void |
printSourceAttributionTree(OutputStream out,
Node node) |
static void |
printSourceAttributionTree(PrintWriter out,
Node node) |
static String |
printSyntaxTags(Object node)
Originally returned the tags if any, associated with a node; now unsupported.
|
static void |
printTree(OutputStream out,
Node node)
Prints a human readable form of a
Node AST to the given PrintStream . |
static void |
printTree(PrintWriter p,
Node node) |
static String |
printTreeToString(Node node) |
static boolean |
replaceChild(Node parent,
Node oldChild,
Node newChild) |
static boolean |
verify(Node root) |
public static <T extends Node> T cloneNode(T orig)
public static boolean assertAdopted(Node node)
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.public static <T extends Node> T nonAtomicReplace(Node oldNode, T newNode, CharSequence reason)
public static boolean replaceChild(Node parent, Node oldChild, Node newChild)
public static String findChildFieldName(Node parent, Node child)
public static List<String> collectFieldNames(Class<? extends Node> clazz)
public static Map<String,Node> collectNodeChildren(Node node)
Node.Child
and Node.Children
annotated field names and values.
This is a utility intended for debugging and tracing purposes.public static Map<String,Object> collectNodeProperties(Node node)
Node.Child
or Node.Children
. This is a utility intended for debugging
and tracing purposes.public static boolean isReplacementSafe(Node parent, Node oldChild, Node newChild)
public static boolean forEachChild(Node parent, NodeVisitor visitor)
true
if all children were visited, false
otherwisepublic static <T> T[] concat(T[] first, T[] second)
public static Node getNthParent(Node node, int n)
public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass)
public static <T> List<T> findAllParents(Node start, Class<T> clazz)
public static <T> T findFirstNodeInstance(Node root, Class<T> clazz)
public static <T> List<T> findAllNodeInstances(Node root, Class<T> clazz)
public static int countNodes(Node root)
public static int countNodes(Node root, NodeUtil.NodeCountFilter filter)
public static String printCompactTreeToString(Node node)
public static void printCompactTree(OutputStream out, Node node)
public static String printSourceAttributionTree(Node node)
public static void printSourceAttributionTree(OutputStream out, Node node)
public static void printSourceAttributionTree(PrintWriter out, Node node)
public static String printSyntaxTags(Object node)
public static void printTree(OutputStream out, Node node)
Node
AST to the given PrintStream
. This
print method does not check for cycles in the node structure.out
- the stream to print to.node
- the root node to writepublic static void printTree(PrintWriter p, Node node)
public static boolean verify(Node root)