Class RNCNode
- All Implemented Interfaces:
RNCRange
- Direct Known Subclasses:
RNCAttribute,RNCDatatypesDecl,RNCDefine,RNCDiv,RNCDocument,RNCElement,RNCFileReferenceNode,RNCNamespaceDecl,RNCStart
Each node represents a span of text in the source document, defined by a
start offset (inclusive) and an end offset (exclusive). Nodes form a tree via
parent-child relationships: the root is always an RNCDocument, and
children are specific constructs like RNCElement, RNCAttribute,
RNCDefine, etc.
Use case: the RNCParser builds an AST of RNCNode subclasses
from a .rnc file. This tree is then used by language features (hover,
definition, code lens) to locate defines, elements, and other constructs.
Example AST for start = element root \{ text \}:
RNCDocument └─ RNCStart (start=0, end=5) └─ RNCElement (start=8, end=30, name="root")
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child node and sets its parent to this node.findNodeAt(int offset) Finds the deepest node in the tree that contains the given offset.Returns the list of child nodes (nevernull, returns empty list if no children).intgetEnd()Returns the exclusive end offset of this node in the source text.abstract RNCNodeTypeWalks up the parent chain to find the rootRNCDocument.Returns the parent node, ornullfor the rootRNCDocument.intgetStart()Returns the inclusive start offset of this node in the source text.getText()Returns the source text spanned by this node.booleanReturns whether this node has any child nodes.booleanisClosed()Returns whether this node has been properly closed (e.g. the parser found a matching closing brace\}).voidsetClosed(boolean closed) Sets whether this node is closed.voidsetEnd(int end) Sets the exclusive end offset of this node.voidsetStart(int start) Sets the inclusive start offset of this node.
-
Constructor Details
-
RNCNode
public RNCNode(int start, int end) Creates a new node spanning the given offsets.- Parameters:
start- the inclusive start offset.end- the exclusive end offset (may be adjusted later as more tokens are parsed).
-
-
Method Details
-
getStart
public int getStart()Returns the inclusive start offset of this node in the source text. -
setStart
public void setStart(int start) Sets the inclusive start offset of this node.- Parameters:
start- the new start offset.
-
getEnd
public int getEnd()Returns the exclusive end offset of this node in the source text. -
setEnd
public void setEnd(int end) Sets the exclusive end offset of this node. Called by the parser when the node's extent is fully determined (e.g. when the closing brace is found).- Parameters:
end- the new end offset.
-
getParent
Returns the parent node, ornullfor the rootRNCDocument.- Returns:
- the parent node.
-
addChild
Adds a child node and sets its parent to this node.- Parameters:
child- the child node to add.
-
getChildren
Returns the list of child nodes (nevernull, returns empty list if no children).- Returns:
- the children.
-
hasChildren
public boolean hasChildren()Returns whether this node has any child nodes.- Returns:
trueif this node has children.
-
isClosed
public boolean isClosed()Returns whether this node has been properly closed (e.g. the parser found a matching closing brace\}).Use case: used by diagnostics to detect unclosed blocks like
element root \{} with no matching {@code \}.- Returns:
trueif the node is closed.
-
setClosed
public void setClosed(boolean closed) Sets whether this node is closed.- Parameters:
closed-trueif a matching close token was found.
-
getOwnerDocument
Walks up the parent chain to find the rootRNCDocument.Use case: model classes like
RNCDefineuse this to access the source text for extracting their name or body content.- Specified by:
getOwnerDocumentin interfaceRNCRange- Returns:
- the owning
RNCDocument, ornullif not attached.
-
getText
Returns the source text spanned by this node.- Returns:
- the text from
getStart()togetEnd(), ornullif this node is not attached to a document.
-
findNodeAt
Finds the deepest node in the tree that contains the given offset.Use case: used to determine which AST construct the cursor is inside, for context-sensitive features like completion.
- Parameters:
offset- the character offset to look up.- Returns:
- the deepest node containing the offset (may be
this).
-
getNodeType
-