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
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanassertAdopted(Node node) Asserts that a node is adopted by aRootNodeand prints a formatted error message with the error path if it is not adopted.static booleanassertRecursion(Node node, int maxRecursion) Fails with an assertion if the exactnode typeis 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.ChildandNode.Childrenannotated 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 intcountNodes(Node root) static intcountNodes(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 StringfindChildFieldName(Node parent, Node child) Finds the field in a parent node and returns its name.static <T> TfindFirstNodeInstance(Node root, Class<T> clazz) findNodeChildren(Node node) static <T> TfindParent(Node start, Class<T> clazz) static booleanforEachChild(Node parent, NodeVisitor visitor) Executes a closure for every non-null child of the parent node.static NodegetNthParent(Node node, int n) Get the nth parent of a node, where the 0th parent is the node itself.static booleanisReplacementSafe(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 voidprintCompactTree(OutputStream out, Node node) static StringprintCompactTreeToString(Node node) static Stringstatic voidprintSourceAttributionTree(OutputStream out, Node node) static voidprintSourceAttributionTree(PrintWriter out, Node node) static StringprintSyntaxTags(Object node) Originally returned the tags if any, associated with a node; now unsupported.static voidprintTree(OutputStream out, Node node) Prints a human readable form of aNodeAST to the givenPrintStream.static voidprintTree(PrintWriter p, Node node) static StringprintTreeToString(Node node) static booleanreplaceChild(Node parent, Node oldChild, Node newChild) static boolean
-
Method Details
-
cloneNode
- Since:
- 0.8 or earlier
-
assertAdopted
Asserts that a node is adopted by aRootNodeand prints a formatted error message with the error path if it is not adopted. Provided node must be notnull. Throws anAssertionErrorif it fails and always returnstrueotherwise for convenient usage with theassertstatement.- Since:
- 23.1
-
findNodeChildren
-
nonAtomicReplace
- Since:
- 0.8 or earlier
-
replaceChild
-
findChildFieldName
-
collectFieldNames
-
collectNodeChildren
Finds and retrieves allNode.ChildandNode.Childrenannotated 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.ChildorNode.Children. This is a utility intended for debugging and tracing purposes.- Since:
- 22.2
-
isReplacementSafe
-
forEachChild
Executes a closure for every non-null child of the parent node.- Returns:
trueif all children were visited,falseotherwise- Since:
- 0.8 or earlier
-
concat
public static <T> T[] concat(T[] first, T[] second) - Since:
- 0.8 or earlier
-
getNthParent
-
findAnnotation
Find annotation in class/interface hierarchy.- Since:
- 0.8 or earlier
-
findParent
-
findAllParents
-
collectNodes
-
findFirstNodeInstance
-
findAllNodeInstances
-
countNodes
- Since:
- 0.8 or earlier
-
countNodes
- Since:
- 0.8 or earlier
-
printCompactTreeToString
-
printCompactTree
- Since:
- 0.8 or earlier
-
printSourceAttributionTree
-
printSourceAttributionTree
- Since:
- 0.8 or earlier
-
printSourceAttributionTree
- Since:
- 0.8 or earlier
-
printSyntaxTags
-
printTree
Prints a human readable form of aNodeAST 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
-
printTree
- Since:
- 0.8 or earlier
-
verify
- Since:
- 0.8 or earlier
-
assertRecursion
-