Class RNCDocument
- All Implemented Interfaces:
RNCRange
This is the root node of the RNC abstract syntax tree, holding the full source text, the document URI, and all top-level constructs (namespace declarations, datatypes declarations, start pattern, defines, includes, divs, elements, and attributes) as child nodes. It also collects parser errors.
Use case: produced by RNCParser.parse(CharSequence, String) and used
by all language features (completion, hover, definition, etc.) to access the
document structure.
Example: parsing the RNC source:
namespace a = "http://example.com"
start = root
root = element root {
attribute id { text },
name+
}
name = element name { text }
produces an RNCDocument with children:
RNCNamespaceDecl, RNCStart, RNCDefine("root"),
RNCDefine("name").
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single parser error with a code, message, and source range. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(RNCErrorCode errorCode, String message, int start, int end) Records a parser error in this document.findDefine(String name) Finds a define by name.getAllVisibleDefines(RNCInclude excludeInclude, IRNCDocumentProvider documentProvider) Returns all defines visible from this document: local defines plus defines from all included files.Returns all top-level datatypes declarations in this document.Returns all define declarations in this document, including those nested insidedivorincludeblocks.Returns the list of parser errors collected during parsing.Returns all external references in this document, including nested ones.Returns all file reference nodes (includes and externals) in this document.Returns all top-level include declarations in this document.Returns all top-level namespace declarations in this document.Returns the full source text of the document.Returns the start declaration, ornullif none exists.getText(int start, int end) Extracts a substring from the source text.getUri()Returns the document URI.booleanReturns whether adefault namespacedeclaration exists.booleanReturnstrueif this document has no meaningful content — only whitespace and comments, no declarations or patterns.booleanReturns whether this document has a top-level pattern (e.g., a standaloneelement root { text }without astart =declaration).booleanisOnElementOrAttributeName(int offset) Returnstrueif the given offset falls within the name range of anyelementorattributepattern node in the document.voidsetTextDocument(TextDocument textDocument) Methods inherited from class org.eclipse.lemminx.extensions.relaxng.grammar.rnc.RNCNode
addChild, findNodeAt, getChildren, getEnd, getOwnerDocument, getParent, getStart, getText, hasChildren, isClosed, setClosed, setEnd, setStart
-
Constructor Details
-
RNCDocument
Creates a new RNC document.- Parameters:
source- the full source text.uri- the document URI.
-
-
Method Details
-
getNodeType
- Specified by:
getNodeTypein classRNCNode
-
getTextDocument
-
setTextDocument
-
addError
Records a parser error in this document.- Parameters:
errorCode- the error code identifying the type of error.message- the human-readable error message.start- the inclusive start offset of the error range.end- the exclusive end offset of the error range.
-
getErrors
Returns the list of parser errors collected during parsing.- Returns:
- the errors (may be empty, never
null).
-
getUri
Returns the document URI.- Returns:
- the URI string (e.g.
"file:///path/to/schema.rnc").
-
getSource
Returns the full source text of the document.- Returns:
- the source text.
-
getText
Extracts a substring from the source text.- Parameters:
start- the inclusive start offset.end- the exclusive end offset.- Returns:
- the extracted text.
-
getNamespaceDecls
Returns all top-level namespace declarations in this document.Example RNC:
namespace a = "http://example.com"- Returns:
- the namespace declarations.
-
getDatatypesDecls
Returns all top-level datatypes declarations in this document.Example RNC:
datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes"- Returns:
- the datatypes declarations.
-
getDefines
Returns all define declarations in this document, including those nested insidedivorincludeblocks.Use case: used by completion (to suggest define references), code lens (to count references), highlighting, and definition (to find declarations).
Example RNC:
root = element root \{ text \}declares a define named "root".- Returns:
- all defines in the document (searches recursively through children).
-
getStartDecl
Returns the start declaration, ornullif none exists.Example RNC:
start = root- Returns:
- the
RNCStartnode, ornull.
-
hasTopLevelPattern
public boolean hasTopLevelPattern()Returns whether this document has a top-level pattern (e.g., a standaloneelement root { text }without astart =declaration).In RNC, a schema can be either a grammar form (
start = ...) or a pattern form (a bare pattern at the top level).- Returns:
trueif a top-level element or attribute pattern exists.
-
hasDefaultNamespace
public boolean hasDefaultNamespace()Returns whether adefault namespacedeclaration exists.- Returns:
trueif a default namespace is declared.
-
getIncludes
Returns all top-level include declarations in this document.Example RNC:
include "other.rnc"- Returns:
- the include declarations.
-
getExternals
Returns all external references in this document, including nested ones.Example RNC:
start = external "other.rnc" -
getFileReferences
Returns all file reference nodes (includes and externals) in this document. -
isOnElementOrAttributeName
public boolean isOnElementOrAttributeName(int offset) Returnstrueif the given offset falls within the name range of anyelementorattributepattern node in the document.Use case: rename must refuse to operate when the cursor is on an element or attribute name (e.g.
element tune \{ \}), because those names are XML node names, not define references, and renaming them would be semantically wrong.- Parameters:
offset- the character offset to test.- Returns:
trueif the offset is inside an element or attribute name.
-
getAllVisibleDefines
public List<RNCDefine> getAllVisibleDefines(RNCInclude excludeInclude, IRNCDocumentProvider documentProvider) Returns all defines visible from this document: local defines plus defines from all included files. Duplicates (by name) are excluded — local defines take precedence.- Parameters:
excludeInclude- optional include to skip (e.g. the enclosing include when completing inside an include body), ornull.documentProvider- provides access to included documents (checks open documents first, falls back to disk).- Returns:
- the list of all visible defines.
-
findDefine
Finds a define by name.Use case: used by hover (to show the define text), definition (to navigate to the declaration), and highlighting (to locate the Write highlight).
- Parameters:
name- the define name to search for (e.g. "root").- Returns:
- the matching
RNCDefine, ornullif not found.
-
hasNoContent
public boolean hasNoContent()Returnstrueif this document has no meaningful content — only whitespace and comments, no declarations or patterns.Use case: when the document has no content, RNC completion offers new-file snippets (full schema templates) instead of incremental declarations.
- Returns:
trueif the document has no content (no declarations, no non-whitespace/non-comment text).
-