comparison org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.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.TextEditGroup;
14
15 import org.eclipse.text.edits.MultiTextEdit; // packageimport
16 import org.eclipse.text.edits.CopySourceEdit; // packageimport
17 import org.eclipse.text.edits.MoveSourceEdit; // packageimport
18 import org.eclipse.text.edits.CopyingRangeMarker; // packageimport
19 import org.eclipse.text.edits.ReplaceEdit; // packageimport
20 import org.eclipse.text.edits.EditDocument; // packageimport
21 import org.eclipse.text.edits.UndoCollector; // packageimport
22 import org.eclipse.text.edits.DeleteEdit; // packageimport
23 import org.eclipse.text.edits.MoveTargetEdit; // packageimport
24 import org.eclipse.text.edits.CopyTargetEdit; // packageimport
25 import org.eclipse.text.edits.TextEditCopier; // packageimport
26 import org.eclipse.text.edits.ISourceModifier; // packageimport
27 import org.eclipse.text.edits.TextEditMessages; // packageimport
28 import org.eclipse.text.edits.TextEditProcessor; // packageimport
29 import org.eclipse.text.edits.MalformedTreeException; // packageimport
30 import org.eclipse.text.edits.TreeIterationInfo; // packageimport
31 import org.eclipse.text.edits.TextEditVisitor; // packageimport
32 import org.eclipse.text.edits.TextEdit; // packageimport
33 import org.eclipse.text.edits.RangeMarker; // packageimport
34 import org.eclipse.text.edits.UndoEdit; // packageimport
35 import org.eclipse.text.edits.InsertEdit; // packageimport
36
37
38 import java.lang.all;
39 import java.util.Arrays;
40 import java.util.List;
41 import java.util.ArrayList;
42
43
44
45
46 import org.eclipse.core.runtime.Assert;
47 import org.eclipse.jface.text.IRegion;
48
49
50 /**
51 * A text edit group combines a list of {@link TextEdit}s
52 * and a name into a single object. The name must be a human
53 * readable string use to present the text edit group in the
54 * user interface.
55 * <p>
56 * Clients may extend this class to add extra information to
57 * a text edit group.
58 * </p>
59 *
60 * @since 3.0
61 */
62 public class TextEditGroup {
63
64 private String fDescription;
65 private List fEdits;
66
67 /**
68 * Creates a new text edit group with the given name.
69 *
70 * @param name the name of the text edit group. Must be
71 * a human readable string
72 */
73 public this(String name) {
74 // super();
75 Assert.isNotNull(name);
76 fDescription= name;
77 fEdits= new ArrayList(3);
78 }
79
80 /**
81 * Creates a new text edit group with a name and a single
82 * {@link TextEdit}.
83 *
84 * @param name the name of the text edit group. Must be
85 * a human readable string
86 * @param edit the edit to manage
87 */
88 public this(String name, TextEdit edit) {
89 Assert.isNotNull(name);
90 Assert.isNotNull(edit);
91 fDescription= name;
92 fEdits= new ArrayList(1);
93 fEdits.add(edit);
94 }
95
96 /**
97 * Creates a new text edit group with the given name and
98 * array of edits.
99 *
100 * @param name the name of the text edit group. Must be
101 * a human readable string
102 * @param edits the array of edits
103 */
104 public this(String name, TextEdit[] edits) {
105 // super();
106 Assert.isNotNull(name);
107 Assert.isTrue(edits !is null);
108 fDescription= name;
109 fEdits= new ArrayList(Arrays.asList(edits));
110 }
111
112 /**
113 * Returns the edit group's name.
114 *
115 * @return the edit group's name
116 */
117 public String getName() {
118 return fDescription;
119 }
120
121 /**
122 * Adds the given {@link TextEdit} to this group.
123 *
124 * @param edit the edit to add
125 */
126 public void addTextEdit(TextEdit edit) {
127 fEdits.add(edit);
128 }
129
130 /**
131 * Removes the given {@link TextEdit} from this group.
132 *
133 * @param edit the edit to remove
134 * @return <code>true</code> if this group contained the specified edit.
135 * @since 3.3
136 */
137 public bool removeTextEdit(TextEdit edit) {
138 return fEdits.remove(edit);
139 }
140
141 /**
142 * Removes all text edits from this group.
143 *
144 * @since 3.3
145 */
146 public void clearTextEdits() {
147 fEdits.clear();
148 }
149
150
151
152 /**
153 * Returns <code>true</code> if the list of managed
154 * {@link TextEdit}s is empty; otherwise <code>false
155 * </code> is returned.
156 *
157 * @return whether the list of managed text edits is
158 * empty or not
159 */
160 public bool isEmpty() {
161 return fEdits.isEmpty();
162 }
163
164 /**
165 * Returns an array of {@link TextEdit}s containing
166 * the edits managed by this group.
167 *
168 * @return the managed text edits
169 */
170 public TextEdit[] getTextEdits() {
171 return arraycast!(TextEdit)( fEdits.toArray());
172 }
173
174 /**
175 * Returns the text region covered by the edits managed via this
176 * edit group. If the group doesn't manage any edits <code>null
177 * </code> is returned.
178 *
179 * @return the text region covered by this edit group or <code>
180 * null</code> if no edits are managed
181 */
182 public IRegion getRegion() {
183 int size= fEdits.size();
184 if (size is 0) {
185 return null;
186 } else if (size is 1) {
187 return (cast(TextEdit)fEdits.get(0)).getRegion();
188 } else {
189 return TextEdit.getCoverage(arraycast!(TextEdit)(fEdits.toArray()));
190 }
191 }
192 }