Mercurial > projects > dwt2
comparison org.eclipse.text/src/org/eclipse/text/edits/ReplaceEdit.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | 5feec68b4556 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 org.eclipse.text.edits.ReplaceEdit; | |
14 | |
15 import org.eclipse.text.edits.TextEditVisitor; // packageimport | |
16 import org.eclipse.text.edits.TextEdit; // packageimport | |
17 | |
18 | |
19 import java.lang.all; | |
20 import java.util.Set; | |
21 | |
22 | |
23 import org.eclipse.core.runtime.Assert; | |
24 import org.eclipse.jface.text.BadLocationException; | |
25 import org.eclipse.jface.text.IDocument; | |
26 | |
27 /** | |
28 * Text edit to replace a range in a document with a different | |
29 * string. | |
30 * | |
31 * @since 3.0 | |
32 */ | |
33 public final class ReplaceEdit : TextEdit { | |
34 | |
35 private String fText; | |
36 | |
37 /** | |
38 * Constructs a new replace edit. | |
39 * | |
40 * @param offset the offset of the range to replace | |
41 * @param length the length of the range to replace | |
42 * @param text the new text | |
43 */ | |
44 public this(int offset, int length, String text) { | |
45 super(offset, length); | |
46 Assert.isNotNull(text); | |
47 fText= text; | |
48 } | |
49 | |
50 /* | |
51 * Copy constructor | |
52 * | |
53 * @param other the edit to copy from | |
54 */ | |
55 private this(ReplaceEdit other) { | |
56 super(other); | |
57 fText= other.fText; | |
58 } | |
59 | |
60 /** | |
61 * Returns the new text replacing the text denoted | |
62 * by the edit. | |
63 * | |
64 * @return the edit's text. | |
65 */ | |
66 public String getText() { | |
67 return fText; | |
68 } | |
69 | |
70 /* | |
71 * @see TextEdit#doCopy | |
72 */ | |
73 protected TextEdit doCopy() { | |
74 return new ReplaceEdit(this); | |
75 } | |
76 | |
77 /* | |
78 * @see TextEdit#accept0 | |
79 */ | |
80 protected void accept0(TextEditVisitor visitor) { | |
81 bool visitChildren= visitor.visit(this); | |
82 if (visitChildren) { | |
83 acceptChildren(visitor); | |
84 } | |
85 } | |
86 | |
87 /* | |
88 * @see TextEdit#performDocumentUpdating | |
89 */ | |
90 int performDocumentUpdating(IDocument document) { | |
91 document.replace(getOffset(), getLength(), fText); | |
92 fDelta= fText.length() - getLength(); | |
93 return fDelta; | |
94 } | |
95 | |
96 /* | |
97 * @see TextEdit#deleteChildren | |
98 */ | |
99 bool deleteChildren() { | |
100 return true; | |
101 } | |
102 | |
103 /* | |
104 * @see org.eclipse.text.edits.TextEdit#internalToString(java.lang.StringBuffer, int) | |
105 * @since 3.3 | |
106 */ | |
107 void internalToString(StringBuffer buffer, int indent) { | |
108 super.internalToString(buffer, indent); | |
109 buffer.append(" <<").append(fText); //$NON-NLS-1$ | |
110 } | |
111 } |