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()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.NodegetDescendantForByteRange(int startByte, int endByte)Deprecated, for removal: This API element is subject to removal in a future version.UsegetDescendant(int, int)insteadintgetEndByte()PointgetEndPoint()StringgetFieldNameForChild(int child)NodegetFirstChildForByte(int offset)NodegetFirstNamedChildForByte(int offset)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()NodegetNextSibling()NodegetParent()NodegetPrevNamedSibling()NodegetPrevSibling()RangegetRange()intgetStartByte()PointgetStartPoint()SymbolgetSymbol()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
@Deprecated(since="1.6.0", forRemoval=true) public Node getDescendantForByteRange(int startByte, int endByte)
Deprecated, for removal: This API element is subject to removal in a future version.UsegetDescendant(int, int)instead- Returns:
- The smallest node within this node that spans the given range of bytes
-
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 is nullIllegalArgumentException- 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
-
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:
ByteOffsetOutOfBoundsException- 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:
ByteOffsetOutOfBoundsException- if the byte offset is outside the node's byte range
-
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 is nullIllegalArgumentException- 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()
- 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
-
getSymbol
public Symbol getSymbol()
- Returns:
- The node's symbol
- Since:
- 1.6.0
-
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
-
-