|
Eclipse Platform Release 3.1 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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 un-parented. 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:
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
.
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 neither 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. |
protected void |
childDocumentUpdated()
Hook method called when the document updating of a child edit has been completed. |
protected void |
childRegionUpdated()
Hook method called when the region updating of a child edit has been completed. |
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. |
TextEdit |
getRoot()
Returns the root edit of the edit tree. |
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. |
void |
moveTree(int delta)
Move all offsets in the tree by the given delta. |
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
CREATE_UNDO
nor
UPDATE_REGIONS
is set.
public static final int CREATE_UNDO
null
is returned from method
apply
.
public static final int UPDATE_REGIONS
Constructor Detail |
protected TextEdit(int offset, int length)
null and the edit doesn't have any children.
- Parameters:
offset
- the edit's offsetlength
- the edit's length
protected TextEdit(TextEdit source)
source
- the source to copy formMethod Detail |
public final IRegion getRegion()
IRegion
contains the edit's offset and length at
the point in time when this call is made. Any subsequent changes
to the edit's offset and length aren't reflected in the returned
region object.
Creating a region for a deleted edit will result in an assertion failure.
public int getOffset()
-1
if the edit
is marked as deleted.
public int getLength()
-1
if the edit is marked as deleted.
public final int getInclusiveEnd()
getOffset() + getLength() - 1;
public final int getExclusiveEnd()
getOffset() + getLength();
public final boolean isDeleted()
true
if the edit has been
deleted; otherwise false
is returned.public final void moveTree(int delta)
delta
- the deltapublic boolean covers(TextEdit other)
true
if the edit covers the given edit
other
. It is up to the concrete text edit to
decide if a edit of length zero can cover another edit.
other
- the other edit
true if the edit covers the other edit;
otherwise false
is returned.
protected boolean canZeroLengthCover()
true
if an edit with length zero can cover
another edit. Returns false
otherwise.
public final TextEdit getParent()
null
if this edit hasn't been add to another edit.
public final TextEdit getRoot()
public final void addChild(TextEdit child) throws MalformedTreeException
child
to this edit.
child
- the child edit to add
MalformedTreeException
- is thrown if the child
edit can't be added to this edit. This is the case if the child
overlaps with one of its siblings or if the child edit's region
isn't fully covered by this edit.public final void addChildren(TextEdit[] edits) throws MalformedTreeException
edits
to this edit.
edits
- the text edits to add
MalformedTreeException
- is thrown if one of
the given edits can't be added to this edit.addChild(TextEdit)
public final TextEdit removeChild(int index)
null
.
index
- the index of the edit to remove
IndexOutOfBoundsException
- if the index
is out of rangepublic final boolean removeChild(TextEdit child)
child
- the child to be removed
true
if the edit contained the given
child; otherwise false
is returnedpublic final TextEdit[] removeChildren()
null
.
public final boolean hasChildren()
true
if this edit has children. Otherwise
false
is returned.
true
if this edit has children; otherwise
false
is returnedpublic final TextEdit[] getChildren()
public final int getChildrenSize()
public static IRegion getCoverage(TextEdit[] edits)
null
.
edits
- an array of edits
null
if all edits are marked as deletedpublic final boolean equals(Object obj)
Edit
implementation of this Object
method uses object identity (==).
obj
- the other object
true
iff this == obj
; otherwise
false
is returnedObject.equals(java.lang.Object)
public final int hashCode()
Edit
implementation of this Object
method calls uses Object#hashCode()
to compute its
hash code.
Object.hashCode()
public String toString()
public final TextEdit copy()
doCopy()
protected abstract TextEdit doCopy()
Implementers of this method should use the copy constructor
This method should not be called from outside the framework.
Please use
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.
copy
to create a copy of a edit tree.
copy()
,
postProcessCopy(TextEditCopier)
,
TextEditCopier
protected void postProcessCopy(TextEditCopier copier)
This default implementation does nothing
copier
- the copier that manages a map between original and
copied edit.TextEditCopier
public final void accept(TextEditVisitor visitor)
visitor
- the visitor object
IllegalArgumentException
- if the visitor is nullprotected 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)
.
visitor
- the visitor objectprotected 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.
visitor
- the visitor objectpublic final UndoEdit apply(IDocument document, int style) throws MalformedTreeException, BadLocationException
MalformedTreeException
or use TextEditProcessor
to
execute an edit tree.
document
- the document to be manipulatedstyle
- flags controlling the execution of the edit tree. Valid
flags are: CREATE_UNDO
and UPDATE_REGIONS.
CREATE_UNDO
is specified. Otherwise
null
is returned.
MalformedTreeException
- is thrown if the tree isn't
in a valid state. This exception is thrown before any edit
is executed. So the document is still in its original state.
BadLocationException
- is thrown if one of the edits
in the tree can't be executed. The state of the document is
undefined if this exception is thrown.TextEditProcessor.performEdits()
public final UndoEdit apply(IDocument document) throws MalformedTreeException, BadLocationException
apply(document, CREATE_UNDO | UPDATE_REGIONS)
document
- the document to which to apply this edit
CREATE_UNDO
is specified. Otherwise
null
is returned.
MalformedTreeException
- is thrown if the tree isn't
in a valid state. This exception is thrown before any edit
is executed. So the document is still in its original state.
BadLocationException
- is thrown if one of the edits
in the tree can't be executed. The state of the document is
undefined if this exception is thrown.apply(IDocument, int)
protected void childDocumentUpdated()
apply(IDocument)
or
apply(IDocument, int)
this method is called
getChildrenSize()
times.
May be overridden by subclasses of MultiTextEdit
.
protected void childRegionUpdated()
apply(IDocument)
this method is
called getChildrenSize()
times. When calling
apply(IDocument, int)
this method is called
getChildrenSize()
times, when the style parameter contains the
UPDATE_REGIONS
flag.
May be overridden by subclasses of MultiTextEdit
.
|
Eclipse Platform Release 3.1 |
|||||||||||
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, 2005. All rights reserved.