Package com.oracle.truffle.api.nodes
Class NodeUtil
java.lang.Object
com.oracle.truffle.api.nodes.NodeUtil
Utility class that manages the special access methods for node instances.
- Since:
- 0.8 or earlier
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
assertAdopted
(Node node) Asserts that a node is adopted by aRootNode
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 exactnode type
is used as a parent.static <T extends Node>
TcloneNode
(T orig) collectFieldNames
(Class<? extends Node> clazz) Finds and retrieves all field names of a node class.collectNodeChildren
(Node node) Finds and retrieves allNode.Child
andNode.Children
annotated field names and values.collectNodeProperties
(Node node) Finds and retrieves all properties of a 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>
TfindAnnotation
(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) 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>
TnonAtomicReplace
(Node oldNode, T newNode, CharSequence reason) static void
printCompactTree
(OutputStream out, Node node) static String
printCompactTreeToString
(Node node) static String
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 aNode
AST to the givenPrintStream
.static void
printTree
(PrintWriter p, Node node) static String
printTreeToString
(Node node) static boolean
replaceChild
(Node parent, Node oldChild, Node newChild) static boolean
-
Method Details
-
cloneNode
- Since:
- 0.8 or earlier
-
assertAdopted
Asserts that a node is adopted by aRootNode
and prints a formatted error message with the error path if it is not adopted. Provided node must be notnull
. Throws anAssertionError
if it fails and always returnstrue
otherwise for convenient usage with theassert
statement.- Since:
- 23.1
-
findNodeChildren
- Since:
- 0.8 or earlier
-
nonAtomicReplace
- Since:
- 0.8 or earlier
-
replaceChild
- Since:
- 0.8 or earlier
-
findChildFieldName
Finds the field in a parent node and returns its name. Utility for debugging and tracing purposes.- Since:
- 22.2
-
collectFieldNames
Finds and retrieves all field names of a node class. This is a utility intended for debugging and tracing purposes.- Since:
- 22.2
-
collectNodeChildren
Finds and retrieves allNode.Child
andNode.Children
annotated field names and values. This is a utility intended for debugging and tracing purposes.- Since:
- 22.2
-
collectNodeProperties
Finds and retrieves all properties of a node. Properties of a node are all fields not annotated withNode.Child
orNode.Children
. This is a utility intended for debugging and tracing purposes.- Since:
- 22.2
-
isReplacementSafe
Determines whether a proposed child replacement would be safe: structurally and type.- Since:
- 0.8 or earlier
-
forEachChild
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
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
Find annotation in class/interface hierarchy.- Since:
- 0.8 or earlier
-
findParent
- Since:
- 0.8 or earlier
-
findAllParents
- Since:
- 0.8 or earlier
-
collectNodes
- Since:
- 0.8 or earlier
-
findFirstNodeInstance
- Since:
- 0.8 or earlier
-
findAllNodeInstances
- Since:
- 0.8 or earlier
-
countNodes
- Since:
- 0.8 or earlier
-
countNodes
- Since:
- 0.8 or earlier
-
printCompactTreeToString
- Since:
- 0.8 or earlier
-
printCompactTree
- Since:
- 0.8 or earlier
-
printSourceAttributionTree
- Since:
- 0.8 or earlier
-
printSourceAttributionTree
- Since:
- 0.8 or earlier
-
printSourceAttributionTree
- Since:
- 0.8 or earlier
-
printSyntaxTags
Originally returned the tags if any, associated with a node; now unsupported.- Since:
- 0.8 or earlier
-
printTree
Prints a human readable form of aNode
AST to the givenPrintStream
. 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
- Since:
- 0.8 or earlier
-
printTree
- Since:
- 0.8 or earlier
-
verify
- Since:
- 0.8 or earlier
-
assertRecursion
Fails with an assertion if the exactnode type
is used as a parent. Returnstrue
if the node isnull
.- Since:
- 21.2
-