Class GrammarReferenceLocator
GrammarReference objects with pre-computed line/column positions.
Positions are computed once during locate(TextDocument) from the
TextDocument passed in. After that, callers build LSP
Locations and TextEdits
directly from the cached GrammarReference.line(),
GrammarReference.startChar(), and GrammarReference.endChar()
— no file re-read required.
This is step 2 in the rename flow (after Bloom filter pre-filtering):
WorkspaceIndex.findReferencingFiles(java.lang.String)— Bloom filter finds candidates (instant)- GrammarReferenceLocator — scans each candidate for exact positions
GrammarFileRenameSupport— builds the WorkspaceEdit from the located refs
Unlike XMLReferenceCollector which collects names into a Set
for Bloom filter indexing, this class returns GrammarReference
records with line/column positions for building TextEdits.
Use cases covered (Phase 1 — file-level references):
- UC14:
<?xml-model href="..."?>— rename grammar → update href - UC15:
xsi:noNamespaceSchemaLocation="..."— idem - UC16:
xsi:schemaLocation="ns path"— update the file path part - UC17/18:
<!DOCTYPE ... SYSTEM "...">— update system ID - UC21:
href="..."andlocation="..."on XInclude, XSLT import/include, WSDL import - xs:include/xs:import
schemaLocation="..." - OASIS XML Catalog:
uri="..."onuri,public,system,systemSuffix,uriSuffixentries
Uses LemMinX's XMLScanner (fault-tolerant, no DOM).
All comparisons are char-by-char — Strings are only created for
values that are actually returned as GrammarReferences.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<GrammarReference> locate(CharSequence text) static List<GrammarReference> locate(CharSequence text, List<IGrammarReferenceContributor> contributors) static List<GrammarReference> locate(TextDocument doc) Scans XML content and returns every grammar reference with its exact line/column position.static List<GrammarReference> locate(TextDocument doc, List<IGrammarReferenceContributor> contributors) Scans XML content and returns every grammar reference, including those discovered by extension-providedIGrammarReferenceContributors.static List<GrammarReference> locateReferencesTo(CharSequence text, String fileName) Finds grammar references intextwhose filename portion equalsfileName.static List<GrammarReference> locateReferencesTo(CharSequence text, String fileName, List<IGrammarReferenceContributor> contributors) static List<GrammarReference> locateReferencesTo(CharSequence text, Path targetPath, Path referencingFile) Finds grammar references intextthat actually resolve totargetPathwhen the containing file isreferencingFile.static List<GrammarReference> locateReferencesTo(CharSequence text, Path targetPath, Path referencingFile, List<IGrammarReferenceContributor> contributors) static List<GrammarReference> locateReferencesTo(TextDocument doc, Path targetPath, Path referencingFile, List<IGrammarReferenceContributor> contributors) Finds grammar references indocthat actually resolve totargetPathwhen the containing file isreferencingFile.static List<GrammarReference> locateReferencesWithValue(CharSequence text, String identifier) Finds grammar references intextwhose value exactly equalsidentifier.static List<GrammarReference> locateReferencesWithValue(CharSequence text, String identifier, List<IGrammarReferenceContributor> contributors) static List<GrammarReference> locateReferencesWithValue(List<GrammarReference> all, String identifier)
-
Constructor Details
-
GrammarReferenceLocator
public GrammarReferenceLocator()
-
-
Method Details
-
locate
Scans XML content and returns every grammar reference with its exact line/column position.Use case (indexing):
WorkspaceIndex.indexFile(java.nio.file.Path)reads a bounded head oforder.xmlinto aTextDocumentand passes it here. The returned references — e.g.[XML_MODEL_HREF line=0,col=17-27 "schema.xsd"]— are cached in theFileBloomEntryand used for all subsequent code-lens counts, Find References, and rename edits without re-reading the file.- Parameters:
doc- the XML document to scan (may be a head-limited fragment).- Returns:
- all located grammar references; empty if none found.
-
locate
public static List<GrammarReference> locate(TextDocument doc, List<IGrammarReferenceContributor> contributors) Scans XML content and returns every grammar reference, including those discovered by extension-providedIGrammarReferenceContributors.- Parameters:
doc- the XML document to scan.contributors- extension-provided contributors for non-standard grammar reference attributes.- Returns:
- all located grammar references; empty if none found.
-
locate
- Parameters:
text- raw XML content.- Returns:
- all located grammar references; empty if none found.
-
locate
public static List<GrammarReference> locate(CharSequence text, List<IGrammarReferenceContributor> contributors) - Parameters:
text- raw XML content.contributors- extension-provided contributors.- Returns:
- all located grammar references; empty if none found.
-
locateReferencesTo
Finds grammar references intextwhose filename portion equalsfileName.Use case: Bloom-filter pre-filtering for rename: quickly find candidate references in
order.xmlwhen renamingschema.xsd. A referencehref="../schemas/schema.xsd"matches because its last path segment is"schema.xsd". Callers that need path accuracy should uselocateReferencesTo(CharSequence, Path, Path)instead.- Parameters:
text- XML content to scan.fileName- bare filename to match (e.g."schema.xsd").- Returns:
- references whose last path segment equals
fileName; empty if none.
-
locateReferencesTo
public static List<GrammarReference> locateReferencesTo(CharSequence text, String fileName, List<IGrammarReferenceContributor> contributors) -
locateReferencesTo
public static List<GrammarReference> locateReferencesTo(CharSequence text, Path targetPath, Path referencingFile) Finds grammar references intextthat actually resolve totargetPathwhen the containing file isreferencingFile.This is the path-accurate variant used by Find References and the code lens participant. Without path resolution, two XSD files named
foo.xsdin different directories would each claim references that belong to the other.Use case: Workspace has
schemas/order.xsdandlib/order.xsd.data.xmlcontainshref="schemas/order.xsd". Openinglib/order.xsdmust show 0 references; openingschemas/order.xsdmust show 1 reference. This method resolves"schemas/order.xsd"relative todata.xml's directory and compares with the target path.- Parameters:
text- XML content to scan.targetPath- absolute path of the grammar file being queried.referencingFile- absolute path of the file being scanned.- Returns:
- references that resolve to
targetPath; empty if none.
-
locateReferencesTo
public static List<GrammarReference> locateReferencesTo(CharSequence text, Path targetPath, Path referencingFile, List<IGrammarReferenceContributor> contributors) -
locateReferencesTo
public static List<GrammarReference> locateReferencesTo(TextDocument doc, Path targetPath, Path referencingFile, List<IGrammarReferenceContributor> contributors) Finds grammar references indocthat actually resolve totargetPathwhen the containing file isreferencingFile.Use case — rename with open document: When a file is open in the editor and the user has made edits, cached line/column positions may no longer match the live DOM.
GrammarFileRenameSupportpasses the live document content here to recompute accurate positions before building the renameTextEdits.- Parameters:
doc- live document content.targetPath- absolute path of the grammar file being renamed.referencingFile- absolute path of the file being scanned.contributors- extension-provided contributors.- Returns:
- references that resolve to
targetPath; empty if none.
-
locateReferencesWithValue
public static List<GrammarReference> locateReferencesWithValue(CharSequence text, String identifier) Finds grammar references intextwhose value exactly equalsidentifier.Used by catalog code lenses to verify that a candidate file actually references a grammar via a catalog key (systemId, publicId, or URI name) rather than by filename. Unlike
locateReferencesTo(CharSequence, String), this method does not strip path segments — the full value must matchidentifierexactly.- Parameters:
text- XML content to scan.identifier- catalog key to match (e.g."http://example.org/schema").- Returns:
- references whose value equals
identifier; empty if none.
-
locateReferencesWithValue
public static List<GrammarReference> locateReferencesWithValue(CharSequence text, String identifier, List<IGrammarReferenceContributor> contributors) -
locateReferencesWithValue
public static List<GrammarReference> locateReferencesWithValue(List<GrammarReference> all, String identifier)
-