2  * (c) Copyright IBM Corp. 2000, 2001.
 
   5 package net.sourceforge.phpdt.internal.corext.textmanipulation;
 
   7 import org.eclipse.core.runtime.CoreException;
 
   9 // import net.sourceforge.phpdt.internal.corext.Assert;
 
  11 public abstract class SimpleTextEdit extends TextEdit {
 
  13         private TextRange fRange;
 
  17         public static SimpleTextEdit createReplace(int offset, int length,
 
  19                 return new SimpleTextEditImpl(offset, length, text);
 
  22         public static SimpleTextEdit createInsert(int offset, String text) {
 
  23                 return new SimpleTextEditImpl(offset, 0, text);
 
  26         public static SimpleTextEdit createDelete(int offset, int length) {
 
  27                 return new SimpleTextEditImpl(offset, length, ""); //$NON-NLS-1$
 
  30         private final static class SimpleTextEditImpl extends SimpleTextEdit {
 
  31                 protected SimpleTextEditImpl(TextRange range, String text) {
 
  35                 protected SimpleTextEditImpl(int offset, int length, String text) {
 
  36                         super(offset, length, text);
 
  39                 public TextEdit copy() {
 
  40                         return new SimpleTextEditImpl(getTextRange().copy(), getText());
 
  44         protected SimpleTextEdit() {
 
  45                 this(TextRange.UNDEFINED, ""); //$NON-NLS-1$
 
  48         protected SimpleTextEdit(int offset, int length, String text) {
 
  49                 this(new TextRange(offset, length), text);
 
  52         protected SimpleTextEdit(TextRange range, String text) {
 
  53                 // Assert.isNotNull(range);
 
  54                 // Assert.isNotNull(text);
 
  60          * Returns the text edit's text
 
  62          * @return the text edit's text
 
  64         public String getText() {
 
  69          * Sets the text edit's text
 
  71          * This method should only be called from within the <code>
 
  76          *            the text edit's text
 
  78         protected final void setText(String text) {
 
  80                 // Assert.isNotNull(fText);
 
  84          * Sets the text edit's range.
 
  86          * This method should only be called from within the <code>
 
  91          *            the text edit's range.
 
  93         protected void setTextRange(TextRange range) {
 
  95                 // Assert.isNotNull(fRange);
 
 101          * @see TextEdit#getTextRange
 
 103         public TextRange getTextRange() {
 
 110          * @see TextEdit#doPerform
 
 112         public final TextEdit perform(TextBuffer buffer) throws CoreException {
 
 113                 String current = buffer.getContent(fRange.fOffset, fRange.fLength);
 
 114                 buffer.replace(fRange, fText);
 
 115                 return new SimpleTextEditImpl(fRange, current);