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.TextEditVisitor;
|
|
14
|
131
|
15 import dwtx.text.edits.MultiTextEdit; // packageimport
|
|
16 import dwtx.text.edits.CopySourceEdit; // packageimport
|
|
17 import dwtx.text.edits.MoveSourceEdit; // packageimport
|
|
18 import dwtx.text.edits.CopyingRangeMarker; // packageimport
|
|
19 import dwtx.text.edits.ReplaceEdit; // packageimport
|
|
20 import dwtx.text.edits.EditDocument; // packageimport
|
|
21 import dwtx.text.edits.UndoCollector; // packageimport
|
|
22 import dwtx.text.edits.DeleteEdit; // packageimport
|
|
23 import dwtx.text.edits.MoveTargetEdit; // packageimport
|
|
24 import dwtx.text.edits.CopyTargetEdit; // packageimport
|
|
25 import dwtx.text.edits.TextEditCopier; // packageimport
|
|
26 import dwtx.text.edits.ISourceModifier; // packageimport
|
|
27 import dwtx.text.edits.TextEditMessages; // packageimport
|
|
28 import dwtx.text.edits.TextEditProcessor; // packageimport
|
|
29 import dwtx.text.edits.MalformedTreeException; // packageimport
|
|
30 import dwtx.text.edits.TreeIterationInfo; // packageimport
|
|
31 import dwtx.text.edits.TextEditGroup; // packageimport
|
|
32 import dwtx.text.edits.TextEdit; // packageimport
|
|
33 import dwtx.text.edits.RangeMarker; // packageimport
|
|
34 import dwtx.text.edits.UndoEdit; // packageimport
|
|
35 import dwtx.text.edits.InsertEdit; // packageimport
|
|
36
|
|
37
|
129
|
38 import dwt.dwthelper.utils;
|
|
39
|
|
40 /**
|
|
41 * A visitor for text edits.
|
|
42 * <p>
|
|
43 * For each different concrete text edit type <it>T</it> there is a method:
|
|
44 * <ul>
|
|
45 * <li><code>public bool visit(<it>T</it> node)</code> - Visits the given edit to
|
|
46 * perform some arbitrary operation. If <code>true </code> is returned, the given edit's
|
|
47 * child edits will be visited next; however, if <code>false</code> is returned, the
|
|
48 * given edit's child edits will not be visited. The default implementation provided by
|
|
49 * this class calls a generic method <code>visitNode(<it>TextEdit</it> node)</code>.
|
|
50 * Subclasses may reimplement these method as needed.</li>
|
|
51 * </ul>
|
|
52 * </p>
|
|
53 * <p>
|
|
54 * In addition, there are methods for visiting text edits in the
|
|
55 * abstract, regardless of node type:
|
|
56 * <ul>
|
|
57 * <li><code>public void preVisit(TextEdit edit)</code> - Visits
|
|
58 * the given edit to perform some arbitrary operation.
|
|
59 * This method is invoked prior to the appropriate type-specific
|
|
60 * <code>visit</code> method.
|
|
61 * The default implementation of this method does nothing.
|
|
62 * Subclasses may reimplement this method as needed.</li>
|
|
63 *
|
|
64 * <li><code>public void postVisit(TextEdit edit)</code> - Visits
|
|
65 * the given edit to perform some arbitrary operation.
|
|
66 * This method is invoked after the appropriate type-specific
|
|
67 * <code>endVisit</code> method.
|
|
68 * The default implementation of this method does nothing.
|
|
69 * Subclasses may reimplement this method as needed.</li>
|
|
70 * </ul>
|
|
71 * </p>
|
|
72 * <p>
|
|
73 * For edits with children, the child nodes are visited in increasing order.
|
|
74 * </p>
|
|
75 *
|
|
76 * @see TextEdit#accept(TextEditVisitor)
|
|
77 * @since 3.0
|
|
78 */
|
|
79 public class TextEditVisitor {
|
|
80
|
|
81 /**
|
|
82 * Visits the given text edit prior to the type-specific visit.
|
|
83 * (before <code>visit</code>).
|
|
84 * <p>
|
|
85 * The default implementation does nothing. Subclasses may reimplement.
|
|
86 * </p>
|
|
87 *
|
|
88 * @param edit the node to visit
|
|
89 */
|
|
90 public void preVisit(TextEdit edit) {
|
|
91 // default implementation: do nothing
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * Visits the given text edit following the type-specific visit
|
|
96 * (after <code>endVisit</code>).
|
|
97 * <p>
|
|
98 * The default implementation does nothing. Subclasses may reimplement.
|
|
99 * </p>
|
|
100 *
|
|
101 * @param edit the node to visit
|
|
102 */
|
|
103 public void postVisit(TextEdit edit) {
|
|
104 // default implementation: do nothing
|
|
105 }
|
|
106
|
|
107 /**
|
|
108 * Visits the given text edit. This method is called by default from
|
|
109 * type-specific visits. It is not called by an edit's accept method.
|
|
110 * The default implementation returns <code>true</code>.
|
|
111 *
|
|
112 * @param edit the node to visit
|
|
113 * @return If <code>true</code> is returned, the given node's child
|
|
114 * nodes will be visited next; however, if <code>false</code> is
|
|
115 * returned, the given node's child nodes will not be visited.
|
|
116 */
|
|
117 public bool visitNode(TextEdit edit) {
|
|
118 return true;
|
|
119 }
|
|
120
|
|
121 /**
|
|
122 * Visits a <code>CopySourceEdit</code> instance.
|
|
123 *
|
|
124 * @param edit the node to visit
|
|
125 * @return If <code>true</code> is returned, the given node's child
|
|
126 * nodes will be visited next; however, if <code>false</code> is
|
|
127 * returned, the given node's child nodes will not be visited.
|
|
128 */
|
|
129 public bool visit(CopySourceEdit edit) {
|
|
130 return visitNode(edit);
|
|
131 }
|
|
132
|
|
133 /**
|
|
134 * Visits a <code>CopyTargetEdit</code> instance.
|
|
135 *
|
|
136 * @param edit the node to visit
|
|
137 * @return If <code>true</code> is returned, the given node's child
|
|
138 * nodes will be visited next; however, if <code>false</code> is
|
|
139 * returned, the given node's child nodes will not be visited.
|
|
140 */
|
|
141 public bool visit(CopyTargetEdit edit) {
|
|
142 return visitNode(edit);
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * Visits a <code>MoveSourceEdit</code> instance.
|
|
147 *
|
|
148 * @param edit the node to visit
|
|
149 * @return If <code>true</code> is returned, the given node's child
|
|
150 * nodes will be visited next; however, if <code>false</code> is
|
|
151 * returned, the given node's child nodes will not be visited.
|
|
152 */
|
|
153 public bool visit(MoveSourceEdit edit) {
|
|
154 return visitNode(edit);
|
|
155 }
|
|
156
|
|
157 /**
|
|
158 * Visits a <code>MoveTargetEdit</code> instance.
|
|
159 *
|
|
160 * @param edit the node to visit
|
|
161 * @return If <code>true</code> is returned, the given node's child
|
|
162 * nodes will be visited next; however, if <code>false</code> is
|
|
163 * returned, the given node's child nodes will not be visited.
|
|
164 */
|
|
165 public bool visit(MoveTargetEdit edit) {
|
|
166 return visitNode(edit);
|
|
167 }
|
|
168
|
|
169 /**
|
|
170 * Visits a <code>RangeMarker</code> instance.
|
|
171 *
|
|
172 * @param edit the node to visit
|
|
173 * @return If <code>true</code> is returned, the given node's child
|
|
174 * nodes will be visited next; however, if <code>false</code> is
|
|
175 * returned, the given node's child nodes will not be visited.
|
|
176 */
|
|
177 public bool visit(RangeMarker edit) {
|
|
178 return visitNode(edit);
|
|
179 }
|
|
180
|
|
181 /**
|
|
182 * Visits a <code>CopyingRangeMarker</code> instance.
|
|
183 *
|
|
184 * @param edit the node to visit
|
|
185 * @return If <code>true</code> is returned, the given node's child
|
|
186 * nodes will be visited next; however, if <code>false</code> is
|
|
187 * returned, the given node's child nodes will not be visited.
|
|
188 */
|
|
189 public bool visit(CopyingRangeMarker edit) {
|
|
190 return visitNode(edit);
|
|
191 }
|
|
192
|
|
193 /**
|
|
194 * Visits a <code>DeleteEdit</code> instance.
|
|
195 *
|
|
196 * @param edit the node to visit
|
|
197 * @return If <code>true</code> is returned, the given node's child
|
|
198 * nodes will be visited next; however, if <code>false</code> is
|
|
199 * returned, the given node's child nodes will not be visited.
|
|
200 */
|
|
201 public bool visit(DeleteEdit edit) {
|
|
202 return visitNode(edit);
|
|
203 }
|
|
204
|
|
205 /**
|
|
206 * Visits a <code>InsertEdit</code> instance.
|
|
207 *
|
|
208 * @param edit the node to visit
|
|
209 * @return If <code>true</code> is returned, the given node's child
|
|
210 * nodes will be visited next; however, if <code>false</code> is
|
|
211 * returned, the given node's child nodes will not be visited.
|
|
212 */
|
|
213 public bool visit(InsertEdit edit) {
|
|
214 return visitNode(edit);
|
|
215 }
|
|
216
|
|
217 /**
|
|
218 * Visits a <code>ReplaceEdit</code> instance.
|
|
219 *
|
|
220 * @param edit the node to visit
|
|
221 * @return If <code>true</code> is returned, the given node's child
|
|
222 * nodes will be visited next; however, if <code>false</code> is
|
|
223 * returned, the given node's child nodes will not be visited.
|
|
224 */
|
|
225 public bool visit(ReplaceEdit edit) {
|
|
226 return visitNode(edit);
|
|
227 }
|
|
228
|
|
229 /**
|
|
230 * Visits a <code>UndoEdit</code> instance.
|
|
231 *
|
|
232 * @param edit the node to visit
|
|
233 * @return If <code>true</code> is returned, the given node's child
|
|
234 * nodes will be visited next; however, if <code>false</code> is
|
|
235 * returned, the given node's child nodes will not be visited.
|
|
236 */
|
|
237 public bool visit(UndoEdit edit) {
|
|
238 return visitNode(edit);
|
|
239 }
|
|
240
|
|
241 /**
|
|
242 * Visits a <code>MultiTextEdit</code> instance.
|
|
243 *
|
|
244 * @param edit the node to visit
|
|
245 * @return If <code>true</code> is returned, the given node's child
|
|
246 * nodes will be visited next; however, if <code>false</code> is
|
|
247 * returned, the given node's child nodes will not be visited.
|
|
248 */
|
|
249 public bool visit(MultiTextEdit edit) {
|
|
250 return visitNode(edit);
|
|
251 }
|
|
252 }
|