Package: groovy.console.ui.text

## [Java] Class SmartDocumentFilter

- groovy.console.ui.text.SmartDocumentFilter

-     public class SmartDocumentFilter
      extends DocumentFilter

  The document filter based on Parrot's lexer is for highlighting the content of text editor

  Since:
    3.0.0

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static List<Integer>` | `HIGHLIGHTED_TOKEN_TYPE_LIST` | Token types rendered with the reserved-word style.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `SmartDocumentFilter(DefaultStyledDocument styledDocument)` Creates a filter that styles the supplied document.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public List<Token>` | `getLatestTokenList()` Returns the tokens produced by the most recent successful parse.
    `` | `public Tuple2<Integer, Integer>` | `getRenderRange()` Returns the character range scheduled for selective re-rendering.
    `` | `public void` | `insertString(FilterBypass fb, int offset, String text, AttributeSet attrs)` Invoked prior to insertion of text into the specified Document. Subclasses that want to conditionally allow insertion should override this and only call supers implementation as necessary, or call directly into the FilterBypass. Parameters: `fb` - FilterBypass that can be used to mutate Document `offset` - the offset into the document to insert the content >= 0. All positions that track change at or after the given location will move. `string` - the string to insert `attr` - the attributes to associate with the inserted content. This may be null if there are no attributes. Throws: BadLocationException the given insert position is not a valid position within the document
    `` | `public boolean` | `isLatest()` Indicates whether the cached token list reflects the current document text.
    `` | `public void` | `remove(FilterBypass fb, int offset, int length)` Invoked prior to removal of the specified region in the specified Document. Subclasses that want to conditionally allow removal should override this and only call supers implementation as necessary, or call directly into the `FilterBypass` as necessary. Parameters: `fb` - FilterBypass that can be used to mutate Document `offset` - the offset from the beginning >= 0 `length` - the number of characters to remove >= 0 Throws: BadLocationException some portion of the removal range was not a valid part of the document. The location in the exception is the first bad position encountered.
    `` | `public void` | `reparseDocument()` Forces a full re-parse and re-render of the document with current styles.
    `` | `public void` | `replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)` Invoked prior to replacing a region of text in the specified Document. Subclasses that want to conditionally allow replace should override this and only call supers implementation as necessary, or call directly into the FilterBypass. Parameters: `fb` - FilterBypass that can be used to mutate Document `offset` - Location in Document `length` - Length of text to delete `text` - Text to insert, null indicates no text to insert `attrs` - AttributeSet indicating attributes of inserted text, null is legal. Throws: BadLocationException the given insert position is not a valid position within the document
    `` | `public void` | `setRenderRange(Tuple2<Integer, Integer> renderRange)` Limits rendering to the supplied character range for the next parse.
    `` | `public static void` | `updateStyles()` Updates all SmartDocumentFilter styles with current theme colors.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class DocumentFilter` | `equals, getClass, hashCode, insertString, notify, notifyAll, remove, replace, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final List<Integer> HIGHLIGHTED_TOKEN_TYPE_LIST

      Token types rendered with the reserved-word style.

  - ### Constructor Detail

    - #### public SmartDocumentFilter(DefaultStyledDocument styledDocument)

      Creates a filter that styles the supplied document.

      Parameters:
        `styledDocument` - the document to tokenize and highlight

  - ### Method Detail

    - #### public List<Token> getLatestTokenList()

      Returns the tokens produced by the most recent successful parse.

      Returns:
        the latest token list

    - #### public Tuple2<Integer, Integer> getRenderRange()

      Returns the character range scheduled for selective re-rendering.

      Returns:
        the current render range, or `null` if the whole document will be rendered

    - #### public void insertString(FilterBypass fb, int offset, String text, AttributeSet attrs)

      Invoked prior to insertion of text into the specified Document. Subclasses that want to conditionally allow insertion should override this and only call supers implementation as necessary, or call directly into the FilterBypass.

      Parameters:
        `fb` - FilterBypass that can be used to mutate Document
        `offset` - the offset into the document to insert the content >= 0. All positions that track change at or after the given location will move.
        `string` - the string to insert
        `attr` - the attributes to associate with the inserted content. This may be null if there are no attributes.
      Throws:
        BadLocationException the given insert position is not a valid position within the document

    - #### public boolean isLatest()

      Indicates whether the cached token list reflects the current document text.

      Returns:
        `true` if the latest parse completed successfully

    - #### public void remove(FilterBypass fb, int offset, int length)

      Invoked prior to removal of the specified region in the specified Document. Subclasses that want to conditionally allow removal should override this and only call supers implementation as necessary, or call directly into the `FilterBypass` as necessary.

      Parameters:
        `fb` - FilterBypass that can be used to mutate Document
        `offset` - the offset from the beginning >= 0
        `length` - the number of characters to remove >= 0
      Throws:
        BadLocationException some portion of the removal range was not a valid part of the document. The location in the exception is the first bad position encountered.

    - #### public void reparseDocument()

      Forces a full re-parse and re-render of the document with current styles. Clears the incremental-render cache first so every token is restyled, not just the ones that differ from the last parse.

      Since:
        6.0.0

    - #### public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs)

      Invoked prior to replacing a region of text in the specified Document. Subclasses that want to conditionally allow replace should override this and only call supers implementation as necessary, or call directly into the FilterBypass.

      Parameters:
        `fb` - FilterBypass that can be used to mutate Document
        `offset` - Location in Document
        `length` - Length of text to delete
        `text` - Text to insert, null indicates no text to insert
        `attrs` - AttributeSet indicating attributes of inserted text, null is legal.
      Throws:
        BadLocationException the given insert position is not a valid position within the document

    - #### public void setRenderRange(Tuple2<Integer, Integer> renderRange)

      Limits rendering to the supplied character range for the next parse.

      Parameters:
        `renderRange` - the inclusive start and stop offsets to re-render, or `null` for all text

    - #### public static void updateStyles()

      Updates all SmartDocumentFilter styles with current theme colors. Attribute values are sourced from ThemeManager so custom .theme files feed both this (ANTLR-token-driven) path and the regex-driven GroovyFilter path from one place. Called at init time and on theme switch.

      Since:
        6.0.0