01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.text.edits;
11:
12: import org.eclipse.jface.text.BadLocationException;
13: import org.eclipse.jface.text.IDocument;
14:
15: /**
16: * Text edit to delete a range in a document.
17: * <p>
18: * A delete edit is equivalent to <code>ReplaceEdit(
19: * offset, length, "")</code>.
20: *
21: * @since 3.0
22: */
23: public final class DeleteEdit extends TextEdit {
24:
25: /**
26: * Constructs a new delete edit.
27: *
28: * @param offset the offset of the range to replace
29: * @param length the length of the range to replace
30: */
31: public DeleteEdit(int offset, int length) {
32: super (offset, length);
33: }
34:
35: /*
36: * Copy constructor
37: */
38: private DeleteEdit(DeleteEdit other) {
39: super (other);
40: }
41:
42: /*
43: * @see TextEdit#doCopy
44: */
45: protected TextEdit doCopy() {
46: return new DeleteEdit(this );
47: }
48:
49: /*
50: * @see TextEdit#accept0
51: */
52: protected void accept0(TextEditVisitor visitor) {
53: boolean visitChildren = visitor.visit(this );
54: if (visitChildren) {
55: acceptChildren(visitor);
56: }
57: }
58:
59: /*
60: * @see TextEdit#performDocumentUpdating
61: */
62: int performDocumentUpdating(IDocument document)
63: 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: }
|