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
VariableCompletionandFunctionCompletioncompletions 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
- Author:
- Robert Futrell
-
-
Field Summary
-
Fields inherited from class org.fife.ui.autocomplete.CompletionProviderBase
EMPTY_STRING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLanguageAwareCompletionProvider()Constructor subclasses can use when they don't have their default provider created at construction time.LanguageAwareCompletionProvider(CompletionProvider defaultProvider)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearParameterizedCompletionParams()Calling this method will result in anUnsupportedOperationExceptionbeing thrown.StringgetAlreadyEnteredText(JTextComponent comp)Returns the text just before the current caret position that could be the start of something auto-completable.CompletionProvidergetCommentCompletionProvider()Returns the completion provider to use for comments.List<Completion>getCompletionsAt(JTextComponent tc, Point p)Returns the completions that have been entered at the specified visual location.protected List<Completion>getCompletionsImpl(JTextComponent comp)Does the dirty work of creating a list of completions.CompletionProvidergetDefaultCompletionProvider()Returns the completion provider used when one isn't defined for a particular token type.CompletionProvidergetDocCommentCompletionProvider()Returns the completion provider to use for documentation comments.List<ParameterizedCompletion>getParameterizedCompletions(JTextComponent tc)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).chargetParameterListEnd()Returns the text that marks the end of a list of parameters to a function or method.StringgetParameterListSeparator()Returns the text that separates parameters to a function or method.chargetParameterListStart()Returns the text that marks the start of a list of parameters to a function or method.CompletionProvidergetStringCompletionProvider()Returns the completion provider to use for strings.StringgetToolTipText(org.fife.ui.rtextarea.RTextArea textArea, MouseEvent e)Returns the tool tip to display for a mouse event.booleanisAutoActivateOkay(JTextComponent tc)This method is called if auto-activation is enabled in the parentAutoCompletionafter the user types a single character.voidsetCommentCompletionProvider(CompletionProvider provider)Sets the comment completion provider.voidsetDefaultCompletionProvider(CompletionProvider provider)Sets the default completion provider.voidsetDocCommentCompletionProvider(CompletionProvider provider)Sets the documentation comment completion provider.voidsetParameterizedCompletionParams(char listStart, String separator, char listEnd)Calling this method will result in anUnsupportedOperationExceptionbeing thrown.voidsetStringCompletionProvider(CompletionProvider provider)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
-
-
-
-
Constructor Detail
-
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
public LanguageAwareCompletionProvider(CompletionProvider defaultProvider)
Constructor.- Parameters:
defaultProvider- The provider to use when no provider is assigned to a particular token type. This cannot benull.
-
-
Method Detail
-
clearParameterizedCompletionParams
public void clearParameterizedCompletionParams()
Calling this method will result in anUnsupportedOperationExceptionbeing thrown. To set the parameter completion parameters, do so on the provider returned bygetDefaultCompletionProvider().- Specified by:
clearParameterizedCompletionParamsin interfaceCompletionProvider- Overrides:
clearParameterizedCompletionParamsin classCompletionProviderBase- Throws:
UnsupportedOperationException- Always.- See Also:
setParameterizedCompletionParams(char, String, char)
-
getAlreadyEnteredText
public String getAlreadyEnteredText(JTextComponent comp)
Returns the text just before the current caret position that could be the start of something auto-completable.- Specified by:
getAlreadyEnteredTextin interfaceCompletionProvider- Parameters:
comp- The text component.- Returns:
- The text. A return value of
nullmeans 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
public CompletionProvider getCommentCompletionProvider()
Returns the completion provider to use for comments.- Returns:
- The completion provider to use.
- See Also:
setCommentCompletionProvider(CompletionProvider)
-
getCompletionsAt
public List<Completion> getCompletionsAt(JTextComponent tc, Point p)
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:
getCompletionsAtin interfaceCompletionProvider- Parameters:
tc- The text component.p- The position, usually from a MouseEvent.- Returns:
- The completions, or an empty list if there are none.
-
getCompletionsImpl
protected List<Completion> getCompletionsImpl(JTextComponent comp)
Does the dirty work of creating a list of completions.- Specified by:
getCompletionsImplin classCompletionProviderBase- Parameters:
comp- The text component to look in.- Returns:
- The list of possible completions, or an empty list if there are none.
-
getDefaultCompletionProvider
public CompletionProvider getDefaultCompletionProvider()
Returns the completion provider used when one isn't defined for a particular token type.- Returns:
- The completion provider to use.
- See Also:
setDefaultCompletionProvider(CompletionProvider)
-
getDocCommentCompletionProvider
public CompletionProvider getDocCommentCompletionProvider()
Returns the completion provider to use for documentation comments.- Returns:
- The completion provider to use.
- See Also:
setDocCommentCompletionProvider(CompletionProvider)
-
getParameterizedCompletions
public List<ParameterizedCompletion> getParameterizedCompletions(JTextComponent tc)
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:
getParameterizedCompletionsin interfaceCompletionProvider- Parameters:
tc- The text component.- Returns:
- The list of
ParameterizedCompletions. If no completions are available, this may benull.
-
getParameterListEnd
public char getParameterListEnd()
Returns the text that marks the end of a list of parameters to a function or method.- Specified by:
getParameterListEndin interfaceCompletionProvider- Overrides:
getParameterListEndin classCompletionProviderBase- Returns:
- The text for a parameter list end, for example,
'
)'. - See Also:
CompletionProvider.getParameterListStart(),CompletionProvider.getParameterListSeparator(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getParameterListSeparator
public String getParameterListSeparator()
Returns the text that separates parameters to a function or method.- Specified by:
getParameterListSeparatorin interfaceCompletionProvider- Overrides:
getParameterListSeparatorin classCompletionProviderBase- Returns:
- The text that separates parameters, for example,
"
,". - See Also:
CompletionProvider.getParameterListStart(),CompletionProvider.getParameterListEnd(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getParameterListStart
public char getParameterListStart()
Returns the text that marks the start of a list of parameters to a function or method.- Specified by:
getParameterListStartin interfaceCompletionProvider- Overrides:
getParameterListStartin classCompletionProviderBase- Returns:
- The text for a parameter list start, for example,
"
(". - See Also:
CompletionProvider.getParameterListEnd(),CompletionProvider.getParameterListSeparator(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getStringCompletionProvider
public CompletionProvider getStringCompletionProvider()
Returns the completion provider to use for strings.- Returns:
- The completion provider to use.
- See Also:
setStringCompletionProvider(CompletionProvider)
-
isAutoActivateOkay
public boolean isAutoActivateOkay(JTextComponent tc)
This method is called if auto-activation is enabled in the parentAutoCompletionafter 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, aCompletionProviderfor Java might want to returntruefor this method only if the last character typed was a '.'.- Specified by:
isAutoActivateOkayin interfaceCompletionProvider- Overrides:
isAutoActivateOkayin classCompletionProviderBase- Parameters:
tc- The text component.- Returns:
- Whether auto-activation would be appropriate.
-
setCommentCompletionProvider
public void setCommentCompletionProvider(CompletionProvider provider)
Sets the comment completion provider.- Parameters:
provider- The provider to use in comments.- See Also:
getCommentCompletionProvider()
-
setDefaultCompletionProvider
public void setDefaultCompletionProvider(CompletionProvider provider)
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:
getDefaultCompletionProvider()
-
setDocCommentCompletionProvider
public void setDocCommentCompletionProvider(CompletionProvider provider)
Sets the documentation comment completion provider.- Parameters:
provider- The provider to use in comments.- See Also:
getDocCommentCompletionProvider()
-
setParameterizedCompletionParams
public void setParameterizedCompletionParams(char listStart, String separator, char listEnd)Calling this method will result in anUnsupportedOperationExceptionbeing thrown. To set the parameter completion parameters, do so on the provider returned bygetDefaultCompletionProvider().- Specified by:
setParameterizedCompletionParamsin interfaceCompletionProvider- Overrides:
setParameterizedCompletionParamsin 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:
clearParameterizedCompletionParams()
-
setStringCompletionProvider
public void setStringCompletionProvider(CompletionProvider provider)
Sets the completion provider to use while in a string.- Parameters:
provider- The provider to use.- See Also:
getStringCompletionProvider()
-
getToolTipText
public String getToolTipText(org.fife.ui.rtextarea.RTextArea textArea, MouseEvent e)
Returns the tool tip to display for a mouse event.For this method to be called, the RSyntaxTextArea must be registered with the javax.swing.ToolTipManager like so:
ToolTipManager.sharedInstance().registerComponent(textArea);
- Specified by:
getToolTipTextin interfaceorg.fife.ui.rtextarea.ToolTipSupplier- Parameters:
textArea- The text area.e- The mouse event.- Returns:
- The tool tip text, or
nullif none.
-
-