java.lang.Object
org.eclipse.lemminx.extensions.relaxng.grammar.rnc.RNCNode
All Implemented Interfaces:
RNCRange
Direct Known Subclasses:
RNCAttribute, RNCDatatypesDecl, RNCDefine, RNCDiv, RNCDocument, RNCElement, RNCFileReferenceNode, RNCNamespaceDecl, RNCStart

public abstract class RNCNode extends Object implements RNCRange
Base class for all nodes in the RNC (RELAX NG Compact Syntax) abstract syntax tree.

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
    Constructor
    Description
    RNCNode(int start, int end)
    Creates a new node spanning the given offsets.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds 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 (never null, returns empty list if no children).
    int
    Returns the exclusive end offset of this node in the source text.
    abstract RNCNodeType
     
    Walks up the parent chain to find the root RNCDocument.
    Returns the parent node, or null for the root RNCDocument.
    int
    Returns the inclusive start offset of this node in the source text.
    Returns the source text spanned by this node.
    boolean
    Returns whether this node has any child nodes.
    boolean
    Returns whether this node has been properly closed (e.g. the parser found a matching closing brace \}).
    void
    setClosed(boolean closed)
    Sets whether this node is closed.
    void
    setEnd(int end)
    Sets the exclusive end offset of this node.
    void
    setStart(int start)
    Sets the inclusive start offset of this node.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.
      Specified by:
      getStart in interface RNCRange
      Returns:
      the start offset.
    • 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.
      Specified by:
      getEnd in interface RNCRange
      Returns:
      the end offset.
    • 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

      public RNCNode getParent()
      Returns the parent node, or null for the root RNCDocument.
      Returns:
      the parent node.
    • addChild

      public void addChild(RNCNode child)
      Adds a child node and sets its parent to this node.
      Parameters:
      child - the child node to add.
    • getChildren

      public List<RNCNode> getChildren()
      Returns the list of child nodes (never null, returns empty list if no children).
      Returns:
      the children.
    • hasChildren

      public boolean hasChildren()
      Returns whether this node has any child nodes.
      Returns:
      true if 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:
      true if the node is closed.
    • setClosed

      public void setClosed(boolean closed)
      Sets whether this node is closed.
      Parameters:
      closed - true if a matching close token was found.
    • getOwnerDocument

      public RNCDocument getOwnerDocument()
      Walks up the parent chain to find the root RNCDocument.

      Use case: model classes like RNCDefine use this to access the source text for extracting their name or body content.

      Specified by:
      getOwnerDocument in interface RNCRange
      Returns:
      the owning RNCDocument, or null if not attached.
    • getText

      public String getText()
      Returns the source text spanned by this node.
      Returns:
      the text from getStart() to getEnd(), or null if this node is not attached to a document.
    • findNodeAt

      public RNCNode findNodeAt(int offset)
      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

      public abstract RNCNodeType getNodeType()