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 for getTemplates(String), getContextType(ITextViewer, IRegion) and getImage(Template).
Since:
3.0
  • Constructor Details

    • TemplateCompletionProcessor

      public TemplateCompletionProcessor()
  • Method Details

    • 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 interface IContentAssistProcessor
      Parameters:
      viewer - the viewer whose document is used to compute the proposals
      offset - 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 specifying IRegion as third parameter
      Creates a new proposal.

      Forwards to createProposal(Template, TemplateContext, IRegion, int). Do neither call nor override.

      Parameters:
      template - the template to be applied by the proposal
      context - the context for the proposal
      region - the region the proposal applies to
      relevance - the relevance of the proposal
      Returns:
      a new ICompletionProposal for template
      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 proposal
      context - the context for the proposal
      region - the region the proposal applies to
      relevance - the relevance of the proposal
      Returns:
      a new ICompletionProposal for template
    • getTemplates

      protected abstract Template[] getTemplates(String contextTypeId)
      Returns the templates valid for the context type specified by contextTypeId.
      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 a DocumentTemplateContext for the context type at the given location.
      Parameters:
      viewer - the viewer for which the context is created
      region - the region into document 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 viewer
      region - 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 for
      prefix - the prefix after which content assist was requested
      Returns:
      the relevance of template
      See Also:
    • 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 viewer
      offset - offset into document
      Returns:
      the prefix to consider
      See Also:
    • getImage

      protected abstract Image getImage(Template template)
      Returns the image to be used for the proposal for template.
      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 interface IContentAssistProcessor
      Parameters:
      viewer - the viewer whose document is used to compute the possible contexts
      documentOffset - 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 interface IContentAssistProcessor
      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 interface IContentAssistProcessor
      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 interface IContentAssistProcessor
      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 return null if the processor is incapable of computing context information.
      Specified by:
      getContextInformationValidator in interface IContentAssistProcessor
      Returns:
      a context information validator, or null if the processor is incapable of computing context information