public abstract class Node extends java.lang.Object implements NodeInterface, java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static interface |
Node.Child
Marks fields that represent child nodes of this node.
|
static interface |
Node.Children
Marks array fields that are children of this node.
|
Modifier | Constructor and Description |
---|---|
protected |
Node() |
protected |
Node(SourceSection sourceSection) |
Modifier and Type | Method and Description |
---|---|
void |
accept(NodeVisitor nodeVisitor)
Invokes the
NodeVisitor.visit(Node) method for this node and recursively also for all
child nodes. |
void |
adoptChildren() |
void |
assignSourceSection(SourceSection section)
Assigns a link to a guest language source section to this node.
|
<T> T |
atomic(java.util.concurrent.Callable<T> closure) |
void |
atomic(java.lang.Runnable closure) |
void |
clearSourceSection()
Clears any previously assigned guest language source code from this node.
|
protected java.lang.Object |
clone()
Deprecated.
|
Node |
copy()
Creates a shallow copy of this node.
|
java.lang.Iterable<Node> |
getChildren()
Iterator over the children of this node.
|
NodeCost |
getCost()
Returns a rough estimate for the cost of this
Node . |
java.util.Map<java.lang.String,java.lang.Object> |
getDebugProperties()
Returns properties of this node interesting for debugging and can be overwritten by
subclasses to add their own custom properties.
|
java.lang.String |
getDescription()
Returns a user-readable description of the purpose of the Node, or "" if no description is
available.
|
SourceSection |
getEncapsulatingSourceSection()
Retrieves the guest language source code section that is currently assigned to this node.
|
java.lang.String |
getLanguage()
Returns a string representing the language this node has been implemented for.
|
Node |
getParent()
The current parent node of this node.
|
RootNode |
getRootNode()
Get the root node of the tree a node belongs to.
|
SourceSection |
getSourceSection()
Retrieves the guest language source code section that is currently assigned to this node.
|
protected <T extends Node> |
insert(T newChild)
Method that updates the link to the parent in the specified new child node to this node.
|
protected <T extends Node> |
insert(T[] newChildren)
Method that updates the link to the parent in the array of specified new child nodes to this
node.
|
boolean |
isReplaceable()
Checks if this node is properly adopted by a parent and can be replaced.
|
protected void |
onAdopt()
Subclasses of
Node can implement this method to execute extra functionality when a
node is effectively inserted into the AST. |
protected void |
onReplace(Node newNode,
java.lang.CharSequence reason)
Intended to be implemented by subclasses of
Node to receive a notification when the
node is rewritten. |
<T extends Node> |
replace(T newNode)
Replaces this node with another node.
|
<T extends Node> |
replace(T newNode,
java.lang.CharSequence reason)
Replaces this node with another node.
|
java.lang.String |
toString()
Converts this node to a textual representation useful for debugging.
|
protected Node()
protected Node(SourceSection sourceSection)
public final void assignSourceSection(SourceSection section)
section
- the object representing a section in guest language source codepublic NodeCost getCost()
Node
. This estimate can be used by
runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method
is intended to be overridden by subclasses. The default implementation returns the value of
NodeInfo.cost()
of the NodeInfo
annotation declared at the subclass. If no
NodeInfo
annotation is declared the method returns NodeCost.MONOMORPHIC
as a
default value.public final void clearSourceSection()
public final SourceSection getSourceSection()
public final SourceSection getEncapsulatingSourceSection()
protected final <T extends Node> T[] insert(T[] newChildren)
newChildren
- the array of new children whose parent should be updatedprotected final <T extends Node> T insert(T newChild)
newChild
- the new child whose parent should be updatedpublic final void adoptChildren()
public java.util.Map<java.lang.String,java.lang.Object> getDebugProperties()
public final Node getParent()
public final <T extends Node> T replace(T newNode, java.lang.CharSequence reason)
getSourceSection()
) associated with this node, it is transferred to the new node.newNode
- the new node that is the replacementreason
- a description of the reason for the replacementpublic final <T extends Node> T replace(T newNode)
getSourceSection()
) associated with this node, it is transferred to the new node.newNode
- the new node that is the replacementpublic final boolean isReplaceable()
true
if it is safe to replace this node.protected void onReplace(Node newNode, java.lang.CharSequence reason)
Node
to receive a notification when the
node is rewritten. This method is invoked before the actual replace has happened.newNode
- the replacement nodereason
- the reason the replace suppliedprotected void onAdopt()
Node
can implement this method to execute extra functionality when a
node is effectively inserted into the AST. The onAdopt
callback is called after the
node has been effectively inserted, and it is guaranteed to be called only once for any given
node.public final void accept(NodeVisitor nodeVisitor)
NodeVisitor.visit(Node)
method for this node and recursively also for all
child nodes.nodeVisitor
- the visitorpublic final java.lang.Iterable<Node> getChildren()
public Node copy()
@Deprecated protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException
Object.clone()
is not directly
called by subclasses. Use the copy()
method instead.clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public final RootNode getRootNode()
RootNode
or null
if there is none.public java.lang.String toString()
toString
in class java.lang.Object
public final void atomic(java.lang.Runnable closure)
public final <T> T atomic(java.util.concurrent.Callable<T> closure)
public java.lang.String getDescription()
public java.lang.String getLanguage()