2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.textmanipulation;
7 import org.eclipse.core.runtime.CoreException;
10 * A text edit describes an elementary text manipulation operation. Text edits
11 * are executed by adding them to a <code>TextBufferEditor</code> and then
12 * calling <code>perform</code> on the <code>TextBufferEditor</code>.
14 * After a <code>TextEdit</code> has been added to a <code>TextBufferEditor</code>
15 * the method <code>connect</code> is sent to the text edit. A <code>TextEdit</code>
16 * is allowed to do some adjustments of the text range it is going to manipulate while inside
17 * the hook <code>connect</code>.
19 * @see TextBufferEditor
21 public abstract class TextEdit {
23 // index that determines the insertion order into a text buffer
24 /* package */ int index;
25 /* package */ boolean isSynthetic;
28 * Connects this text edit to the given <code>TextBufferEditor</code>. A text edit
29 * must not keep a reference to the passed text buffer editor. It is guaranteed that
30 * the buffer passed to <code>perform<code> is equal to the buffer managed by
31 * the given text buffer editor. But they don't have to be identical.
33 * Note that this method <b>should only be called</b> by a <code>
34 * TextBufferEditor</code>.
36 * This default implementation does nothing. Subclasses may override
39 * @param editor the text buffer editor this text edit has been added to
41 public void connect(TextBufferEditor editor) throws CoreException {
46 * Returns the <code>TextRange</code> that this text edit is going to
47 * manipulate. If this method is called before the <code>TextEdit</code>
48 * has been added to a <code>TextBufferEditor</code> it may return <code>
49 * null</code> or <code>TextRange.UNDEFINED</code> to indicate this situation.
51 * @return the <code>TextRange</code>s this <code>TextEdit is going
54 public abstract TextRange getTextRange();
57 * Performs the text edit. Note that this method <b>should only be called</b>
58 * by a <code>TextBufferEditor</code>.
60 * @param buffer the actual buffer to manipulate
61 * @return a text edit that can undo this text edit
63 public abstract TextEdit perform(TextBuffer buffer) throws CoreException;
66 * This method gets called after all <code>TextEdit</code>s added to a text buffer
67 * editor are executed. Implementors of this method can do some clean-up or can
68 * release allocated resources that are now longer needed.
70 * This default implementation does nothing.
72 public void performed() {
77 * Creates and returns a copy of this object. The copy method should
78 * be implemented in a way so that the copy can be added to a different
79 * <code>TextBufferEditor</code> without causing any harm to the object
80 * from which the copy has been created.
82 * @return a copy of this object.
84 public abstract TextEdit copy() throws CoreException;
87 * Returns the element modified by this text edit. The method
88 * may return <code>null</code> if the modification isn't related to a
89 * element or if the content of the modified text buffer doesn't
92 * This default implementation returns <code>null</code>
94 * @return the element modified by this text edit
96 public Object getModifiedElement() {