Class TemplateCompletion
- All Implemented Interfaces:
Comparable<Completion>,Completion,ParameterizedCompletion
The format of a template is similar to those in Eclipse. The following example would be the format for a for-loop template:
for (int ${i} = 0; ${i} < ${array}.length; ${i}++) {
${cursor}
}
In the above example, the first ${i} is a parameter for the
user to type into; all the other ${i} instances are
automatically changed to what the user types in the first one. The parameter
named ${cursor} is the "ending position" of the template. It's
where the caret moves after it cycles through all other parameters. If the
user types into it, template mode terminates. If more than one
${cursor} parameter is specified, behavior is undefined.
Two dollar signs in a row ("$$") will be evaluated as a single
dollar sign. Otherwise, the template parsing is pretty straightforward and
fault-tolerant.
Leading whitespace is automatically added to lines if the template spans
more than one line, and if used with a text component using a
PlainDocument, tabs will be converted to spaces if requested.
In order to use any instance of a ParameterizedCompletion, you need
to call AutoCompletion.setParameterAssistanceEnabled(boolean) with
a value of true first. Otherwise, any completion choices will be
visible in the completion list, but won't insert anything when selected.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.fife.ui.autocomplete.ParameterizedCompletion
ParameterizedCompletion.Parameter -
Constructor Summary
ConstructorsConstructorDescriptionTemplateCompletion(CompletionProvider provider, String inputText, String definitionString, String template) Constructor.TemplateCompletion(CompletionProvider provider, String inputText, String definitionString, String template, String shortDescription, String summary) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the "definition string" for this completion.Returns the text the user has to (start) typing for this completion to be offered.getInsertionInfo(JTextComponent tc, boolean replaceTabsWithSpaces) Returns completion information for this parameterized completion, given the specified text component.getParam(int index) Returns the specifiedParameterizedCompletion.Parameter.intReturns the number of parameters this completion takes.Returnsnull; template completions insert all of their text viagetInsertionInfo().Returns a short description of this completion.booleanReturns whether a tool tip displaying assistance for each parameter while it is being edited is appropriate for this completion.Returns the description of this auto-complete choice.voidsetShortDescription(String shortDesc) Sets the short description of this template completion.toString()Returns a string representation of this completion.Methods inherited from class org.fife.ui.autocomplete.AbstractCompletion
compareTo, getAlreadyEntered, getIcon, getProvider, getRelevance, getToolTipText, setIcon, setRelevanceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.fife.ui.autocomplete.Completion
compareTo, getAlreadyEntered, getIcon, getProvider, getRelevance, getToolTipText
-
Constructor Details
-
TemplateCompletion
public TemplateCompletion(CompletionProvider provider, String inputText, String definitionString, String template) Constructor.- Parameters:
provider- The completion provider.inputText- The text to be entered to trigger this completion.definitionString- The definition of this completion.template- The template.
-
TemplateCompletion
public TemplateCompletion(CompletionProvider provider, String inputText, String definitionString, String template, String shortDescription, String summary) Constructor.- Parameters:
provider- The completion provider.inputText- The text to be entered to trigger this completion.definitionString- The definition of this completion.template- The template.shortDescription- A short description of this completion.summary- A longer summary of this template.
-
-
Method Details
-
getInputText
Description copied from class:AbstractCompletionReturns the text the user has to (start) typing for this completion to be offered. The default implementation simply returnsCompletion.getReplacementText().- Specified by:
getInputTextin interfaceCompletion- Overrides:
getInputTextin classAbstractCompletion- Returns:
- The text the user has to (start) typing for this completion.
- See Also:
-
getReplacementText
Returnsnull; template completions insert all of their text viagetInsertionInfo().- Specified by:
getReplacementTextin interfaceCompletion- Returns:
nullalways.- See Also:
-
getSummary
Description copied from interface:CompletionReturns the description of this auto-complete choice. This can be used in a popup "description window."- Specified by:
getSummaryin interfaceCompletion- Returns:
- This item's description. This should be HTML. It may be
nullif there is no description for this completion.
-
getDefinitionString
Description copied from interface:ParameterizedCompletionReturns the "definition string" for this completion. For example, for the C "printf" function, this would return "int printf(const char *, ...)".- Specified by:
getDefinitionStringin interfaceParameterizedCompletion- Returns:
- The definition string.
-
getShortDescription
Returns a short description of this completion.- Returns:
- A short description.
- See Also:
-
getShowParameterToolTip
public boolean getShowParameterToolTip()Description copied from interface:ParameterizedCompletionReturns whether a tool tip displaying assistance for each parameter while it is being edited is appropriate for this completion.- Specified by:
getShowParameterToolTipin interfaceParameterizedCompletion- Returns:
- Whether the tool tip is appropriate to display.
-
getInsertionInfo
public ParameterizedCompletionInsertionInfo getInsertionInfo(JTextComponent tc, boolean replaceTabsWithSpaces) Description copied from interface:ParameterizedCompletionReturns completion information for this parameterized completion, given the specified text component.- Specified by:
getInsertionInfoin interfaceParameterizedCompletion- Parameters:
tc- The text component.replaceTabsWithSpaces- Whether to replace tabs with spaces.- Returns:
- The completion info.
-
getParam
Description copied from interface:ParameterizedCompletionReturns the specifiedParameterizedCompletion.Parameter.- Specified by:
getParamin interfaceParameterizedCompletion- Parameters:
index- The index of the parameter to retrieve.- Returns:
- The parameter.
- See Also:
-
getParamCount
public int getParamCount()Description copied from interface:ParameterizedCompletionReturns the number of parameters this completion takes.- Specified by:
getParamCountin interfaceParameterizedCompletion- Returns:
- The number of parameters this completion takes.
- See Also:
-
setShortDescription
Sets the short description of this template completion.- Parameters:
shortDesc- The new short description.- See Also:
-
toString
Description copied from class:AbstractCompletionReturns a string representation of this completion. The default implementation returnsAbstractCompletion.getInputText().- Overrides:
toStringin classAbstractCompletion- Returns:
- A string representation of this completion.
-