- All Superinterfaces:
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:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified child node as the last child of this node.voidAdds the specified child node at the specified position in the child list.voidaddChildren(@NotNull 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 withfirstChild, up to and not includingfirstChildToNotAdd.voidaddLeaf(@NotNull IElementType leafType, @NotNull CharSequence leafText, @Nullable ASTNode anchorBefore) Add leaf element with specified type and text in the child list.@NotNull Objectclone()Creates and returns a deep copy of the AST tree part starting at this node.Creates a copy of the entire AST tree containing this node and returns a counterpart of this node in the resulting tree.@Nullable ASTNodefindChildByType(@NotNull IElementType type) Returns the first child of the specified node which has the specified type.@Nullable ASTNodefindChildByType(@NotNull IElementType type, @Nullable ASTNode anchor) Returns the first child after anchor of the specified node which has the specified type.@Nullable ASTNodefindChildByType(@NotNull TokenSet typesSet) Returns the first child of the specified node which has type from specified set.@Nullable ASTNodefindChildByType(@NotNull TokenSet typesSet, @Nullable ASTNode anchor) Returns the first child after anchor of the specified node which has type from specified set.@Nullable ASTNodefindLeafElementAt(int offset) Finds a leaf child node at the specified offset from the start of the text range of this node.@NotNull CharSequencegetChars()Returns same text getText() returns but might be more effective eliminating toString() transformation from internal CharSequence representationASTNode @NotNull []getChildren(@Nullable TokenSet filter) Returns the list of children of the specified node, optionally filtered by the specified token type filter.<T> TgetCopyableUserData(@NotNull Key<T> key) Returns a copyable user data object attached to this node.@NotNull IElementTypeReturns the type of this node.Returns the first child of this node in the tree.Returns the last child of this node in the tree.getPsi()Returns the PSI element for this node.<T extends PsiElement>
TChecks and returns the PSI element for this node.intReturns the starting offset of the node text in the document.default intReturns the starting offset of the node text relative togetTreeParent().@NotNull StringgetText()Returns the text of this node.intReturns the length of the node text.Returns the text range (a combination of starting offset in the document and length) for this node.Returns the next sibling of this node in the tree.Returns the parent of this node in the tree.Returns the previous sibling of this node in the tree.<T> voidputCopyableUserData(@NotNull Key<T> key, T value) Attaches a copyable user data object to this node.voidremoveChild(@NotNull ASTNode child) Removes the specified node from the list of children of this node.voidremoveRange(@NotNull ASTNode firstNodeToRemove, ASTNode firstNodeToKeep) Removes a range of nodes from the list of children, starting withfirstNodeToRemove, up to and not includingfirstNodeToKeep.voidreplaceAllChildrenToChildrenOf(@NotNull ASTNode anotherParent) Replaces all child nodes with the children of the specified node.voidreplaceChild(@NotNull ASTNode oldChild, @NotNull ASTNode newChild) Replaces the specified child node with another node.booleantextContains(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 Details
-
EMPTY_ARRAY
-
-
Method Details
-
getElementType
Returns the type of this node.- Returns:
- the element type.
-
getText
Returns the text of this node. Note: This call requires traversing whole subtree, so it can be expensive for composite nodes, and should be avoided if possible.- Returns:
- the node text.
-
getChars
Returns same text getText() returns but might be more effective eliminating toString() transformation from internal CharSequence representation Note: This call requires traversing whole subtree, so it can be expensive for composite nodes, and should be avoided if possible.- Returns:
- the node text.
- See Also:
-
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. Note: it works in O(tree_depth) time, which can be slow in deep trees, so invoking this method should be avoided if possible.- Returns:
- the start offset.
-
getStartOffsetInParent
default int getStartOffsetInParent()Returns the starting offset of the node text relative togetTreeParent().- Returns:
- the start offset relative to node parent
-
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. Note: it works in O(tree_depth) time, which can be slow in deep trees, so invoking this method should be avoided if possible.- Returns:
- the text range.
-
getTreeParent
ASTNode getTreeParent()Returns the parent of this node in the tree.- Returns:
- the parent node.
-
getFirstChildNode
ASTNode getFirstChildNode()Returns the first child of this node in the tree.- Returns:
- the first child node.
-
getLastChildNode
ASTNode getLastChildNode()Returns the last child of this node in the tree.- Returns:
- the last child node.
-
getTreeNext
ASTNode getTreeNext()Returns the next sibling of this node in the tree.- Returns:
- the next sibling node.
-
getTreePrev
ASTNode getTreePrev()Returns the previous sibling of this node in the tree.- Returns:
- the previous sibling node.
-
getChildren
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
Adds the specified child node as the last child of this node.- Parameters:
child- the child node to add.
-
addChild
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 (nullto add a child as a last node).
-
addLeaf
void addLeaf(@NotNull @NotNull IElementType leafType, @NotNull @NotNull CharSequence leafText, @Nullable @Nullable ASTNode anchorBefore) Add leaf element with specified type and text in the child list.- Parameters:
leafType- type of leaf element to add.leafText- text of added leaf.anchorBefore- the node before which the child node is inserted.
-
removeChild
Removes the specified node from the list of children of this node.- Parameters:
child- the child node to remove.
-
removeRange
Removes a range of nodes from the list of children, starting withfirstNodeToRemove, up to and not includingfirstNodeToKeep.- Parameters:
firstNodeToRemove- the first child node to remove from the tree.firstNodeToKeep- the first child node to keep in the tree.
-
replaceChild
Replaces the specified child node with another node.- Parameters:
oldChild- the child node to replace.newChild- the node to replace with.
-
replaceAllChildrenToChildrenOf
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(@NotNull @NotNull 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 withfirstChild, up to and not includingfirstChildToNotAdd.- 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
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
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
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
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:
-
findChildByType
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.
-
findChildByType
@Nullable @Nullable ASTNode findChildByType(@NotNull @NotNull IElementType type, @Nullable @Nullable ASTNode anchor) Returns the first child after anchor of the specified node which has the specified type.- Parameters:
type- the type of the node to return.anchor- to start search from- Returns:
- the found node, or null if none was found.
-
findChildByType
Returns the first child of the specified node which has type from specified set.- Parameters:
typesSet- the token set used to filter the returned children.- Returns:
- the found node, or null if none was found.
-
findChildByType
@Nullable @Nullable ASTNode findChildByType(@NotNull @NotNull TokenSet typesSet, @Nullable @Nullable ASTNode anchor) Returns the first child after anchor of the specified node which has type from specified set.- Parameters:
typesSet- the token set used to filter the returned children.anchor- to start search from- Returns:
- the found node, or null if none was found.
-
getPsi
PsiElement getPsi()Returns the PSI element for this node.- Returns:
- the PSI element.
-
getPsi
Checks and returns the PSI element for this node.- Parameters:
clazz- expected psi class- Returns:
- the PSI element.
-