/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package net.sourceforge.phpdt.internal.corext.textmanipulation;
import org.eclipse.core.runtime.CoreException;
/**
* A text edit describes an elementary text manipulation operation. Text edits
* are executed by adding them to a TextBufferEditor
and then
* calling perform
on the TextBufferEditor
.
*
* After a
* Note that this method should only be called by a
* This default implementation does nothing. Subclasses may override
* if needed.
*
* @param editor the text buffer editor this text edit has been added to
*/
public void connect(TextBufferEditor editor) throws CoreException {
// does nothing
}
/**
* Returns the
* This default implementation does nothing.
*/
public void performed() {
// do nothing
}
/**
* Creates and returns a copy of this object. The copy method should be
* implemented in a way so that the copy can be added to a different
*
* This default implementation returns TextEdit
has been added to a
* TextBufferEditor
the method connect
is sent to
* the text edit. A TextEdit
is allowed to do some adjustments of
* the text range it is going to manipulate while inside the hook
* connect
.
*
* @see TextBufferEditor
*/
public abstract class TextEdit {
// index that determines the insertion order into a text buffer
/* package */int index;
/* package */boolean isSynthetic;
/**
* Connects this text edit to the given TextBufferEditor
. A
* text edit must not keep a reference to the passed text buffer editor. It
* is guaranteed that the buffer passed to
* perform
is equal to the buffer managed by
* the given text buffer editor. But they don't have to be identical.
*
* TextBufferEditor
.
*TextRange
that this text edit is going to
* manipulate. If this method is called before the TextEdit
* has been added to a TextBufferEditor
it may return
* null
* or TextRange.UNDEFINED
to indicate this situation.
*
* @return the TextRange
s this TextEdit is going
* to manipulate
*/
public abstract TextRange getTextRange();
/**
* Performs the text edit. Note that this method should only be called
* by a
TextBufferEditor
.
*
* @param buffer
* the actual buffer to manipulate
* @return a text edit that can undo this text edit
*/
public abstract TextEdit perform(TextBuffer buffer) throws CoreException;
/**
* This method gets called after all TextEdit
s added to a
* text buffer editor are executed. Implementors of this method can do some
* clean-up or can release allocated resources that are now longer needed.
* TextBufferEditor
without causing any harm to the object
* from which the copy has been created.
*
* @return a copy of this object.
*/
public abstract TextEdit copy() throws CoreException;
/**
* Returns the element modified by this text edit. The method may return
* null
if the modification isn't related to a element or if
* the content of the modified text buffer doesn't follow any syntax.
* null
*
* @return the element modified by this text edit
*/
public Object getModifiedElement() {
return null;
}
}