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: * A <code>CopyingRangeMarker</code> can be used to track positions when executing
17: * text edits. Additionally a copying range marker stores a local copy of the
18: * text it captures when it gets executed.
19: *
20: * @since 3.0
21: */
22: public final class CopyingRangeMarker extends TextEdit {
23:
24: private String fText;
25:
26: /**
27: * Creates a new <tt>CopyRangeMarker</tt> for the given
28: * offset and length.
29: *
30: * @param offset the marker's offset
31: * @param length the marker's length
32: */
33: public CopyingRangeMarker(int offset, int length) {
34: super (offset, length);
35: }
36:
37: /*
38: * Copy constructor
39: */
40: private CopyingRangeMarker(CopyingRangeMarker other) {
41: super (other);
42: fText = other.fText;
43: }
44:
45: /*
46: * @see TextEdit#doCopy
47: */
48: protected TextEdit doCopy() {
49: return new CopyingRangeMarker(this );
50: }
51:
52: /*
53: * @see TextEdit#accept0
54: */
55: protected void accept0(TextEditVisitor visitor) {
56: boolean visitChildren = visitor.visit(this );
57: if (visitChildren) {
58: acceptChildren(visitor);
59: }
60: }
61:
62: /*
63: * @see TextEdit#performDocumentUpdating
64: */
65: int performDocumentUpdating(IDocument document)
66: throws BadLocationException {
67: fText = document.get(getOffset(), getLength());
68: fDelta = 0;
69: return fDelta;
70: }
71:
72: /*
73: * @see TextEdit#deleteChildren
74: */
75: boolean deleteChildren() {
76: return false;
77: }
78: }
|