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
-
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 TemplateContext
createContext
(ITextViewer viewer, IRegion region) Creates a concrete template context for the given region in the document.protected ICompletionProposal
createProposal
(Template template, TemplateContext context, IRegion region, int relevance) Creates a new proposal.protected ICompletionProposal
createProposal
(Template template, TemplateContext context, Region region, int relevance) Deprecated.protected String
extractPrefix
(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 TemplateContextType
getContextType
(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 Image
Returns the image to be used for the proposal fortemplate
.protected int
getRelevance
(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:IContentAssistProcessor
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.- Specified by:
computeCompletionProposals
in 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
null
if no proposals are possible
-
createProposal
@Deprecated protected ICompletionProposal createProposal(Template template, TemplateContext context, Region region, int relevance) Deprecated.use the version specifyingIRegion
as 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
ICompletionProposal
fortemplate
- 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
ICompletionProposal
fortemplate
-
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 aDocumentTemplateContext
for the context type at the given location.- Parameters:
viewer
- the viewer for which the context is createdregion
- the region intodocument
for 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
null
if 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:IContentAssistProcessor
Returns 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:
computeContextInformation
in 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
null
if no context could be found
-
getCompletionProposalAutoActivationCharacters
public char[] getCompletionProposalAutoActivationCharacters()Description copied from interface:IContentAssistProcessor
Returns the characters which when entered by the user should automatically trigger the presentation of possible completions.- Specified by:
getCompletionProposalAutoActivationCharacters
in interfaceIContentAssistProcessor
- Returns:
- the auto activation characters for completion proposal or
null
if no auto activation is desired
-
getContextInformationAutoActivationCharacters
public char[] getContextInformationAutoActivationCharacters()Description copied from interface:IContentAssistProcessor
Returns the characters which when entered by the user should automatically trigger the presentation of context information.- Specified by:
getContextInformationAutoActivationCharacters
in interfaceIContentAssistProcessor
- Returns:
- the auto activation characters for presenting context information
or
null
if no auto activation is desired
-
getErrorMessage
Description copied from interface:IContentAssistProcessor
Returns the reason why this content assist processor was unable to produce any completion proposals or context information.- Specified by:
getErrorMessage
in interfaceIContentAssistProcessor
- Returns:
- an error message or
null
if no error occurred
-
getContextInformationValidator
Description copied from interface:IContentAssistProcessor
Returns a validator used to determine when displayed context information should be dismissed. May only returnnull
if the processor is incapable of computing context information.- Specified by:
getContextInformationValidator
in interfaceIContentAssistProcessor
- Returns:
- a context information validator, or
null
if the processor is incapable of computing context information
-
IRegion
as third parameter