Class XmlCompletionProvider

java.lang.Object
org.fife.ui.autocomplete.CompletionProviderBase
org.fife.ui.autocomplete.AbstractCompletionProvider
org.fife.ui.autocomplete.DefaultCompletionProvider
org.fife.rsta.ac.xml.XmlCompletionProvider
All Implemented Interfaces:
org.fife.ui.autocomplete.CompletionProvider

class XmlCompletionProvider extends org.fife.ui.autocomplete.DefaultCompletionProvider
A completion provider that, in the absence of a DTD or XML schema, makes a best guess at what completion choices the user might want for XML. It does this by looking at what XML element names and attributes have been used elsewhere in the document:

  • If the caret is not in an XML tag, no completion choices are suggested.
  • If the caret is in an XML tag name, other tag names in the document that start with that prefix are suggested.
  • If the caret is in an XML tag, but not in the tag's name, the document is parsed for other instances of that tag. If any are found, all attributes used for that tag elsewhere are suggested.
Version:
1.0
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

    org.fife.ui.autocomplete.AbstractCompletionProvider.CaseInsensitiveComparator
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final char[]
     

    Fields inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider

    seg

    Fields inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

    comparator, completions

    Fields inherited from class org.fife.ui.autocomplete.CompletionProviderBase

    EMPTY_STRING
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addCompletionImpl(String word, int desiredType)
    Creates a Completion of the proper type and adds it to the completions list.
    private Set<String>
    collectCompletionWordsAttribute(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, org.fife.ui.rsyntaxtextarea.Token inTag, int currentWordStart)
    Returns the list of attribute names to offer for completion choices for a given tag.
    private Set<String>
    collectCompletionWordsTag(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, int currentWordStart)
    Returns the list of tag names to offer for completion choices.
    protected List<org.fife.ui.autocomplete.Completion>
     
    private static int
    getDesiredTokenType(org.fife.ui.rsyntaxtextarea.Token t, int dot)
    Returns the type of token to return as completion choices, based on the current caret position.
    static final org.fife.ui.rsyntaxtextarea.Token
    getTagNameTokenForCaretOffset(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
    If the caret is inside a tag, this method returns the token representing the tag name; otherwise, null is returned.

    Methods inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider

    getAlreadyEnteredText, getCompletionsAt, getParameterizedCompletions, init, isValidChar, loadFromXML, loadFromXML, loadFromXML, loadFromXML

    Methods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

    addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, removeCompletion

    Methods inherited from class org.fife.ui.autocomplete.CompletionProviderBase

    clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, isAutoActivateOkay, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TAG_SELF_CLOSE

      private static final char[] TAG_SELF_CLOSE
  • Constructor Details

    • XmlCompletionProvider

      XmlCompletionProvider()
  • Method Details

    • addCompletionImpl

      private void addCompletionImpl(String word, int desiredType)
      Creates a Completion of the proper type and adds it to the completions list.
      Parameters:
      word - The text of the completion.
      desiredType - The completion type we're collecting.
    • collectCompletionWordsAttribute

      private Set<String> collectCompletionWordsAttribute(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, org.fife.ui.rsyntaxtextarea.Token inTag, int currentWordStart)
      Returns the list of attribute names to offer for completion choices for a given tag.
      Parameters:
      doc - The document being parsed.
      inTag - The XML tag whose attribute is being completed.
      currentWordStart - The start of the current word.
      Returns:
      The set of completion choices. This will never be null.
    • collectCompletionWordsTag

      private Set<String> collectCompletionWordsTag(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, int currentWordStart)
      Returns the list of tag names to offer for completion choices.
      Parameters:
      doc - The document being parsed.
      currentWordStart - The start of the current word.
      Returns:
      The set of completion choices. This will never be null.
    • getCompletionsImpl

      protected List<org.fife.ui.autocomplete.Completion> getCompletionsImpl(JTextComponent comp)
      Overrides:
      getCompletionsImpl in class org.fife.ui.autocomplete.AbstractCompletionProvider
    • getDesiredTokenType

      private static int getDesiredTokenType(org.fife.ui.rsyntaxtextarea.Token t, int dot)
      Returns the type of token to return as completion choices, based on the current caret position.
      Parameters:
      t - The previous "important" (e.g., non-whitespace) token.
      dot - The caret position.
      Returns:
      The token type, or TokenTypes.NULL if no completion choices should be suggested for the current caret position.
    • getTagNameTokenForCaretOffset

      public static final org.fife.ui.rsyntaxtextarea.Token getTagNameTokenForCaretOffset(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
      If the caret is inside a tag, this method returns the token representing the tag name; otherwise, null is returned.
      Parameters:
      textArea - The text area.
      Returns:
      The token representing the tag name, or null if it could not be found.