public static class LexerDocumentRenderer.DefaultLexerOffsetsCache extends LexerOffsetsCache
DefaultLexerOffsetsCache
provides rapid access for
offsets that correspond to the start of a language token. This is
used primarily for rendering purposes to speed up painting of
arbitrary regions in the document. This is done by maintaining a
boolean bitmap representing the lines of the document. A value of
"true" in the bitmap corresponds to the presence (start, middle or
end) of a multi-line token in the given line of the document. Note
that this is only based on the "type" of the token, not whether it
actually occupies multiple lines. This information allows us to
rapidly determine which line of the document we can start scanning
from in order to render some portion of the document.
This class is primarily just a utility class - it is up to users of
this class (such as the LexerDocumentRenderer) to bear responsibility
for maintaining this cache. When the document is modified, the
style provider (or maintainer of this class) must call
invalidateOffsets()
to invalidate old, potentially
incorrect cached information.
Note that this implementation makes the assumption that changes (inserts or removes) in a given line will have no affect on tokens in previous lines except possibly to lengthen or shorten a token.
Specifically, suppose token A is token in line A (though token A may not necessarily end or start on line A), and line B is a line after line A (not necessarily immediately.) The implementation assumption is that changes in line B will have no affect on the starting offset of any token A and any line A that occur before line B (though the change may affect the end offset of token A.)
If the syntax of your language you wish to render does not fit this assumption, then you will not be able to use this cache implementation.
Constructor and Description |
---|
LexerDocumentRenderer.DefaultLexerOffsetsCache(LexerDocumentRenderer documentRenderer)
Constructs a new LexerOffsetsCache for the given style provider.
|
Modifier and Type | Method and Description |
---|---|
protected int |
findClosestOffsetInternal(Lexer lexer,
LexerToken lexerToken,
int offset)
Internal implementation of findClosestOffset() that does the
real work.
|
protected void |
invalidateOffsetsInternal(int startOffset)
Invalidates all offsets larger than or equal to the given offset.
|
findClosestOffset, getDocumentRenderer, invalidateOffsets
public LexerDocumentRenderer.DefaultLexerOffsetsCache(LexerDocumentRenderer documentRenderer)
documentRenderer
- the document renderer which mantains this cacheprotected int findClosestOffsetInternal(Lexer lexer, LexerToken lexerToken, int offset)
findClosestOffsetInternal
in class LexerOffsetsCache
lexer
- the (scratch) lexer to uselexerToken
- the lexer token to useoffset
- the maximum offset to findprotected void invalidateOffsetsInternal(int startOffset)
invalidateOffsetsInternal
in class LexerOffsetsCache
startOffset
- minimum offset to remove from the cache