Package org.eclipse.jface.text.templates
Class DocumentTemplateContext
java.lang.Object
org.eclipse.jface.text.templates.TemplateContext
org.eclipse.jface.text.templates.DocumentTemplateContext
- All Implemented Interfaces:
- IAdaptable
Instances of this class describe the context of a template as a region of
 a document. That region may be either specified by its offset and length, or
 by a 
Position which may or may not be registered with the
 document.
 Clients may instantiate and extend this class.
- Since:
- 3.0
- 
Constructor SummaryConstructorsConstructorDescriptionDocumentTemplateContext(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.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanEvaluate(Template template) Tests if the specified template can be evaluated in this context.Evaluates the template in this context and returns a template buffer.intReturns the completion length within the string of the context.intReturns the completion offset within the string of the context.Returns the document.intgetEnd()Returns the end offset of the keyword.getKey()Returns the keyword which triggered template insertion.intgetStart()Returns the beginning offset of the keyword.protected voidsetCompletionLength(int newLength) Sets the completion length.protected voidsetCompletionOffset(int newOffset) Sets the completion offset.Methods inherited from class org.eclipse.jface.text.templates.TemplateContextgetAdapter, getContextType, getVariable, isReadOnly, setReadOnly, setVariable
- 
Constructor Details- 
DocumentTemplateContextpublic DocumentTemplateContext(TemplateContextType type, IDocument document, int offset, int length) Creates a document template context.- Parameters:
- type- the context type
- document- the document this context applies to
- offset- the offset of the document region
- length- the length of the document region
 
- 
DocumentTemplateContextCreates a document template context. The suppliedPositionwill be queried to compute thegetStartandgetEndmethods, which will therefore answer updated position data if it is registered with the document.- Parameters:
- type- the context type
- document- the document this context applies to
- position- the position describing the area of the document which forms the template context
- Since:
- 3.1
 
 
- 
- 
Method Details- 
getDocumentReturns the document.- Returns:
- the document
 
- 
getCompletionOffsetpublic int getCompletionOffset()Returns the completion offset within the string of the context.- Returns:
- the completion offset within the string of the context
 
- 
setCompletionOffsetprotected void setCompletionOffset(int newOffset) Sets the completion offset.- Parameters:
- newOffset- the new completion offset
 
- 
getCompletionLengthpublic int getCompletionLength()Returns the completion length within the string of the context.- Returns:
- the completion length within the string of the context
 
- 
setCompletionLengthprotected void setCompletionLength(int newLength) Sets the completion length.- Parameters:
- newLength- the new completion length
 
- 
getKeyReturns the keyword which triggered template insertion.- Returns:
- the keyword which triggered template insertion
 
- 
getStartpublic int getStart()Returns the beginning offset of the keyword.- Returns:
- the beginning offset of the keyword
 
- 
getEndpublic int getEnd()Returns the end offset of the keyword.- Returns:
- the end offset of the keyword
 
- 
canEvaluateDescription copied from class:TemplateContextTests 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). - Specified by:
- canEvaluatein class- TemplateContext
- Parameters:
- template- the- Templateto check
- Returns:
- trueif- templatecan be evaluated in this context,- falseotherwise
 
- 
evaluateDescription copied from class:TemplateContextEvaluates 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.- Specified by:
- evaluatein class- TemplateContext
- 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
 
 
-