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 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.use the version specifyingIRegionas third parameterprotected StringextractPrefix(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.IContextInformationValidatorgetContextInformationValidator()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.StringgetErrorMessage()Returns the reason why this content assist processor was unable to produce any completion proposals or context information.protected abstract ImagegetImage(Template template)Returns 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.
-
-
-
Method Detail
-
computeCompletionProposals
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
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
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 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
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
nullif 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: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
public String 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
public IContextInformationValidator 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
-
-