Package org.eclipse.jface.text.templates
Class TemplateCompletionProcessor
- java.lang.Object
-
- org.eclipse.jface.text.templates.TemplateCompletionProcessor
-
- All Implemented Interfaces:
IContentAssistProcessor
public abstract class TemplateCompletionProcessor extends Object implements IContentAssistProcessor
A completion processor that computes template proposals. Subclasses need to provide implementations forgetTemplates(String)
,getContextType(ITextViewer, IRegion)
andgetImage(Template)
.- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description TemplateCompletionProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ICompletionProposal[]
computeCompletionProposals(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.IContextInformation[]
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.use the version specifyingIRegion
as third parameterprotected String
extractPrefix(ITextViewer viewer, int offset)
Heuristically extracts the prefix used for determining template relevance from the viewer's document.char[]
getCompletionProposalAutoActivationCharacters()
Returns the characters which when entered by the user should automatically trigger the presentation of possible completions.char[]
getContextInformationAutoActivationCharacters()
Returns the characters which when entered by the user should automatically trigger the presentation of context information.IContextInformationValidator
getContextInformationValidator()
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.String
getErrorMessage()
Returns the reason why this content assist processor was unable to produce any completion proposals or context information.protected abstract Image
getImage(Template template)
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
.
-
-
-
Method Detail
-
computeCompletionProposals
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
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
protected abstract Template[] getTemplates(String contextTypeId)
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
protected TemplateContext createContext(ITextViewer viewer, IRegion region)
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
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.- 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
protected int getRelevance(Template template, String prefix)
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(ITextViewer, int)
-
extractPrefix
protected String extractPrefix(ITextViewer viewer, int offset)
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:
getRelevance(Template, String)
-
getImage
protected abstract Image getImage(Template template)
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
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset)
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
public String 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
public IContextInformationValidator 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
-
-