Class IndexScanner
java.lang.Object
org.eclipse.lemminx.extensions.index.scanner.IndexScanner
- All Implemented Interfaces:
AutoCloseable
Lightweight streaming XML scanner for workspace Bloom-index collection.
Design goals
- Reader-based — operates on a
Reader; never loads the whole file into memory. Peak heap per file = theBufferedReaderinternal buffer (~8 KB) plus the small strings captured per token. - Forward-only — no backtracking beyond a single character; a
16-char
PushbackReaderbuffer is enough for all look-ahead. - No DOM — produces only the
IndexTokenTypes needed to build aBloomFilterand locateGrammarReferences. All other XML constructs are skipped without allocation. - Inline position tracking —
lineandcolare updated on everyread()call; nopositionAt(offset)look-up against a full-document line index is needed.
Usage
try (IndexScanner scanner = new IndexScanner(Files.newBufferedReader(path))) {
IndexTokenType token;
while ((token = scanner.next()) != IndexTokenType.EOS) {
switch (token) {
case START_TAG -> System.out.println("element: " + scanner.getValue());
case ATTRIBUTE_NAME -> System.out.println("attr: " + scanner.getValue());
case ATTRIBUTE_VALUE-> System.out.println("value: " + scanner.getValue());
// ...
}
}
}
Position: getLine() and getStartChar() /
getEndChar() are 0-indexed, matching LSP conventions.
They are captured at the start of each token's value content (quotes stripped
for attribute values and DOCTYPE identifiers).
Thread safety: not thread-safe; use one instance per thread.
-
Constructor Summary
ConstructorsConstructorDescriptionIndexScanner(Reader reader) Creates a scanner that reads fromreaderwith no character limit.IndexScanner(Reader reader, int maxChars) Creates a scanner that reads fromreaderand stops aftermaxCharscharacters. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()int0-indexed exclusive end column of the token value.intgetLine()0-indexed line number of the token start.intAbsolute character offset of the token start in the source stream.int0-indexed start column of the token value (LSPcharacter).getValue()Returns the string value of the last token (quotes stripped for values).booleanReturnstrueif scanning stopped because themaxCharslimit was reached before the end of the stream.next()Advances to the next significant token and returns its type.
-
Constructor Details
-
IndexScanner
Creates a scanner that reads fromreaderwith no character limit. The reader is wrapped in aBufferedReader(8 KB) unless it already is one.- Parameters:
reader- source of XML content; the scanner takes ownership and closes it.
-
IndexScanner
Creates a scanner that reads fromreaderand stops aftermaxCharscharacters. UseisPartial()after scanning to check whether the limit was hit.- Parameters:
reader- source of XML content; the scanner takes ownership and closes it.maxChars- maximum characters to consume;Integer.MAX_VALUE= no limit.
-
-
Method Details
-
next
Advances to the next significant token and returns its type.- Returns:
- the next token, or
IndexTokenType.EOSat end of stream. - Throws:
IOException- if the underlying reader fails.
-
getValue
Returns the string value of the last token (quotes stripped for values). -
getOffset
public int getOffset()Absolute character offset of the token start in the source stream. -
getLine
public int getLine()0-indexed line number of the token start. -
getStartChar
public int getStartChar()0-indexed start column of the token value (LSPcharacter). -
getEndChar
public int getEndChar()0-indexed exclusive end column of the token value. -
isPartial
public boolean isPartial()Returnstrueif scanning stopped because themaxCharslimit was reached before the end of the stream. Whentrue, callers should treat the indexed file as partially scanned and conservatively include it as a candidate in all lookups. -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-