|
Eclipse Platform Release 3.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.text.edits.TextEdit
A text edit describes an elementary text manipulation operation. Edits are executed by applying them to a document (e.g. an instance of IDocument ).
Text edits form a tree. Clients can navigate the tree upwards, from child to parent, as well as downwards. Newly created edits are unparented. New edits are added to the tree by calling one of the add methods on a parent edit.
An edit tree is well formed in the following sense:
Any manipulation of the tree that violates one of the above requirements results in a MalformedTreeException.
Insert edits are represented by an edit of length 0. If more than one insert edit exists at the same offset then the edits are executed in the order in which they have been added to a parent. The following code example:
IDocument document= new Document("org"); MultiEdit edit= new MultiEdit(); edit.add(new InsertEdit(0, "www."); edit.add(new InsertEdit(0, "eclipse."); edit.apply(document);therefore results in string: "www.eclipse.org".
Text edits can be executed in a mode where the edit's region is updated to reflect the edit's position in the changed document. Region updating is enabled by default or can be requested by passing UPDATE_REGIONS to the apply(IDocument, int) method. In the above example the region of the InsertEdit(0, "eclipse.") edit after executing the root edit is [3, 8]. If the region of an edit got deleted during change execution the region is set to [-1, -1] and the method isDeleted returns true.
This class isn't intended to be subclassed outside of the edit framework. Clients are only allowed to subclass MultiTextEdit.
Field Summary | |
static int | CREATE_UNDO
Flags indicating that applying an edit tree to a document is supposed to create a corresponding undo edit. |
static int | NONE
Flags indicating that either CREATE_UNDO nor UPDATE_REGIONS is set. |
static int | UPDATE_REGIONS
Flag indicating that the edit's region will be updated to reflect its position in the changed document. |
Constructor Summary | |
protected | TextEdit(int offset,
int length)
Create a new text edit. |
protected | TextEdit(TextEdit source)
Copy constructor |
Method Summary | |
void | accept(TextEditVisitor visitor)
Accepts the given visitor on a visit of the current edit. |
protected abstract void | accept0(TextEditVisitor visitor)
Accepts the given visitor on a type-specific visit of the current edit. |
protected void | acceptChildren(TextEditVisitor visitor)
Accepts the given visitor on the edits children. |
void | addChild(TextEdit child)
Adds the given edit child to this edit. |
void | addChildren(TextEdit[] edits)
Adds all edits in edits to this edit. |
UndoEdit | apply(IDocument document)
Applies the edit tree rooted by this edit to the given document. |
UndoEdit | apply(IDocument document,
int style)
Applies the edit tree rooted by this edit to the given document. |
protected boolean | canZeroLengthCover()
Returns true if an edit with length zero can cover another edit. |
TextEdit | copy()
Creates a deep copy of the edit tree rooted at this edit. |
boolean | covers(TextEdit other)
Returns true if the edit covers the given edit other. |
protected abstract TextEdit | doCopy()
Creates and returns a copy of this edit. |
boolean | equals(Object obj)
The Edit implementation of this Object method uses object identity (==). |
TextEdit[] | getChildren()
Returns the edit's children. |
int | getChildrenSize()
Returns the size of the managed children. |
static IRegion | getCoverage(TextEdit[] edits)
Returns the text range spawned by the given array of text edits. |
int | getExclusiveEnd()
Returns the exclusive end position of this edit. |
int | getInclusiveEnd()
Returns the inclusive end position of this edit. |
int | getLength()
Returns the length of the edit. |
int | getOffset()
Returns the offset of the edit. |
TextEdit | getParent()
Returns the edit's parent. |
IRegion | getRegion()
Returns the range that this edit is manipulating. |
boolean | hasChildren()
Returns true if this edit has children. |
int | hashCode()
The Edit implementation of this Object method calls uses Object#hashCode() to compute its hash code. |
boolean | isDeleted()
Returns whether this edit has been deleted or not. |
protected void | postProcessCopy(TextEditCopier copier)
This method is called on every edit of the copied tree to do some post-processing like connected an edit to a different edit in the tree. |
TextEdit | removeChild(int index)
Removes the edit specified by the given index from the list of children. |
boolean | removeChild(TextEdit child)
Removes the first occurrence of the given child from the list of children. |
TextEdit[] | removeChildren()
Removes all child edits from and returns them. |
String | toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NONE
public static final int CREATE_UNDO
public static final int UPDATE_REGIONS
Constructor Detail |
protected TextEdit(int offset, int length)
protected TextEdit(TextEdit source)
Method Detail |
public final IRegion getRegion()
Creating a region for a deleted edit will result in an assertion failure.
public final int getOffset()
public final int getLength()
public final int getInclusiveEnd()
getOffset() + getLength() - 1;
public final int getExclusiveEnd()
getOffset() + getLength();
public final boolean isDeleted()
public final boolean covers(TextEdit other)
protected boolean canZeroLengthCover()
public final TextEdit getParent()
public final void addChild(TextEdit child) throws MalformedTreeException
public final void addChildren(TextEdit[] edits) throws MalformedTreeException
public final TextEdit removeChild(int index)
public final boolean removeChild(TextEdit child)
public final TextEdit[] removeChildren()
public final boolean hasChildren()
public final TextEdit[] getChildren()
public final int getChildrenSize()
public static IRegion getCoverage(TextEdit[] edits)
public final boolean equals(Object obj)
public final int hashCode()
public String toString()
public final TextEdit copy()
protected abstract TextEdit doCopy()
Implementers of this method should use the copy constructor Edit#Edit(Edit source) to initialize the edit part of the copy. Implementors aren't responsible to actually copy the children or to set the right parent.
This method should not be called from outside the framework. Please use copy to create a copy of a edit tree.
protected void postProcessCopy(TextEditCopier copier)
This default implementation does nothing
public final void accept(TextEditVisitor visitor)
protected abstract void accept0(TextEditVisitor visitor)
General template for implementation on each concrete TextEdit class:
boolean visitChildren = visitor.visit(this); if (visitChildren) { acceptChildren(visitor); }Note that the caller (accept) takes care of invoking visitor.preVisit(this) and visitor.postVisit(this).
protected final void acceptChildren(TextEditVisitor visitor)
This method must be used by the concrete implementations of accept to traverse list-values properties; it encapsulates the proper handling of on-the-fly changes to the list.
public final UndoEdit apply(IDocument document, int style) throws MalformedTreeException, BadLocationException
public final UndoEdit apply(IDocument document) throws MalformedTreeException, BadLocationException
|
Eclipse Platform Release 3.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.