Interface AutoCompletions.Completion

Enclosing class:
AutoCompletions

public static interface AutoCompletions.Completion
A single completion. Instances must be able to determine whether they can provide a valid autocompletion, given an input string and a caret position - and, if so, also supply the completion text to insert.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the text that should be inserted for the full completion.
    Get the text that should be displayed for this completion.
    getInsertion(String text, int pos, String lastToken)
    Get the string to insert, given the provided text and position.
    Get the tokenizer needed to extract the relevant bit of the text to determine the validity and/or insertion for the completion.
    boolean
    isCompatible(String text, int pos, String lastToken)
    Test if this completion is compatible with the provided text.
  • Method Details

    • getCompletionText

      String getCompletionText()
      Get the text that should be inserted for the full completion.
      Returns:
    • getDisplayText

      String getDisplayText()
      Get the text that should be displayed for this completion. This which may include additional information that isn't part of the completion itself (e.g. method parameters, return type).
      Returns:
    • getInsertion

      String getInsertion(String text, int pos, String lastToken)
      Get the string to insert, given the provided text and position. This involves stripping off any overlapping part of the completion, so that it can be inserted at pos.
      Parameters:
      text - the full text
      pos - the current caret position
      lastToken - the final token, as output by getTokenizer(). If null, the token will be calculated - but it can improve performance to precompute tokens whenever multiple completions use the same way of determining tokens.
      Returns:
      the text to insert
    • isCompatible

      boolean isCompatible(String text, int pos, String lastToken)
      Test if this completion is compatible with the provided text.
      Parameters:
      text - the full text
      pos - the current caret position
      lastToken - the final token, as output by getTokenizer(). If null, the token will be calculated - but it can improve performance to precompute tokens whenever multiple completions use the same way of determining tokens.
      Returns:
    • getTokenizer

      default AutoCompletions.CompletionTokenizer getTokenizer()
      Get the tokenizer needed to extract the relevant bit of the text to determine the validity and/or insertion for the completion.

      Important! This exists for efficiency, so that if many completions use the same tokenizer, the (possibly long) text does not need to be re-tokenized each time. It is therefore important to return a shared instance, rather than a new object for each completion.

      Returns:
      the completion tokenizer, which must not be null
      See Also: