2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.textmanipulation;
7 import org.eclipse.core.runtime.CoreException;
9 //import org.eclipse.jdt.internal.corext.Assert;
11 public abstract class SimpleTextEdit extends TextEdit {
13 private TextRange fRange;
16 public static SimpleTextEdit createReplace(int offset, int length, String text) {
17 return new SimpleTextEditImpl(offset, length, text);
20 public static SimpleTextEdit createInsert(int offset, String text) {
21 return new SimpleTextEditImpl(offset, 0, text);
24 public static SimpleTextEdit createDelete(int offset, int length) {
25 return new SimpleTextEditImpl(offset, length, ""); //$NON-NLS-1$
28 private final static class SimpleTextEditImpl extends SimpleTextEdit {
29 protected SimpleTextEditImpl(TextRange range, String text) {
32 protected SimpleTextEditImpl(int offset, int length, String text) {
33 super(offset, length, text);
35 public TextEdit copy() {
36 return new SimpleTextEditImpl(getTextRange().copy(), getText());
40 protected SimpleTextEdit() {
41 this(TextRange.UNDEFINED, ""); //$NON-NLS-1$
44 protected SimpleTextEdit(int offset, int length, String text) {
45 this(new TextRange(offset, length), text);
47 protected SimpleTextEdit(TextRange range, String text) {
48 // Assert.isNotNull(range);
49 // Assert.isNotNull(text);
55 * Returns the text edit's text
57 * @return the text edit's text
59 public String getText() {
64 * Sets the text edit's text
66 * This method should only be called from within the <code>
67 * connect</code> method.
69 * @param text the text edit's text
71 protected final void setText(String text) {
73 // Assert.isNotNull(fText);
77 * Sets the text edit's range.
79 * This method should only be called from within the <code>
80 * connect</code> method.
82 * @param range the text edit's range.
84 protected void setTextRange(TextRange range) {
86 // Assert.isNotNull(fRange);
90 * @see TextEdit#getTextRange
92 public TextRange getTextRange() {
97 * @see TextEdit#doPerform
99 public final TextEdit perform(TextBuffer buffer) throws CoreException {
100 String current= buffer.getContent(fRange.fOffset, fRange.fLength);
101 buffer.replace(fRange, fText);
102 return new SimpleTextEditImpl(fRange, current);