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
15 * <code>TextBufferEditor</code> the method <code>connect</code> is sent to
16 * the text edit. A <code>TextEdit</code> is allowed to do some adjustments of
17 * the text range it is going to manipulate while inside the hook
18 * <code>connect</code>.
20 * @see TextBufferEditor
22 public abstract class TextEdit {
24 // index that determines the insertion order into a text buffer
25 /* package */int index;
27 /* package */boolean isSynthetic;
30 * Connects this text edit to the given <code>TextBufferEditor</code>. A
31 * text edit must not keep a reference to the passed text buffer editor. It
32 * is guaranteed that the buffer passed to
33 * <code>perform<code> is equal to the buffer managed by
34 * the given text buffer editor. But they don't have to be identical.
36 * Note that this method <b>should only be called</b> by a <code>
37 * TextBufferEditor</code>.
39 * This default implementation does nothing. Subclasses may override
42 * @param editor the text buffer editor this text edit has been added to
44 public void connect(TextBufferEditor editor) throws CoreException {
49 * Returns the <code>TextRange</code> that this text edit is going to
50 * manipulate. If this method is called before the <code>TextEdit</code>
51 * has been added to a <code>TextBufferEditor</code> it may return <code>
53 * or <code>TextRange.UNDEFINED</code> to indicate this situation.
55 * @return the <code>TextRange</code>s this <code>TextEdit is going
58 public abstract TextRange getTextRange();
61 * Performs the text edit. Note that this method <b>should only be called</b>
62 * by a <code>TextBufferEditor</code>.
65 * the actual buffer to manipulate
66 * @return a text edit that can undo this text edit
68 public abstract TextEdit perform(TextBuffer buffer) throws CoreException;
71 * This method gets called after all <code>TextEdit</code>s added to a
72 * text buffer editor are executed. Implementors of this method can do some
73 * clean-up or can release allocated resources that are now longer needed.
75 * This default implementation does nothing.
77 public void performed() {
82 * Creates and returns a copy of this object. The copy method should be
83 * implemented in a way so that the copy can be added to a different
84 * <code>TextBufferEditor</code> without causing any harm to the object
85 * from which the copy has been created.
87 * @return a copy of this object.
89 public abstract TextEdit copy() throws CoreException;
92 * Returns the element modified by this text edit. The method may return
93 * <code>null</code> if the modification isn't related to a element or if
94 * the content of the modified text buffer doesn't follow any syntax.
96 * This default implementation returns <code>null</code>
98 * @return the element modified by this text edit
100 public Object getModifiedElement() {