Package ch.usi.si.seart.treesitter
Class Node
- java.lang.Object
-
- ch.usi.si.seart.treesitter.Node
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(Object obj)NodegetChild(int child)Get the node's child at the given index, where zero represents the first child.NodegetChildByFieldName(@NotNull String name)intgetChildCount()List<Node>getChildren()StringgetContent()NodegetDescendantForByteRange(int startByte, int endByte)intgetEndByte()PointgetEndPoint()StringgetFieldNameForChild(int child)NodegetFirstChildForByte(int offset)NodegetFirstNamedChildForByte(int offset)NodegetNextNamedSibling()NodegetNextSibling()StringgetNodeString()Deprecated, for removal: This API element is subject to removal in a future version.This operation is potentially unsafe for large treesNodegetParent()NodegetPrevNamedSibling()NodegetPrevSibling()RangegetRange()intgetStartByte()PointgetStartPoint()StringgetType()booleanhasError()inthashCode()booleanisExtra()Check if the node is 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()StringtoString()TreeCursorwalk()QueryCursorwalk(@NotNull Query query)-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getChild
public Node getChild(int child)
Get the node's child at the given index, where zero represents the first child.- Parameters:
child- The zero-indexed child position- Returns:
- The Node's child at the given index
- 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)
- Parameters:
name- The child field name- Returns:
- The node's child with the given field name
- Throws:
NullPointerException- if the field name is null
-
getChildCount
public int getChildCount()
- Returns:
- The node's number of children
-
getContent
public String getContent()
- Returns:
- The source code content encapsulated by this node
- Since:
- 1.5.0
-
getDescendantForByteRange
public Node getDescendantForByteRange(int startByte, int endByte)
- Parameters:
startByte- The starting byte of the rangeendByte- The ending byte of the range- Returns:
- The smallest node within this node that spans the given range of bytes
- Throws:
IllegalArgumentException- ifstartByte>endByte
-
getEndByte
public int getEndByte()
- Returns:
- The node's end byte
-
getEndPoint
public Point getEndPoint()
- Returns:
- The node's end position in terms of rows and columns
-
getFieldNameForChild
public String getFieldNameForChild(int child)
- Parameters:
child- The zero-indexed child position- Returns:
- The field name for node's child at the given index,
with zero representing the first child,
nullif no field is found - 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)
- Parameters:
offset- The offset in bytes- Returns:
- The node's first child that extends beyond the given byte offset
- Throws:
IndexOutOfBoundsException- if the byte offset is outside the node's byte range
-
getFirstNamedChildForByte
public Node getFirstNamedChildForByte(int offset)
- Parameters:
offset- The offset in bytes- Returns:
- The node's first named child that extends beyond the given byte offset
- Throws:
IndexOutOfBoundsException- if the byte offset is outside the node's byte range
-
getNodeString
@Deprecated(since="1.4.0", forRemoval=true) public String getNodeString()
Deprecated, for removal: This API element is subject to removal in a future version.This operation is potentially unsafe for large trees- Returns:
- An S-expression representing the node as a string
- See Also:
SymbolicExpressionPrinter
-
getNextNamedSibling
public Node getNextNamedSibling()
- Returns:
- The node's next named sibling
-
getNextSibling
public Node getNextSibling()
- Returns:
- The node's next sibling
-
getPrevNamedSibling
public Node getPrevNamedSibling()
- Returns:
- The node's previous named sibling
-
getPrevSibling
public Node getPrevSibling()
- Returns:
- The node's previous sibling
-
getParent
public Node getParent()
- Returns:
- The node's immediate parent
-
getRange
public Range getRange()
- Returns:
- The node's range, indicating its byte and file position span
-
getStartByte
public int getStartByte()
- Returns:
- The node's start byte
-
getStartPoint
public Point getStartPoint()
- Returns:
- The node's start position in terms of rows and columns
-
getType
public String getType()
- Returns:
- The node's type as a string
-
hasError
public boolean hasError()
- Returns:
- true if the node is a syntax error or contains any syntax errors, false otherwise
-
isExtra
public boolean isExtra()
Check if the node is extra. Extra nodes represent things like comments, which are not required by the grammar, but can appear anywhere.- Returns:
- true if the node is an extra, false otherwise
-
isMissing
public boolean isMissing()
Check if the node is missing. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.- Returns:
- true if the node is missing, false otherwise
-
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:
- true if the node is named, false otherwise
-
isNull
public boolean isNull()
Check if the node is null node.- Returns:
- true if
id == 0, false otherwise
-
walk
public TreeCursor walk()
- Returns:
- A new tree cursor starting from the given node
-
walk
public QueryCursor walk(@NotNull @NotNull Query query)
- Parameters:
query- the query to run against this node's subtree- Returns:
- A new query cursor starting from the given node
- Since:
- 1.5.0
-
-