Package ch.usi.si.seart.treesitter
Class Node
- java.lang.Object
-
- ch.usi.si.seart.treesitter.Node
-
-
Constructor Summary
Constructors Constructor Description Node()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)NodegetChild(int child)Get the childNodeat the given index.NodegetChildByFieldName(@NotNull String name)Get the childNoderesiding in a given named field.intgetChildCount()Get the number of children associated with this node.List<Node>getChildren()Get an ordered list of this node's children.StringgetContent()Get the source code content encapsulated by this node.NodegetDescendant(int startByte, int endByte)Get the smallest node within this node that spans the given range of bytes.NodegetDescendant(@NotNull Point startPoint, @NotNull Point endPoint)Get the smallest node within this node that spans the given range of points.intgetDescendantCount()Get the node's number of descendants, including one for the node itself.intgetEndByte()Get the byte offset where this node ends.PointgetEndPoint()Get the node's end position in terms of rows and columns.StringgetFieldNameForChild(int child)Get the field name of a childNoderesiding at a given index.NodegetFirstChildForByte(int offset)Get the first childNodethat extends beyond the given byte offset.NodegetFirstNamedChildForByte(int offset)Get the first named childNodethat extends beyond the given byte offset.LanguagegetLanguage()Get theLanguagethat was used to parse this node’s syntax tree.NodegetNamedChild(int child)Get the named childNodeat the given index.intgetNamedChildCount()Get the number of named children associated with this node.List<Node>getNamedChildren()Get an ordered list of this node's named children.NodegetNamedDescendant(int startByte, int endByte)Get the smallest named node within this node that spans the given range of bytes.NodegetNamedDescendant(@NotNull Point startPoint, @NotNull Point endPoint)Get the smallest named node within this node that spans the given range of points.NodegetNextNamedSibling()Get the next named siblingNode.intgetNextParseState()Get the parse state after thisNode.NodegetNextSibling()Get the next siblingNode.NodegetParent()Get the parentNode.intgetParseState()Get the parse state of thisNode.NodegetPrevNamedSibling()Get the previous named siblingNode.NodegetPrevSibling()Get the previous siblingNode.RangegetRange()Get the node'sRange, indicating its byte and row-column position span.intgetStartByte()Get the byte offset where this node starts.PointgetStartPoint()Get the node's start position in terms of rows and columns.SymbolgetSymbol()Get the syntax treeSymbolassociated with this node.StringgetType()Get the node's type as a string.booleanhasChanges()Check if this node, or any of its children, has been edited.booleanhasError()Check if this node represents a syntax error or contains any syntax errors anywhere within it.inthashCode()booleanisError()Check if this node represents a syntax error.booleanisExtra()Check if the node is an extra.booleanisMissing()Check if the node is missing.booleanisNamed()Check if the node is named.booleanisNull()Check if the node is null node.@NotNull Iterator<Node>iterator()Create an iterator over the current node's subtree.StringtoString()TreeCursorwalk()Create a newTreeCursorstarting from this node.QueryCursorwalk(@NotNull Query query)Create a newQueryCursorstarting from this node.-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getChild
public Node getChild(int child)
Get the childNodeat the given index.- Parameters:
child- the zero-indexed child position- Returns:
- the child
- Throws:
IndexOutOfBoundsException- if the index is a negative number or if it is greater or equal to the total number of children
-
getChildByFieldName
public Node getChildByFieldName(@NotNull @NotNull String name)
Get the childNoderesiding in a given named field.- Parameters:
name- the child field name- Returns:
- the node's child with the given field name
- Throws:
NullPointerException- ifnameisnull
-
getChildCount
public int getChildCount()
Get the number of children associated with this node.- Returns:
- the count of this node's children
-
getChildren
public List<Node> getChildren()
Get an ordered list of this node's children.- Returns:
- this node's children
-
getContent
public String getContent()
Get the source code content encapsulated by this node.- Returns:
- the node's source code
- Since:
- 1.5.0
-
getDescendant
public Node getDescendant(int startByte, int endByte)
Get the smallest node within this node that spans the given range of bytes.- Parameters:
startByte- the start byte of the rangeendByte- the end byte of the range- Returns:
- a descendant node
- Throws:
ByteOffsetOutOfBoundsException- if either argument is outside of this node's byte rangeIllegalArgumentException- if:startByte< 0endByte< 0startByte>endByte
- Since:
- 1.6.0
-
getDescendant
public Node getDescendant(@NotNull @NotNull Point startPoint, @NotNull @NotNull Point endPoint)
Get the smallest node within this node that spans the given range of points.- Parameters:
startPoint- the start point of the rangeendPoint- the end point of the range- Returns:
- a descendant node
- Throws:
NullPointerException- if either argument isnullIllegalArgumentException- if any point coordinates are negative, or ifstartPointis a position that comes afterendPointPointOutOfBoundsException- if any of the arguments is outside of this node's position range- Since:
- 1.6.0
-
getDescendantCount
public int getDescendantCount()
Get the node's number of descendants, including one for the node itself.- Returns:
- the count of this node's descendants
- Since:
- 1.11.0
-
getEndByte
public int getEndByte()
Get the byte offset where this node ends.- Returns:
- the node's end byte
-
getEndPoint
public Point getEndPoint()
Get the node's end position in terms of rows and columns.- Returns:
- the node's end position
-
getFieldNameForChild
public String getFieldNameForChild(int child)
Get the field name of a childNoderesiding at a given index.- Parameters:
child- the zero-indexed child position- Returns:
- the child field name,
nullif child does not reside in a field - Throws:
IndexOutOfBoundsException- if the index is a negative number or if it is greater or equal to the total number of children
-
getFirstChildForByte
public Node getFirstChildForByte(int offset)
Get the first childNodethat extends beyond the given byte offset.- Parameters:
offset- the offset in bytes- Returns:
- the child
- Throws:
ByteOffsetOutOfBoundsException- if the byte offset is outside the node's byte range
-
getFirstNamedChildForByte
public Node getFirstNamedChildForByte(int offset)
Get the first named childNodethat extends beyond the given byte offset.- Parameters:
offset- the offset in bytes- Returns:
- the child
- Throws:
ByteOffsetOutOfBoundsException- if the byte offset is outside the node's byte range
-
getLanguage
public Language getLanguage()
Get theLanguagethat was used to parse this node’s syntax tree.- Returns:
- the node's language
- Since:
- 1.9.0
-
getNamedChild
public Node getNamedChild(int child)
Get the named childNodeat the given index.- Parameters:
child- the zero-indexed child position- Returns:
- the named child
- Throws:
IndexOutOfBoundsException- if the index is a negative number or if it is greater or equal to the total number of named children- Since:
- 1.9.0
-
getNamedChildCount
public int getNamedChildCount()
Get the number of named children associated with this node.- Returns:
- the count of this node's named children
- Since:
- 1.9.0
-
getNamedChildren
public List<Node> getNamedChildren()
Get an ordered list of this node's named children.- Returns:
- this node's named children
- Since:
- 1.9.0
-
getNamedDescendant
public Node getNamedDescendant(int startByte, int endByte)
Get the smallest named node within this node that spans the given range of bytes.- Parameters:
startByte- the start byte of the rangeendByte- the end byte of the range- Returns:
- a named descendant node
- Throws:
ByteOffsetOutOfBoundsException- if either argument is outside of this node's byte rangeIllegalArgumentException- if:startByte< 0endByte< 0startByte>endByte
- Since:
- 1.6.0
-
getNamedDescendant
public Node getNamedDescendant(@NotNull @NotNull Point startPoint, @NotNull @NotNull Point endPoint)
Get the smallest named node within this node that spans the given range of points.- Parameters:
startPoint- the start point of the rangeendPoint- the end point of the range- Returns:
- a named descendant node
- Throws:
NullPointerException- if either argument isnullIllegalArgumentException- if any point coordinates are negative, or ifstartPointis a position that comes afterendPointPointOutOfBoundsException- if any of the arguments is outside of this node's position range- Since:
- 1.6.0
-
getNextNamedSibling
public Node getNextNamedSibling()
Get the next named siblingNode.- Returns:
- the next named sibling,
nullif there is none
-
getNextParseState
public int getNextParseState()
Get the parse state after thisNode.- Returns:
- the next parse state
- Since:
- 1.11.0
-
getNextSibling
public Node getNextSibling()
Get the next siblingNode.- Returns:
- the next sibling,
nullif there is none
-
getPrevNamedSibling
public Node getPrevNamedSibling()
Get the previous named siblingNode.- Returns:
- the previous named sibling,
nullif there is none
-
getPrevSibling
public Node getPrevSibling()
Get the previous siblingNode.- Returns:
- the previous sibling,
nullif there is none
-
getParent
public Node getParent()
Get the parentNode.- Returns:
- the parent,
nullif there is none
-
getParseState
public int getParseState()
Get the parse state of thisNode.- Returns:
- the parse state
- Since:
- 1.11.0
-
getRange
public Range getRange()
Get the node'sRange, indicating its byte and row-column position span.- Returns:
- the node's range
-
getStartByte
public int getStartByte()
Get the byte offset where this node starts.- Returns:
- the node's start byte
-
getStartPoint
public Point getStartPoint()
Get the node's start position in terms of rows and columns.- Returns:
- the node's start position
-
getSymbol
public Symbol getSymbol()
Get the syntax treeSymbolassociated with this node.- Returns:
- the node's symbol
- Since:
- 1.6.0
-
getType
public String getType()
Get the node's type as a string.- Returns:
- the node's type
-
hasChanges
public boolean hasChanges()
Check if this node, or any of its children, has been edited.- Returns:
trueif the node has been edited, or contains one such child in its subtree,falseotherwise- Since:
- 1.11.0
-
hasError
public boolean hasError()
Check if this node represents a syntax error or contains any syntax errors anywhere within it. Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.- Returns:
trueif the node is anERROR, or contains one such child in its subtree,falseotherwise
-
isError
public boolean isError()
Check if this node represents a syntax error. Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.- Returns:
trueif the node is anERROR,falseotherwise- Since:
- 1.11.0
-
isExtra
public boolean isExtra()
Check if the node is an extra. Extra nodes represent things like comments, which are not required by the grammar, but can appear anywhere.- Returns:
trueif the node is an extra,falseotherwise
-
isMissing
public boolean isMissing()
Check if the node is missing. These nodes are inserted by the parser in order to recover from certain kinds of syntax errors.- Returns:
trueif the node isMISSING,falseotherwise
-
isNamed
public boolean isNamed()
Check if the node is named. Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.- Returns:
trueif the node is named,falseotherwise
-
isNull
public boolean isNull()
Check if the node is null node.- Returns:
trueifid == 0,falseotherwise
-
walk
public TreeCursor walk()
Create a newTreeCursorstarting from this node.- Returns:
- a tree cursor
-
walk
public QueryCursor walk(@NotNull @NotNull Query query)
Create a newQueryCursorstarting from this node.- Parameters:
query- the query to run against this node's subtree- Returns:
- a query cursor
- Since:
- 1.5.0
-
-