public interface ASTNode extends UserDataHolder
PsiBuilder
,
out of which a PSI tree is then created.PsiElement
Modifier and Type | Field and Description |
---|---|
static ASTNode[] |
EMPTY_ARRAY |
Modifier and Type | Method and Description |
---|---|
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 . |
void |
addLeaf(IElementType leafType,
java.lang.CharSequence leafText,
ASTNode anchorBefore)
Add leaf element with specified type and text in the child list.
|
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 |
findChildByType(IElementType type,
ASTNode anchor)
Returns the first child after anchor of the specified node which has the specified type.
|
ASTNode |
findChildByType(TokenSet typesSet)
Returns the first child of the specified node which has type from specified set.
|
ASTNode |
findChildByType(TokenSet typesSet,
ASTNode anchor)
Returns the first child after anchor of the specified node which has type from specified set.
|
ASTNode |
findLeafElementAt(int offset)
Finds a leaf child node at the specified offset from the start of the text range of this node.
|
java.lang.CharSequence |
getChars()
Returns same text getText() returns but might be more effective eliminating toString() transformation from internal CharSequence representation
|
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.
|
<T extends PsiElement> |
getPsi(java.lang.Class<T> clazz)
Checks and returns the PSI element for this node.
|
int |
getStartOffset()
Returns the starting offset of the node text in the document.
|
default int |
getStartOffsetInParent()
Returns the starting offset of the node text relative to
getTreeParent() . |
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 next sibling of this node in the tree.
|
ASTNode |
getTreeParent()
Returns the parent of this node in the tree.
|
ASTNode |
getTreePrev()
Returns the previous 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.
|
getUserData, putUserData
static final ASTNode[] EMPTY_ARRAY
IElementType getElementType()
java.lang.String getText()
java.lang.CharSequence getChars()
PsiElement.textMatches(java.lang.CharSequence)
,
textContains(char)
boolean textContains(char c)
c
- the character to search for.int getStartOffset()
default int getStartOffsetInParent()
getTreeParent()
.int getTextLength()
TextRange getTextRange()
ASTNode getTreeParent()
ASTNode getFirstChildNode()
ASTNode getLastChildNode()
ASTNode getTreeNext()
ASTNode getTreePrev()
ASTNode [] getChildren(TokenSet filter)
filter
- the token set used to filter the returned children, or null if
all children should be returned.void addChild(ASTNode child)
child
- the child node to add.void addChild(ASTNode child, ASTNode anchorBefore)
child
- the child node to add.anchorBefore
- the node before which the child node is inserted (null
to add a child as a last node).void addLeaf(IElementType leafType, java.lang.CharSequence leafText, ASTNode anchorBefore)
leafType
- type of leaf element to add.leafText
- text of added leaf.anchorBefore
- the node before which the child node is inserted.void removeChild(ASTNode child)
child
- the child node to remove.void removeRange(ASTNode firstNodeToRemove, ASTNode firstNodeToKeep)
firstNodeToRemove
,
up to and not including firstNodeToKeep
.firstNodeToRemove
- the first child node to remove from the tree.firstNodeToKeep
- the first child node to keep in the tree.void replaceChild(ASTNode oldChild, ASTNode newChild)
oldChild
- the child node to replace.newChild
- the node to replace with.void replaceAllChildrenToChildrenOf(ASTNode anotherParent)
anotherParent
- the parent node whose children are used for replacement.void addChildren(ASTNode firstChild, ASTNode firstChildToNotAdd, ASTNode anchorBefore)
firstChild
, up to and not including firstChildToNotAdd
.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.java.lang.Object clone()
ASTNode copyElement()
ASTNode findLeafElementAt(int offset)
offset
- the relative offset for which the child node is requested.<T> T getCopyableUserData(Key<T> key)
key
- the key for accessing the user data object.putCopyableUserData(Key, Object)
<T> void putCopyableUserData(Key<T> key, T value)
key
- the key for accessing the user data object.value
- the user data object to attach.getCopyableUserData(Key)
ASTNode findChildByType(IElementType type)
type
- the type of the node to return.ASTNode findChildByType(IElementType type, ASTNode anchor)
type
- the type of the node to return.anchor
- to start search fromASTNode findChildByType(TokenSet typesSet)
typesSet
- the token set used to filter the returned children.ASTNode findChildByType(TokenSet typesSet, ASTNode anchor)
typesSet
- the token set used to filter the returned children.anchor
- to start search fromPsiElement getPsi()
<T extends PsiElement> T getPsi(java.lang.Class<T> clazz)
clazz
- expected psi class