Package org.eclipse.jface.text.templates
Class TemplateContext
java.lang.Object
org.eclipse.jface.text.templates.TemplateContext
- All Implemented Interfaces:
IAdaptable
- Direct Known Subclasses:
DocumentTemplateContext
Provides the context for a
Template being resolved. Keeps track
of resolved variables.
Clients may extend this class.
- Since:
- 3.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTemplateContext(TemplateContextType contextType) Creates a template context of a particular context type. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancanEvaluate(Template template) Tests if the specified template can be evaluated in this context.abstract TemplateBufferEvaluates the template in this context and returns a template buffer.<T> TgetAdapter(Class<T> adapter) Default implementation does nothing, clients can override to provide adapters.Returns the context type of this context.getVariable(String name) Returns the value of a defined variable.booleanReturnstrueif the receiver is read-only,falseotherwise.voidsetReadOnly(boolean readOnly) Sets or clears the read-only flag.voidsetVariable(String name, String value) Defines the value of a variable.
-
Constructor Details
-
TemplateContext
Creates a template context of a particular context type.- Parameters:
contextType- the context type of this context
-
-
Method Details
-
getContextType
Returns the context type of this context.- Returns:
- the context type of this context
-
setReadOnly
public void setReadOnly(boolean readOnly) Sets or clears the read-only flag.- Parameters:
readOnly- the new read-only state
-
isReadOnly
public boolean isReadOnly()Returnstrueif the receiver is read-only,falseotherwise.- Returns:
trueif the receiver is read-only,falseotherwise
-
setVariable
Defines the value of a variable.- Parameters:
name- the name of the variablevalue- the value of the variable,nullto un-define a variable
-
getVariable
Returns the value of a defined variable.- Parameters:
name- the name of the variable- Returns:
- returns the value of the variable,
nullif the variable was not defined
-
evaluate
public abstract TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException 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.- Parameters:
template- the template to evaluate- Returns:
- returns the buffer with the evaluated template or
nullif the buffer could not be created - Throws:
BadLocationException- if evaluation fails due to concurrently changed documents etc.TemplateException- if the template specification is not valid
-
canEvaluate
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).
- Parameters:
template- theTemplateto check- Returns:
trueiftemplatecan be evaluated in this context,falseotherwise
-
getAdapter
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. Returnsnullif 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:
getAdapterin interfaceIAdaptable- Type Parameters:
T- the class type- Parameters:
adapter- the adapter class to look up- Returns:
- a object of the given class, or
nullif this object does not have an adapter for the given class
-