public class DocumentTemplateContext extends TemplateContext
Position
which may or may not be registered with the
document.
Clients may instantiate and extend this class.
Constructor and Description |
---|
DocumentTemplateContext(TemplateContextType type,
IDocument document,
int offset,
int length)
Creates a document template context.
|
DocumentTemplateContext(TemplateContextType type,
IDocument document,
Position position)
Creates a document template context.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canEvaluate(Template template)
Tests if the specified template can be evaluated in this context.
|
TemplateBuffer |
evaluate(Template template)
Evaluates the template in this context and returns a template buffer.
|
int |
getCompletionLength()
Returns the completion length within the string of the context.
|
int |
getCompletionOffset()
Returns the completion offset within the string of the context.
|
IDocument |
getDocument()
Returns the document.
|
int |
getEnd()
Returns the end offset of the keyword.
|
String |
getKey()
Returns the keyword which triggered template insertion.
|
int |
getStart()
Returns the beginning offset of the keyword.
|
protected void |
setCompletionLength(int newLength)
Sets the completion length.
|
protected void |
setCompletionOffset(int newOffset)
Sets the completion offset.
|
getContextType, getVariable, isReadOnly, setReadOnly, setVariable
public DocumentTemplateContext(TemplateContextType type, IDocument document, int offset, int length)
type
- the context typedocument
- the document this context applies tooffset
- the offset of the document regionlength
- the length of the document regionpublic DocumentTemplateContext(TemplateContextType type, IDocument document, Position position)
Position
will be queried to compute the getStart
and
getEnd
methods, which will therefore answer updated
position data if it is registered with the document.type
- the context typedocument
- the document this context applies toposition
- the position describing the area of the document which
forms the template contextpublic IDocument getDocument()
public int getCompletionOffset()
protected void setCompletionOffset(int newOffset)
newOffset
- the new completion offsetpublic int getCompletionLength()
protected void setCompletionLength(int newLength)
newLength
- the new completion lengthpublic String getKey()
public int getStart()
public int getEnd()
public boolean canEvaluate(Template template)
TemplateContext
Examples are templates defined for a different context (e.g. a javadoc template cannot be evaluated in Java context).
canEvaluate
in class TemplateContext
template
- the Template
to checktrue
if template
can be evaluated
in this context, false
otherwisepublic TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
TemplateContext
Evaluation means translating the template into a TemplateBuffer
,
resolving the defined variables in this context and possibly formatting
the resolved buffer.
evaluate
in class TemplateContext
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 valid
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.