*/
package net.sourceforge.phpdt.internal.corext.template;
+import net.sourceforge.phpdt.internal.corext.Assert;
+
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-//import org.eclipse.jdt.internal.corext.Assert;
/**
* A typical text based document template context.
*/
public abstract class DocumentTemplateContext extends TemplateContext {
- /** The text of the document. */
- private final IDocument fDocument;
- /** The completion position. */
- private final int fCompletionPosition;
+ /** The text of the document. */
+ private final IDocument fDocument;
+ /** The completion offset. */
+ private final int fCompletionOffset;
+ /** The completion length. */
+ private final int fCompletionLength;
- /**
- * Creates a document template context.
- */
- protected DocumentTemplateContext(ContextType type, IDocument document, int completionPosition) {
- super(type);
+ /**
+ * Creates a document template context.
+ */
+ protected DocumentTemplateContext(ContextType type, IDocument document,
+ int completionOffset, int completionLength)
+ {
+ super(type);
-// Assert.isNotNull(document);
-// Assert.isTrue(completionPosition >= 0 && completionPosition <= document.getLength());
+ Assert.isNotNull(document);
+ Assert.isTrue(completionOffset >= 0 && completionOffset <= document.getLength());
+ Assert.isTrue(completionLength >= 0);
- fDocument= document;
- fCompletionPosition= completionPosition;
- }
+ fDocument= document;
+ fCompletionOffset= completionOffset;
+ fCompletionLength= completionLength;
+ }
- public IDocument getDocument() {
- return fDocument;
- }
+ public IDocument getDocument() {
+ return fDocument;
+ }
- /**
- * Returns the string of the context.
- */
-// public String getString() {
-// return fDocument.get();
-// }
+ /**
+ * Returns the completion offset within the string of the context.
+ */
+ public int getCompletionOffset() {
+ return fCompletionOffset;
+ }
- /**
- * Returns the completion position within the string of the context.
- */
- public int getCompletionPosition() {
- return fCompletionPosition;
- }
+ /**
+ * Returns the completion length within the string of the context.
+ */
+ public int getCompletionLength() {
+ return fCompletionLength;
+ }
- /**
- * Returns the keyword which triggered template insertion.
- */
- public String getKey() {
- int offset= getStart();
- int length= getEnd() - offset;
- try {
- return fDocument.get(offset, length);
- } catch (BadLocationException e) {
- return ""; //$NON-NLS-1$
- }
- }
+ /**
+ * Returns the keyword which triggered template insertion.
+ */
+ public String getKey() {
+ int offset= getStart();
+ int length= getEnd() - offset;
+ try {
+ return fDocument.get(offset, length);
+ } catch (BadLocationException e) {
+ return ""; //$NON-NLS-1$
+ }
+ }
- /**
- * Returns the beginning offset of the keyword.
- */
- public int getStart() {
- return fCompletionPosition;
- }
+ /**
+ * Returns the beginning offset of the keyword.
+ */
+ public int getStart() {
+ return fCompletionOffset;
+ }
- /**
- * Returns the end offset of the keyword.
- */
- public int getEnd() {
- return fCompletionPosition;
- }
+ /**
+ * Returns the end offset of the keyword.
+ */
+ public int getEnd() {
+ return fCompletionOffset + fCompletionLength;
+ }
}
+