com.intellij.lang
Interface ASTNode

All Superinterfaces:
UserDataHolder

public interface ASTNode
extends UserDataHolder

A node in the AST tree. The AST is an intermediate parsing tree created by PsiBuilder, out of which a PSI tree is then created.

See Also:
PsiElement

Field Summary
static ASTNode[] EMPTY_ARRAY
           
 
Method Summary
 void addChild(ASTNode child)
          Adds the specified child node as the last child of this node.
 void addChild(ASTNode child, ASTNode anchorBefore)
          Adds the specified child node at the specified position in the child list.
 void addChildren(ASTNode firstChild, ASTNode firstChildToNotAdd, ASTNode anchorBefore)
          Adds a range of nodes belonging to the same parent to the list of children of this node, starting with firstChild, up to and not including firstChildToNotAdd.
 java.lang.Object clone()
          Creates and returns a deep copy of the AST tree part starting at this node.
 ASTNode copyElement()
          Creates a copy of the entire AST tree containing this node and returns a counterpart of this node in the resulting tree.
 ASTNode findChildByType(IElementType type)
          Returns the first child of the specified node which has the specified type.
 ASTNode findLeafElementAt(int offset)
          Finds a leaf child node at the specified offset from the start of the text range of this node.
 ASTNode[] getChildren(TokenSet filter)
          Returns the list of children of the specified node, optionally filtered by the specified token type filter.
<T> T
getCopyableUserData(Key<T> key)
          Returns a copyable user data object attached to this node.
 IElementType getElementType()
          Returns the type of this node.
 ASTNode getFirstChildNode()
          Returns the first child of this node in the tree.
 ASTNode getLastChildNode()
          Returns the last child of this node in the tree.
 PsiElement getPsi()
          Returns the PSI element for this node.
 int getStartOffset()
          Returns the starting offset of the node text in the document.
 java.lang.String getText()
          Returns the text of this node.
 int getTextLength()
          Returns the length of the node text.
 TextRange getTextRange()
          Returns the text range (a combination of starting offset in the document and length) for this node.
 ASTNode getTreeNext()
          Returns the previous sibling of this node in the tree.
 ASTNode getTreeParent()
          Returns the parent of this node in the tree.
 ASTNode getTreePrev()
          Returns the next sibling of this node in the tree.
<T> void
putCopyableUserData(Key<T> key, T value)
          Attaches a copyable user data object to this node.
 void removeChild(ASTNode child)
          Removes the specified node from the list of children of this node.
 void removeRange(ASTNode firstNodeToRemove, ASTNode firstNodeToKeep)
          Removes a range of nodes from the list of children, starting with firstNodeToRemove, up to and not including firstNodeToKeep.
 void replaceAllChildrenToChildrenOf(ASTNode anotherParent)
          Replaces all child nodes with the children of the specified node.
 void replaceChild(ASTNode oldChild, ASTNode newChild)
          Replaces the specified child node with another node.
 boolean textContains(char c)
          Checks if the specified character is present in the text of this node.
 
Methods inherited from interface com.intellij.openapi.util.UserDataHolder
getUserData, putUserData
 

Field Detail

EMPTY_ARRAY

static final ASTNode[] EMPTY_ARRAY
Method Detail

getElementType

IElementType getElementType()
Returns the type of this node.

Returns:
the element type.

getText

java.lang.String getText()
Returns the text of this node.

Returns:
the node text.

textContains

boolean textContains(char c)
Checks if the specified character is present in the text of this node.

Parameters:
c - the character to search for.
Returns:
true if the character is found, false otherwise.

getStartOffset

int getStartOffset()
Returns the starting offset of the node text in the document.

Returns:
the start offset.

getTextLength

int getTextLength()
Returns the length of the node text.

Returns:
the text length.

getTextRange

TextRange getTextRange()
Returns the text range (a combination of starting offset in the document and length) for this node.

Returns:
the text range.

getTreeParent

ASTNode getTreeParent()
Returns the parent of this node in the tree.

Returns:
the parent node.

getFirstChildNode

@Nullable
ASTNode getFirstChildNode()
Returns the first child of this node in the tree.

Returns:
the first child node.

getLastChildNode

@Nullable
ASTNode getLastChildNode()
Returns the last child of this node in the tree.

Returns:
the last child node.

getTreeNext

@Nullable
ASTNode getTreeNext()
Returns the previous sibling of this node in the tree.

Returns:
the previous sibling node.

getTreePrev

@Nullable
ASTNode getTreePrev()
Returns the next sibling of this node in the tree.

Returns:
the next sibling node.

getChildren

ASTNode[] getChildren(@Nullable
                      TokenSet filter)
Returns the list of children of the specified node, optionally filtered by the specified token type filter.

Parameters:
filter - the token set used to filter the returned children, or null if all children should be returned.
Returns:
the children array.

addChild

void addChild(@NotNull
              ASTNode child)
Adds the specified child node as the last child of this node.

Parameters:
child - the child node to add.

addChild

void addChild(@NotNull
              ASTNode child,
              ASTNode anchorBefore)
Adds the specified child node at the specified position in the child list.

Parameters:
child - the child node to add.
anchorBefore - the node before which the child node is inserted.

removeChild

void removeChild(@NotNull
                 ASTNode child)
Removes the specified node from the list of children of this node.

Parameters:
child - the child node to remove.

removeRange

void removeRange(@NotNull
                 ASTNode firstNodeToRemove,
                 ASTNode firstNodeToKeep)
Removes a range of nodes from the list of children, starting with firstNodeToRemove, up to and not including firstNodeToKeep.

Parameters:
firstNodeToRemove - the first child node to remove from the tree.
firstNodeToKeep - the first child node to keep in the tree.

replaceChild

void replaceChild(@NotNull
                  ASTNode oldChild,
                  @NotNull
                  ASTNode newChild)
Replaces the specified child node with another node.

Parameters:
oldChild - the child node to replace.
newChild - the node to replace with.

replaceAllChildrenToChildrenOf

void replaceAllChildrenToChildrenOf(ASTNode anotherParent)
Replaces all child nodes with the children of the specified node.

Parameters:
anotherParent - the parent node whose children are used for replacement.

addChildren

void addChildren(ASTNode firstChild,
                 ASTNode firstChildToNotAdd,
                 ASTNode anchorBefore)
Adds a range of nodes belonging to the same parent to the list of children of this node, starting with firstChild, up to and not including firstChildToNotAdd.

Parameters:
firstChild - the first node to add.
firstChildToNotAdd - the first child node following firstChild which will not be added to the tree.
anchorBefore - the node before which the child nodes are inserted.

clone

java.lang.Object clone()
Creates and returns a deep copy of the AST tree part starting at this node.

Returns:
the top node of the copied tree (as an ASTNode object)

copyElement

ASTNode copyElement()
Creates a copy of the entire AST tree containing this node and returns a counterpart of this node in the resulting tree.

Returns:
the counterpart of this node in the copied tree.

findLeafElementAt

@Nullable
ASTNode findLeafElementAt(int offset)
Finds a leaf child node at the specified offset from the start of the text range of this node.

Parameters:
offset - the relative offset for which the child node is requested.
Returns:
the child node, or null if none is found.

getCopyableUserData

@Nullable
<T> T getCopyableUserData(Key<T> key)
Returns a copyable user data object attached to this node.

Parameters:
key - the key for accessing the user data object.
Returns:
the user data object, or null if no such object is found in the current node.
See Also:
putCopyableUserData(com.intellij.openapi.util.Key, Object)

putCopyableUserData

<T> void putCopyableUserData(Key<T> key,
                             T value)
Attaches a copyable user data object to this node. Copyable user data objects are copied when the AST tree nodes are copied.

Parameters:
key - the key for accessing the user data object.
value - the user data object to attach.
See Also:
getCopyableUserData(com.intellij.openapi.util.Key)

findChildByType

@Nullable
ASTNode findChildByType(IElementType type)
Returns the first child of the specified node which has the specified type.

Parameters:
type - the type of the node to return.
Returns:
the found node, or null if none was found.

getPsi

PsiElement getPsi()
Returns the PSI element for this node.

Returns:
the PSI element.