Package org.fife.ui.autocomplete
Class LanguageAwareCompletionProvider
java.lang.Object
org.fife.ui.autocomplete.CompletionProviderBase
org.fife.ui.autocomplete.LanguageAwareCompletionProvider
- All Implemented Interfaces:
CompletionProvider
,org.fife.ui.rtextarea.ToolTipSupplier
public class LanguageAwareCompletionProvider
extends CompletionProviderBase
implements org.fife.ui.rtextarea.ToolTipSupplier
A completion provider for the C programming language (and other languages
with similar syntax). This provider simply delegates to another provider,
depending on whether the caret is in:
- Code (plain text)
- A string
- A comment
- A documentation comment
This provider also implements the
org.fife.ui.rtextarea.ToolTipSupplier
interface, which allows it
to display tooltips for completion choices. Thus, the standard
VariableCompletion
and FunctionCompletion
completions should
be able to display tooltips with the variable declaration or function
definition (provided the RSyntaxTextArea
was registered with the
javax.swing.ToolTipManager
).
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CompletionProvider
The provider to use when completing in a comment.private CompletionProvider
The provider to use when no provider is assigned to a particular token type.private CompletionProvider
The provider to use while in documentation comments.private CompletionProvider
The provider to use when completing in a string.Fields inherited from class org.fife.ui.autocomplete.CompletionProviderBase
EMPTY_STRING
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructor subclasses can use when they don't have their default provider created at construction time.LanguageAwareCompletionProvider
(CompletionProvider defaultProvider) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Calling this method will result in anUnsupportedOperationException
being thrown.Returns the text just before the current caret position that could be the start of something auto-completable.Returns the completion provider to use for comments.getCompletionsAt
(JTextComponent tc, Point p) Returns the completions that have been entered at the specified visual location.protected List
<Completion> Does the dirty work of creating a list of completions.Returns the completion provider used when one isn't defined for a particular token type.Returns the completion provider to use for documentation comments.Returns a list of parameterized completions that have been entered at the current caret position of a text component (and thus can have their completion choices displayed).char
Returns the text that marks the end of a list of parameters to a function or method.Returns the text that separates parameters to a function or method.char
Returns the text that marks the start of a list of parameters to a function or method.private CompletionProvider
getProviderFor
(JTextComponent comp) Returns the completion provider to use at the current caret position in a text component.Returns the completion provider to use for strings.getToolTipText
(org.fife.ui.rtextarea.RTextArea textArea, MouseEvent e) Returns the tool tip to display for a mouse event.boolean
This method is called if auto-activation is enabled in the parentAutoCompletion
after the user types a single character.void
Sets the comment completion provider.void
Sets the default completion provider.void
Sets the documentation comment completion provider.void
setParameterizedCompletionParams
(char listStart, String separator, char listEnd) Calling this method will result in anUnsupportedOperationException
being thrown.void
Sets the completion provider to use while in a string.Methods inherited from class org.fife.ui.autocomplete.CompletionProviderBase
getCompletions, getListCellRenderer, getParameterChoicesProvider, getParent, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParent
-
Field Details
-
defaultProvider
The provider to use when no provider is assigned to a particular token type. -
stringCompletionProvider
The provider to use when completing in a string. -
commentCompletionProvider
The provider to use when completing in a comment. -
docCommentCompletionProvider
The provider to use while in documentation comments.
-
-
Constructor Details
-
LanguageAwareCompletionProvider
protected LanguageAwareCompletionProvider()Constructor subclasses can use when they don't have their default provider created at construction time. They should callsetDefaultCompletionProvider(CompletionProvider)
in this constructor. -
LanguageAwareCompletionProvider
Constructor.- Parameters:
defaultProvider
- The provider to use when no provider is assigned to a particular token type. This cannot benull
.
-
-
Method Details
-
clearParameterizedCompletionParams
public void clearParameterizedCompletionParams()Calling this method will result in anUnsupportedOperationException
being thrown. To set the parameter completion parameters, do so on the provider returned bygetDefaultCompletionProvider()
.- Specified by:
clearParameterizedCompletionParams
in interfaceCompletionProvider
- Overrides:
clearParameterizedCompletionParams
in classCompletionProviderBase
- Throws:
UnsupportedOperationException
- Always.- See Also:
-
getAlreadyEnteredText
Description copied from interface:CompletionProvider
Returns the text just before the current caret position that could be the start of something auto-completable.- Specified by:
getAlreadyEnteredText
in interfaceCompletionProvider
- Parameters:
comp
- The text component.- Returns:
- The text. A return value of
null
means nothing should be auto-completed; a value of an empty string (""
) means auto-completion should still be considered (i.e., all possible choices are valid).
-
getCommentCompletionProvider
Returns the completion provider to use for comments.- Returns:
- The completion provider to use.
- See Also:
-
getCompletionsAt
Description copied from interface:CompletionProvider
Returns the completions that have been entered at the specified visual location. This can be used for tool tips when the user hovers the mouse over completed text.- Specified by:
getCompletionsAt
in interfaceCompletionProvider
- Parameters:
tc
- The text component.p
- The position, usually from aMouseEvent
.- Returns:
- The completions, or an empty list if there are none.
-
getCompletionsImpl
Does the dirty work of creating a list of completions.- Specified by:
getCompletionsImpl
in classCompletionProviderBase
- Parameters:
comp
- The text component to look in.- Returns:
- The list of possible completions, or an empty list if there are none.
-
getDefaultCompletionProvider
Returns the completion provider used when one isn't defined for a particular token type.- Returns:
- The completion provider to use.
- See Also:
-
getDocCommentCompletionProvider
Returns the completion provider to use for documentation comments.- Returns:
- The completion provider to use.
- See Also:
-
getParameterizedCompletions
Description copied from interface:CompletionProvider
Returns a list of parameterized completions that have been entered at the current caret position of a text component (and thus can have their completion choices displayed).- Specified by:
getParameterizedCompletions
in interfaceCompletionProvider
- Parameters:
tc
- The text component.- Returns:
- The list of
ParameterizedCompletion
s. If no completions are available, this may benull
.
-
getParameterListEnd
public char getParameterListEnd()Description copied from interface:CompletionProvider
Returns the text that marks the end of a list of parameters to a function or method.- Specified by:
getParameterListEnd
in interfaceCompletionProvider
- Overrides:
getParameterListEnd
in classCompletionProviderBase
- Returns:
- The text for a parameter list end, for example,
'
)
', or0
if none. - See Also:
-
getParameterListSeparator
Description copied from interface:CompletionProvider
Returns the text that separates parameters to a function or method.- Specified by:
getParameterListSeparator
in interfaceCompletionProvider
- Overrides:
getParameterListSeparator
in classCompletionProviderBase
- Returns:
- The text that separates parameters, for example,
"
,
". - See Also:
-
getParameterListStart
public char getParameterListStart()Description copied from interface:CompletionProvider
Returns the text that marks the start of a list of parameters to a function or method.- Specified by:
getParameterListStart
in interfaceCompletionProvider
- Overrides:
getParameterListStart
in classCompletionProviderBase
- Returns:
- The text for a parameter list start, for example,
"
(
". - See Also:
-
getProviderFor
Returns the completion provider to use at the current caret position in a text component.- Parameters:
comp
- The text component to check.- Returns:
- The completion provider to use.
-
getStringCompletionProvider
Returns the completion provider to use for strings.- Returns:
- The completion provider to use.
- See Also:
-
isAutoActivateOkay
Description copied from interface:CompletionProvider
This method is called if auto-activation is enabled in the parentAutoCompletion
after the user types a single character. This provider should check the text at the current caret position of the text component, and decide whether auto-activation would be appropriate here. For example, aCompletionProvider
for Java might want to returntrue
for this method only if the last character typed was a '.
'.- Specified by:
isAutoActivateOkay
in interfaceCompletionProvider
- Overrides:
isAutoActivateOkay
in classCompletionProviderBase
- Parameters:
tc
- The text component.- Returns:
- Whether auto-activation would be appropriate.
-
setCommentCompletionProvider
Sets the comment completion provider.- Parameters:
provider
- The provider to use in comments.- See Also:
-
setDefaultCompletionProvider
Sets the default completion provider.- Parameters:
provider
- The provider to use when no provider is assigned to a particular token type. This cannot benull
.- See Also:
-
setDocCommentCompletionProvider
Sets the documentation comment completion provider.- Parameters:
provider
- The provider to use in comments.- See Also:
-
setParameterizedCompletionParams
Calling this method will result in anUnsupportedOperationException
being thrown. To set the parameter completion parameters, do so on the provider returned bygetDefaultCompletionProvider()
.- Specified by:
setParameterizedCompletionParams
in interfaceCompletionProvider
- Overrides:
setParameterizedCompletionParams
in classCompletionProviderBase
- Parameters:
listStart
- The character that marks the beginning of a list of parameters, such as '(
' in C or Java.separator
- Text that should separate parameters in a parameter list when one is inserted. For example, ",
".listEnd
- The character that marks the end of a list of parameters, such as ')
' in C or Java.- Throws:
UnsupportedOperationException
- Always.- See Also:
-
setStringCompletionProvider
Sets the completion provider to use while in a string.- Parameters:
provider
- The provider to use.- See Also:
-
getToolTipText
Returns the tool tip to display for a mouse event.For this method to be called, the
RSyntaxTextArea
must be registered with thejavax.swing.ToolTipManager
like so:ToolTipManager.sharedInstance().registerComponent(textArea);
- Specified by:
getToolTipText
in interfaceorg.fife.ui.rtextarea.ToolTipSupplier
- Parameters:
textArea
- The text area.e
- The mouse event.- Returns:
- The tool tip text, or
null
if none.
-