Class TemplateContext

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public abstract class TemplateContext
    extends Object
    implements IAdaptable
    Provides the context for a Template being resolved. Keeps track of resolved variables.

    Clients may extend this class.

    • Constructor Detail

      • TemplateContext

        protected TemplateContext​(TemplateContextType contextType)
        Creates a template context of a particular context type.
        contextType - the context type of this context
    • Method Detail

      • getContextType

        public TemplateContextType getContextType()
        Returns the context type of this context.
        the context type of this context
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
        Sets or clears the read-only flag.
        readOnly - the new read-only state
      • isReadOnly

        public boolean isReadOnly()
        Returns true if the receiver is read-only, false otherwise.
        true if the receiver is read-only, false otherwise
      • setVariable

        public void setVariable​(String name,
                                String value)
        Defines the value of a variable.
        name - the name of the variable
        value - the value of the variable, null to un-define a variable
      • getVariable

        public String getVariable​(String name)
        Returns the value of a defined variable.
        name - the name of the variable
        returns the value of the variable, null if the variable was not defined
      • evaluate

        public abstract TemplateBuffer evaluate​(Template template)
                                         throws BadLocationException,
        Evaluates the template in this context and returns a template buffer.

        Evaluation means translating the template into a TemplateBuffer, resolving the defined variables in this context and possibly formatting the resolved buffer.

        template - the template to evaluate
        returns the buffer with the evaluated template or null if the buffer could not be created
        BadLocationException - if evaluation fails due to concurrently changed documents etc.
        TemplateException - if the template specification is not valid
      • canEvaluate

        public abstract boolean canEvaluate​(Template template)
        Tests if the specified template can be evaluated in this context.

        Examples are templates defined for a different context (e.g. a javadoc template cannot be evaluated in Java context).

        template - the Template to check
        true if template can be evaluated in this context, false otherwise
      • getAdapter

        public <T> T getAdapter​(Class<T> adapter)
        Default implementation does nothing, clients can override to provide adapters. Returns an object which is an instance of the given class associated with this object. Returns null if no such object can be found.

        Clients may implement this method but should generally call Adapters.adapt(Object, Class, boolean) rather than invoking it directly.

        Specified by:
        getAdapter in interface IAdaptable
        Type Parameters:
        T - the class type
        adapter - the adapter class to look up
        a object of the given class, or null if this object does not have an adapter for the given class