2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.template;
7 import org.eclipse.jface.text.BadLocationException;
8 import org.eclipse.jface.text.IDocument;
10 //import org.eclipse.jdt.internal.corext.Assert;
13 * A typical text based document template context.
15 public abstract class DocumentTemplateContext extends TemplateContext {
17 /** The text of the document. */
18 private final IDocument fDocument;
19 /** The completion position. */
20 private final int fCompletionPosition;
23 * Creates a document template context.
25 protected DocumentTemplateContext(ContextType type, IDocument document, int completionPosition) {
28 // Assert.isNotNull(document);
29 // Assert.isTrue(completionPosition >= 0 && completionPosition <= document.getLength());
32 fCompletionPosition= completionPosition;
35 public IDocument getDocument() {
40 * Returns the string of the context.
42 // public String getString() {
43 // return fDocument.get();
47 * Returns the completion position within the string of the context.
49 public int getCompletionPosition() {
50 return fCompletionPosition;
54 * Returns the keyword which triggered template insertion.
56 public String getKey() {
57 int offset= getStart();
58 int length= getEnd() - offset;
60 return fDocument.get(offset, length);
61 } catch (BadLocationException e) {
62 return ""; //$NON-NLS-1$
67 * Returns the beginning offset of the keyword.
69 public int getStart() {
70 return fCompletionPosition;
74 * Returns the end offset of the keyword.
77 return fCompletionPosition;