public abstract class TemplateContext extends Object implements IAdaptable
Template
being resolved. Keeps track
of resolved variables.
Clients may extend this class.
Modifier | Constructor and Description |
---|---|
protected |
TemplateContext(TemplateContextType contextType)
Creates a template context of a particular context type.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
canEvaluate(Template template)
Tests if the specified template can be evaluated in this context.
|
abstract TemplateBuffer |
evaluate(Template template)
Evaluates the template in this context and returns a template buffer.
|
<T> T |
getAdapter(Class<T> adapter)
Default implementation does nothing, clients can override to provide adapters.
|
TemplateContextType |
getContextType()
Returns the context type of this context.
|
String |
getVariable(String name)
Returns the value of a defined variable.
|
boolean |
isReadOnly()
Returns
true if the receiver is read-only, false otherwise. |
void |
setReadOnly(boolean readOnly)
Sets or clears the read-only flag.
|
void |
setVariable(String name,
String value)
Defines the value of a variable.
|
protected TemplateContext(TemplateContextType contextType)
contextType
- the context type of this contextpublic TemplateContextType getContextType()
public void setReadOnly(boolean readOnly)
readOnly
- the new read-only statepublic boolean isReadOnly()
true
if the receiver is read-only, false
otherwise.true
if the receiver is read-only, false
otherwisepublic void setVariable(String name, String value)
name
- the name of the variablevalue
- the value of the variable, null
to un-define a variablepublic String getVariable(String name)
name
- the name of the variablenull
if the variable was not definedpublic abstract TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
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 evaluatenull
if the buffer could not be createdBadLocationException
- if evaluation fails due to concurrently changed documents etc.TemplateException
- if the template specification is not validpublic abstract boolean canEvaluate(Template template)
Examples are templates defined for a different context (e.g. a javadoc template cannot be evaluated in Java context).
template
- the Template
to checktrue
if template
can be evaluated
in this context, false
otherwisepublic <T> T getAdapter(Class<T> adapter)
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.
getAdapter
in interface IAdaptable
adapter
- the adapter class to look upnull
if this object does not
have an adapter for the given class
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.