Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Eclipse Platform Release 3.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.jface.text.templates
Class DocumentTemplateContext

    java.lang.Object
      org.eclipse.jface.text.templates.TemplateContext
          org.eclipse.jface.text.templates.DocumentTemplateContext

public class DocumentTemplateContext
extends TemplateContext

A typical text based document template context.

Clients may instantiate and extend this class.

Since:
  3.0

Constructor Summary
`DocumentTemplateContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength)` Creates a document template context.

Method Summary
`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.

Methods inherited from class org.eclipse.jface.text.templates.TemplateContext
`getContextType, getVariable, isReadOnly, setReadOnly, setVariable`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DocumentTemplateContext

    public DocumentTemplateContext(TemplateContextType type,
                                   IDocument document,
                                   int completionOffset,
                                   int completionLength)

  Creates a document template context.

Parameters:
  `type` - the context type
  `document` - the document this context applies to
  `completionOffset` - the completion offset (for usage in content assist)
  `completionLength` - the completion length

Method Detail

### getDocument

    public IDocument getDocument()

  Returns the document.

  Returns:
    the document

### getCompletionOffset

    public int getCompletionOffset()

  Returns the completion offset within the string of the context.

  Returns:
    the completion offset within the string of the context

### setCompletionOffset

    protected void setCompletionOffset(int newOffset)

  Sets the completion offset.

  Parameters:
    `newOffset` - the new completion offset

### getCompletionLength

    public int getCompletionLength()

  Returns the completion length within the string of the context.

  Returns:
    the completion length within the string of the context

### setCompletionLength

    protected void setCompletionLength(int newLength)

  Sets the completion length.

  Parameters:
    `newLength` - the new completion length

### getKey

    public String getKey()

  Returns the keyword which triggered template insertion.

  Returns:
    the keyword which triggered template insertion

### getStart

    public int getStart()

  Returns the beginning offset of the keyword.

  Returns:
    the beginning offset of the keyword

### getEnd

    public int getEnd()

  Returns the end offset of the keyword.

  Returns:
    the end offset of the keyword

### canEvaluate

    public boolean canEvaluate(Template template)

  Description copied from class: `TemplateContext`
  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).

  Specified by:
    `canEvaluate` in class `TemplateContext`
  Parameters:
    `template` - the `Template` to check
  Returns:
    `true` if `template` can be evaluated in this context, `false` otherwise

### evaluate

    public TemplateBuffer evaluate(Template template)
                            throws BadLocationException,
                                   TemplateException

  Description copied from class: `TemplateContext`
  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.

  Specified by:
    `evaluate` in class `TemplateContext`
  Parameters:
    `template` - the template to evaluate
  Returns:
    returns the buffer with the evaluated template or `null` if the buffer could not be created
  Throws:
    `TemplateException` - if the template specification is not valid
    `BadLocationException` - if evaluation fails due to concurrently changed documents etc.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Eclipse Platform Release 3.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.