comparison dwtx/text/edits/TextEditVisitor.d @ 129:eb30df5ca28b

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