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.BadLocationException;
9 import org.eclipse.jface.text.IDocument;
11 //import org.eclipse.jdt.internal.corext.Assert;
14 * A typical text based document template context.
16 public abstract class DocumentTemplateContext extends TemplateContext {
18 /** The text of the document. */
19 private final IDocument fDocument;
20 /** The completion position. */
21 private final int fCompletionPosition;
24 * Creates a document template context.
26 protected DocumentTemplateContext(ContextType type, IDocument document, int completionPosition) {
29 // Assert.isNotNull(document);
30 // Assert.isTrue(completionPosition >= 0 && completionPosition <= document.getLength());
33 fCompletionPosition= completionPosition;
36 public IDocument getDocument() {
41 * Returns the string of the context.
43 // public String getString() {
44 // return fDocument.get();
48 * Returns the completion position within the string of the context.
50 public int getCompletionPosition() {
51 return fCompletionPosition;
55 * Returns the keyword which triggered template insertion.
57 public String getKey() {
58 int offset= getStart();
59 int length= getEnd() - offset;
61 return fDocument.get(offset, length);
62 } catch (BadLocationException e) {
63 return ""; //$NON-NLS-1$
68 * Returns the beginning offset of the keyword.
70 public int getStart() {
71 return fCompletionPosition;
75 * Returns the end offset of the keyword.
78 return fCompletionPosition;