Package org.fife.rsta.ac.html
Class HtmlCompletionProvider
java.lang.Object
org.fife.ui.autocomplete.CompletionProviderBase
org.fife.ui.autocomplete.AbstractCompletionProvider
org.fife.ui.autocomplete.DefaultCompletionProvider
org.fife.rsta.ac.html.HtmlCompletionProvider
- All Implemented Interfaces:
org.fife.ui.autocomplete.CompletionProvider
- Direct Known Subclasses:
JspCompletionProvider,PhpCompletionProvider
public class HtmlCompletionProvider
extends org.fife.ui.autocomplete.DefaultCompletionProvider
Completion provider for HTML documents.
- 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
FieldsModifier and TypeFieldDescriptionprivate booleanWhether the text last grabbed viagetAlreadyEnteredText(JTextComponent)was an HTML tag name.private StringReturns the last tag name grabbed viagetAlreadyEnteredText(JTextComponent).private Map<String, List<AttributeCompletion>> A mapping of tag names to their legal attributes.Fields inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider
segFields inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
comparator, completionsFields inherited from class org.fife.ui.autocomplete.CompletionProviderBase
EMPTY_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringThis nasty hack is just a hook for subclasses (e.g.private booleanfindLastTagNameBefore(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, org.fife.ui.rsyntaxtextarea.Token tokenList, int offs) Locates the name of the tag a given offset is in.protected List<AttributeCompletion> getAttributeCompletionsForTag(String tagName) Returns the attributes that can be code-completed for the specified tag.protected List<org.fife.ui.autocomplete.Completion> protected List<org.fife.ui.autocomplete.Completion> Returns the completions for the basic tag set.private static org.fife.ui.rsyntaxtextarea.TokengetTokenBeforeOffset(org.fife.ui.rsyntaxtextarea.Token tokenList, int offs) Returns the token before the specified offset.protected voidCallsDefaultCompletionProvider.loadFromXML(String)to load all standard HTML completions.private static booleaninsideMarkupTag(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.fife.ui.rsyntaxtextarea.Token list, int line, int offs) Returns whether the given offset is inside a markup tag (and not in string content, such as an attribute value).booleanOverridden to ensure auto-activation only occurs in a markup tag.protected booleanReturns the base implementation - basically checking that the caret comes immediately after letters.private static booleanisTagOpeningToken(org.fife.ui.rsyntaxtextarea.Token t) Returns whether this token's text is "<" or "</".Methods inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider
getCompletionsAt, getParameterizedCompletions, init, isValidChar, loadFromXML, loadFromXML, loadFromXML, loadFromXMLMethods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, removeCompletionMethods inherited from class org.fife.ui.autocomplete.CompletionProviderBase
clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent
-
Field Details
-
tagToAttrs
A mapping of tag names to their legal attributes. -
isTagName
private boolean isTagNameWhether the text last grabbed viagetAlreadyEnteredText(JTextComponent)was an HTML tag name.- See Also:
-
lastTagName
Returns the last tag name grabbed viagetAlreadyEnteredText(JTextComponent). This value is only valid ifisTagNameisfalse.
-
-
Constructor Details
-
HtmlCompletionProvider
public HtmlCompletionProvider()Constructor.
-
-
Method Details
-
defaultGetAlreadyEnteredText
This nasty hack is just a hook for subclasses (e.g.PhpCompletionProvider) to be able to get at theDefaultCompletionProviderimplementation.- Parameters:
comp- The text component.- Returns:
- The text, or
nullif none.
-
findLastTagNameBefore
private boolean findLastTagNameBefore(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, org.fife.ui.rsyntaxtextarea.Token tokenList, int offs) Locates the name of the tag a given offset is in. This method assumes that the caller has already concluded thatoffsis in fact inside a tag, and that there is a little "text" just before it.- Parameters:
doc- The document being parsed.tokenList- The token list for the current line.offs- The offset into the document to check.- Returns:
- Whether a tag name was found.
-
getAlreadyEnteredText
- Specified by:
getAlreadyEnteredTextin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
getAlreadyEnteredTextin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
getAttributeCompletionsForTag
Returns the attributes that can be code-completed for the specified tag. Subclasses can override this method to handle more than the standard set of HTML 5 tags and their attributes.- Parameters:
tagName- The tag whose attributes are being code-completed.- Returns:
- A list of attributes, or
nullif the tag is not recognized.
-
getCompletionsImpl
- Overrides:
getCompletionsImplin classorg.fife.ui.autocomplete.AbstractCompletionProvider
-
getTagCompletions
Returns the completions for the basic tag set. This method is here so subclasses can add to it if they provide additional tags (i.e. JSP).- Returns:
- The completions for the standard tag set.
-
getTokenBeforeOffset
private static org.fife.ui.rsyntaxtextarea.Token getTokenBeforeOffset(org.fife.ui.rsyntaxtextarea.Token tokenList, int offs) Returns the token before the specified offset.- Parameters:
tokenList- A list of tokens containing the offset.offs- The offset.- Returns:
- The token before the offset, or
nullif the offset was the first offset in the token list (or not in the token list at all, which would be an error).
-
initCompletions
protected void initCompletions()CallsDefaultCompletionProvider.loadFromXML(String)to load all standard HTML completions. Subclasses can override to also load additional standard tags (i.e. JSP'sjsp:*tags). -
insideMarkupTag
private static boolean insideMarkupTag(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.fife.ui.rsyntaxtextarea.Token list, int line, int offs) Returns whether the given offset is inside a markup tag (and not in string content, such as an attribute value).- Parameters:
textArea- The text area being parsed.list- The list of tokens for the current line (the line containingoffs).line- The index of the line containingoffs.offs- The offset into the text area's content to check.- Returns:
- Whether the offset is inside a markup tag.
-
isAutoActivateOkayOutsideOfMarkup
Returns the base implementation - basically checking that the caret comes immediately after letters. This is here for subclasses that sometimes auto-activate in markup, other times auto-activate in some other language, such as PHP.- Parameters:
tc- The text component.- Returns:
- Whether auto-activation is okay outside of markup.
- See Also:
-
isAutoActivateOkay
Overridden to ensure auto-activation only occurs in a markup tag.- Specified by:
isAutoActivateOkayin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
isAutoActivateOkayin classorg.fife.ui.autocomplete.CompletionProviderBase- See Also:
-
isTagOpeningToken
private static boolean isTagOpeningToken(org.fife.ui.rsyntaxtextarea.Token t) Returns whether this token's text is "<" or "</". It is assumed that whether this is a markup delimiter token is checked elsewhere.- Parameters:
t- The token to check.- Returns:
- Whether it is a tag opening token.
-