Package org.eclipse.jface.text.templates
Class TemplateCompletionProcessor
java.lang.Object
org.eclipse.jface.text.templates.TemplateCompletionProcessor
- All Implemented Interfaces:
IContentAssistProcessor
A completion processor that computes template proposals. Subclasses need to
provide implementations for
getTemplates(String),
getContextType(ITextViewer, IRegion) and getImage(Template).- Since:
- 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomputeCompletionProposals(ITextViewer viewer, int offset) Returns a list of completion proposals based on the specified location within the document that corresponds to the current cursor position within the text viewer.computeContextInformation(ITextViewer viewer, int documentOffset) Returns information about possible contexts based on the specified location within the document that corresponds to the current cursor position within the text viewer.protected TemplateContextcreateContext(ITextViewer viewer, IRegion region) Creates a concrete template context for the given region in the document.protected ICompletionProposalcreateProposal(Template template, TemplateContext context, IRegion region, int relevance) Creates a new proposal.protected ICompletionProposalcreateProposal(Template template, TemplateContext context, Region region, int relevance) Deprecated.protected StringextractPrefix(ITextViewer viewer, int offset) Heuristically extracts the prefix used for determining template relevance from the viewer's document.char[]Returns the characters which when entered by the user should automatically trigger the presentation of possible completions.char[]Returns the characters which when entered by the user should automatically trigger the presentation of context information.Returns a validator used to determine when displayed context information should be dismissed.protected abstract TemplateContextTypegetContextType(ITextViewer viewer, IRegion region) Returns the context type that can handle template insertion at the given region in the viewer's document.Returns the reason why this content assist processor was unable to produce any completion proposals or context information.protected abstract ImageReturns the image to be used for the proposal fortemplate.protected intgetRelevance(Template template, String prefix) Returns the relevance of a template given a prefix.protected abstract Template[]getTemplates(String contextTypeId) Returns the templates valid for the context type specified bycontextTypeId.
-
Constructor Details
-
TemplateCompletionProcessor
public TemplateCompletionProcessor()
-
-
Method Details
-
computeCompletionProposals
Description copied from interface:IContentAssistProcessorReturns a list of completion proposals based on the specified location within the document that corresponds to the current cursor position within the text viewer.- Specified by:
computeCompletionProposalsin interfaceIContentAssistProcessor- Parameters:
viewer- the viewer whose document is used to compute the proposalsoffset- an offset within the document for which completions should be computed- Returns:
- an array of completion proposals or
nullif no proposals are possible
-
createProposal
@Deprecated protected ICompletionProposal createProposal(Template template, TemplateContext context, Region region, int relevance) Deprecated.use the version specifyingIRegionas third parameterCreates a new proposal.Forwards to
createProposal(Template, TemplateContext, IRegion, int). Do neither call nor override.- Parameters:
template- the template to be applied by the proposalcontext- the context for the proposalregion- the region the proposal applies torelevance- the relevance of the proposal- Returns:
- a new
ICompletionProposalfortemplate - Since:
- 3.1
-
createProposal
protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region, int relevance) Creates a new proposal.The default implementation returns an instance of
TemplateProposal. Subclasses may replace this method to provide their own implementations.- Parameters:
template- the template to be applied by the proposalcontext- the context for the proposalregion- the region the proposal applies torelevance- the relevance of the proposal- Returns:
- a new
ICompletionProposalfortemplate
-
getTemplates
Returns the templates valid for the context type specified bycontextTypeId.- Parameters:
contextTypeId- the context type id- Returns:
- the templates valid for this context type id
-
createContext
Creates a concrete template context for the given region in the document. This involves finding out which context type is valid at the given location, and then creating a context of this type. The default implementation returns aDocumentTemplateContextfor the context type at the given location.- Parameters:
viewer- the viewer for which the context is createdregion- the region intodocumentfor which the context is created- Returns:
- a template context that can handle template insertion at the given location, or
null
-
getContextType
Returns the context type that can handle template insertion at the given region in the viewer's document.- Parameters:
viewer- the text viewerregion- the region into the document displayed by viewer- Returns:
- the context type that can handle template expansion for the given location, or
nullif none exists
-
getRelevance
Returns the relevance of a template given a prefix. The default implementation returns a number greater than zero if the template name starts with the prefix, and zero otherwise.- Parameters:
template- the template to compute the relevance forprefix- the prefix after which content assist was requested- Returns:
- the relevance of
template - See Also:
-
extractPrefix
Heuristically extracts the prefix used for determining template relevance from the viewer's document. The default implementation returns the String from offset backwards that forms a java identifier.- Parameters:
viewer- the vieweroffset- offset into document- Returns:
- the prefix to consider
- See Also:
-
getImage
Returns the image to be used for the proposal fortemplate.- Parameters:
template- the template for which an image should be returned- Returns:
- the image for
template
-
computeContextInformation
Description copied from interface:IContentAssistProcessorReturns information about possible contexts based on the specified location within the document that corresponds to the current cursor position within the text viewer.- Specified by:
computeContextInformationin interfaceIContentAssistProcessor- Parameters:
viewer- the viewer whose document is used to compute the possible contextsdocumentOffset- an offset within the document for which context information should be computed- Returns:
- an array of context information objects or
nullif no context could be found
-
getCompletionProposalAutoActivationCharacters
public char[] getCompletionProposalAutoActivationCharacters()Description copied from interface:IContentAssistProcessorReturns the characters which when entered by the user should automatically trigger the presentation of possible completions.- Specified by:
getCompletionProposalAutoActivationCharactersin interfaceIContentAssistProcessor- Returns:
- the auto activation characters for completion proposal or
nullif no auto activation is desired
-
getContextInformationAutoActivationCharacters
public char[] getContextInformationAutoActivationCharacters()Description copied from interface:IContentAssistProcessorReturns the characters which when entered by the user should automatically trigger the presentation of context information.- Specified by:
getContextInformationAutoActivationCharactersin interfaceIContentAssistProcessor- Returns:
- the auto activation characters for presenting context information
or
nullif no auto activation is desired
-
getErrorMessage
Description copied from interface:IContentAssistProcessorReturns the reason why this content assist processor was unable to produce any completion proposals or context information.- Specified by:
getErrorMessagein interfaceIContentAssistProcessor- Returns:
- an error message or
nullif no error occurred
-
getContextInformationValidator
Description copied from interface:IContentAssistProcessorReturns a validator used to determine when displayed context information should be dismissed. May only returnnullif the processor is incapable of computing context information.- Specified by:
getContextInformationValidatorin interfaceIContentAssistProcessor- Returns:
- a context information validator, or
nullif the processor is incapable of computing context information
-
IRegionas third parameter