KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > text > edits > DeleteEdit


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.text.edits;
12
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15
16 /**
17  * Text edit to delete a range in a document.
18  * <p>
19  * A delete edit is equivalent to <code>ReplaceEdit(
20  * offset, length, "")</code>.
21  *
22  * @since 3.0
23  */

24 public final class DeleteEdit extends TextEdit {
25
26     /**
27      * Constructs a new delete edit.
28      *
29      * @param offset the offset of the range to replace
30      * @param length the length of the range to replace
31      */

32     public DeleteEdit(int offset, int length) {
33         super(offset, length);
34     }
35
36     /*
37      * Copy constructor
38      */

39     private DeleteEdit(DeleteEdit other) {
40         super(other);
41     }
42
43     /*
44      * @see TextEdit#doCopy
45      */

46     protected TextEdit doCopy() {
47         return new DeleteEdit(this);
48     }
49
50     /*
51      * @see TextEdit#accept0
52      */

53     protected void accept0(TextEditVisitor visitor) {
54         boolean visitChildren= visitor.visit(this);
55         if (visitChildren) {
56             acceptChildren(visitor);
57         }
58     }
59
60     /*
61      * @see TextEdit#performDocumentUpdating
62      */

63     int performDocumentUpdating(IDocument document) throws BadLocationException {
64         document.replace(getOffset(), getLength(), ""); //$NON-NLS-1$
65
fDelta= -getLength();
66         return fDelta;
67     }
68
69     /*
70      * @see TextEdit#deleteChildren
71      */

72     boolean deleteChildren() {
73         return true;
74     }
75 }
76
Popular Tags