Extension SDK 10.1.2

oracle.javatools.editor.language
Class LexerDocumentRenderer.LexerOffsetsCache

java.lang.Object
  extended byoracle.javatools.editor.language.LexerDocumentRenderer.LexerOffsetsCache
Enclosing class:
LexerDocumentRenderer

public static final class LexerDocumentRenderer.LexerOffsetsCache
extends java.lang.Object

The LexerOffsetsCache 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 Summary
LexerDocumentRenderer.LexerOffsetsCache(LexerDocumentRenderer documentRenderer)
          Constructs a new LexerOffsetsCache for the given style provider.
 
Method Summary
 int findClosestOffset(Lexer lexer, LexerToken lexerToken, int offset)
          Find the closest offset in the buffer we can start scanning from that occurs at or before the indicated offset.
 void invalidateOffsets(int startOffset)
          Invalidates all offsets larger than or equal to the given offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LexerDocumentRenderer.LexerOffsetsCache

public LexerDocumentRenderer.LexerOffsetsCache(LexerDocumentRenderer documentRenderer)
Constructs a new LexerOffsetsCache for the given style provider.

Parameters:
documentRenderer - the document renderer which mantains this cache
Method Detail

findClosestOffset

public int findClosestOffset(Lexer lexer,
                             LexerToken lexerToken,
                             int offset)
Find the closest offset in the buffer we can start scanning from that occurs at or before the indicated offset. Note that this currently returns the closest "reasonable" offset based on some multi-line token guesses. It is not guaranteed to be the closest possible offset.

Parameters:
lexer - the (scratch) lexer to use
lexerToken - the lexer token to use
offset - the maximum offset to find
Returns:
the largest offset <= startOffset

invalidateOffsets

public void invalidateOffsets(int startOffset)
Invalidates all offsets larger than or equal to the given offset.

Parameters:
startOffset - minimum offset to remove from the cache

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.