Mercurial > projects > dwt-addons
annotate dwtx/text/edits/ReplaceEdit.d @ 159:7926b636c282
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 01:57:58 +0200 |
parents | 6dcb0baaa031 |
children |
rev | line source |
---|---|
129 | 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.text.edits.ReplaceEdit; | |
14 | |
131 | 15 import dwtx.text.edits.TextEditVisitor; // packageimport |
16 import dwtx.text.edits.TextEdit; // packageimport | |
17 | |
18 | |
129 | 19 import dwt.dwthelper.utils; |
20 | |
21 | |
22 import dwtx.core.runtime.Assert; | |
23 import dwtx.jface.text.BadLocationException; | |
24 import dwtx.jface.text.IDocument; | |
25 | |
26 /** | |
27 * Text edit to replace a range in a document with a different | |
28 * string. | |
29 * | |
30 * @since 3.0 | |
31 */ | |
32 public final class ReplaceEdit : TextEdit { | |
33 | |
34 private String fText; | |
35 | |
36 /** | |
37 * Constructs a new replace edit. | |
38 * | |
39 * @param offset the offset of the range to replace | |
40 * @param length the length of the range to replace | |
41 * @param text the new text | |
42 */ | |
130 | 43 public this(int offset, int length, String text) { |
129 | 44 super(offset, length); |
45 Assert.isNotNull(text); | |
46 fText= text; | |
47 } | |
48 | |
49 /* | |
50 * Copy constructor | |
51 * | |
52 * @param other the edit to copy from | |
53 */ | |
130 | 54 private this(ReplaceEdit other) { |
129 | 55 super(other); |
56 fText= other.fText; | |
57 } | |
58 | |
59 /** | |
60 * Returns the new text replacing the text denoted | |
61 * by the edit. | |
62 * | |
63 * @return the edit's text. | |
64 */ | |
65 public String getText() { | |
66 return fText; | |
67 } | |
68 | |
69 /* | |
70 * @see TextEdit#doCopy | |
71 */ | |
72 protected TextEdit doCopy() { | |
73 return new ReplaceEdit(this); | |
74 } | |
75 | |
76 /* | |
77 * @see TextEdit#accept0 | |
78 */ | |
79 protected void accept0(TextEditVisitor visitor) { | |
80 bool visitChildren= visitor.visit(this); | |
81 if (visitChildren) { | |
82 acceptChildren(visitor); | |
83 } | |
84 } | |
85 | |
86 /* | |
87 * @see TextEdit#performDocumentUpdating | |
88 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
89 int performDocumentUpdating(IDocument document) { |
129 | 90 document.replace(getOffset(), getLength(), fText); |
91 fDelta= fText.length() - getLength(); | |
92 return fDelta; | |
93 } | |
94 | |
95 /* | |
96 * @see TextEdit#deleteChildren | |
97 */ | |
98 bool deleteChildren() { | |
99 return true; | |
100 } | |
101 | |
102 /* | |
103 * @see dwtx.text.edits.TextEdit#internalToString(java.lang.StringBuffer, int) | |
104 * @since 3.3 | |
105 */ | |
106 void internalToString(StringBuffer buffer, int indent) { | |
107 super.internalToString(buffer, indent); | |
108 buffer.append(" <<").append(fText); //$NON-NLS-1$ | |
109 } | |
110 } |