KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > text > edits > TextEditVisitor


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  *******************************************************************************/

11 package org.eclipse.text.edits;
12
13 /**
14  * A visitor for text edits.
15  * <p>
16  * For each different concrete text edit type <it>T</it> there is a method:
17  * <ul>
18  * <li><code>public boolean visit(<it>T</it> node)</code> - Visits the given edit to
19  * perform some arbitrary operation. If <code>true </code> is returned, the given edit's
20  * child edits will be visited next; however, if <code>false</code> is returned, the
21  * given edit's child edits will not be visited. The default implementation provided by
22  * this class calls a generic method <code>visitNode(<it>TextEdit</it> node)</code>.
23  * Subclasses may reimplement these method as needed.</li>
24  * </ul>
25  * </p>
26  * <p>
27  * In addition, there are methods for visiting text edits in the
28  * abstract, regardless of node type:
29  * <ul>
30  * <li><code>public void preVisit(TextEdit edit)</code> - Visits
31  * the given edit to perform some arbitrary operation.
32  * This method is invoked prior to the appropriate type-specific
33  * <code>visit</code> method.
34  * The default implementation of this method does nothing.
35  * Subclasses may reimplement this method as needed.</li>
36  *
37  * <li><code>public void postVisit(TextEdit edit)</code> - Visits
38  * the given edit to perform some arbitrary operation.
39  * This method is invoked after the appropriate type-specific
40  * <code>endVisit</code> method.
41  * The default implementation of this method does nothing.
42  * Subclasses may reimplement this method as needed.</li>
43  * </ul>
44  * </p>
45  * <p>
46  * For edits with children, the child nodes are visited in increasing order.
47  * </p>
48  *
49  * @see TextEdit#accept(TextEditVisitor)
50  * @since 3.0
51  */

52 public class TextEditVisitor {
53
54     /**
55      * Visits the given text edit prior to the type-specific visit.
56      * (before <code>visit</code>).
57      * <p>
58      * The default implementation does nothing. Subclasses may reimplement.
59      * </p>
60      *
61      * @param edit the node to visit
62      */

63     public void preVisit(TextEdit edit) {
64         // default implementation: do nothing
65
}
66
67     /**
68      * Visits the given text edit following the type-specific visit
69      * (after <code>endVisit</code>).
70      * <p>
71      * The default implementation does nothing. Subclasses may reimplement.
72      * </p>
73      *
74      * @param edit the node to visit
75      */

76     public void postVisit(TextEdit edit) {
77         // default implementation: do nothing
78
}
79
80     /**
81      * Visits the given text edit. This method is called by default from
82      * type-specific visits. It is not called by an edit's accept method.
83      * The default implementation returns <code>true</code>.
84      *
85      * @param edit the node to visit
86      * @return If <code>true</code> is returned, the given node's child
87      * nodes will be visited next; however, if <code>false</code> is
88      * returned, the given node's child nodes will not be visited.
89      */

90     public boolean visitNode(TextEdit edit) {
91         return true;
92     }
93
94     /**
95      * Visits a <code>CopySourceEdit</code> instance.
96      *
97      * @param edit the node to visit
98      * @return If <code>true</code> is returned, the given node's child
99      * nodes will be visited next; however, if <code>false</code> is
100      * returned, the given node's child nodes will not be visited.
101      */

102     public boolean visit(CopySourceEdit edit) {
103         return visitNode(edit);
104     }
105
106     /**
107      * Visits a <code>CopyTargetEdit</code> instance.
108      *
109      * @param edit the node to visit
110      * @return If <code>true</code> is returned, the given node's child
111      * nodes will be visited next; however, if <code>false</code> is
112      * returned, the given node's child nodes will not be visited.
113      */

114     public boolean visit(CopyTargetEdit edit) {
115         return visitNode(edit);
116     }
117
118     /**
119      * Visits a <code>MoveSourceEdit</code> instance.
120      *
121      * @param edit the node to visit
122      * @return If <code>true</code> is returned, the given node's child
123      * nodes will be visited next; however, if <code>false</code> is
124      * returned, the given node's child nodes will not be visited.
125      */

126     public boolean visit(MoveSourceEdit edit) {
127         return visitNode(edit);
128     }
129
130     /**
131      * Visits a <code>MoveTargetEdit</code> instance.
132      *
133      * @param edit the node to visit
134      * @return If <code>true</code> is returned, the given node's child
135      * nodes will be visited next; however, if <code>false</code> is
136      * returned, the given node's child nodes will not be visited.
137      */

138     public boolean visit(MoveTargetEdit edit) {
139         return visitNode(edit);
140     }
141
142     /**
143      * Visits a <code>RangeMarker</code> instance.
144      *
145      * @param edit the node to visit
146      * @return If <code>true</code> is returned, the given node's child
147      * nodes will be visited next; however, if <code>false</code> is
148      * returned, the given node's child nodes will not be visited.
149      */

150     public boolean visit(RangeMarker edit) {
151         return visitNode(edit);
152     }
153
154     /**
155      * Visits a <code>CopyingRangeMarker</code> instance.
156      *
157      * @param edit the node to visit
158      * @return If <code>true</code> is returned, the given node's child
159      * nodes will be visited next; however, if <code>false</code> is
160      * returned, the given node's child nodes will not be visited.
161      */

162     public boolean visit(CopyingRangeMarker edit) {
163         return visitNode(edit);
164     }
165
166     /**
167      * Visits a <code>DeleteEdit</code> instance.
168      *
169      * @param edit the node to visit
170      * @return If <code>true</code> is returned, the given node's child
171      * nodes will be visited next; however, if <code>false</code> is
172      * returned, the given node's child nodes will not be visited.
173      */

174     public boolean visit(DeleteEdit edit) {
175         return visitNode(edit);
176     }
177
178     /**
179      * Visits a <code>InsertEdit</code> instance.
180      *
181      * @param edit the node to visit
182      * @return If <code>true</code> is returned, the given node's child
183      * nodes will be visited next; however, if <code>false</code> is
184      * returned, the given node's child nodes will not be visited.
185      */

186     public boolean visit(InsertEdit edit) {
187         return visitNode(edit);
188     }
189
190     /**
191      * Visits a <code>ReplaceEdit</code> instance.
192      *
193      * @param edit the node to visit
194      * @return If <code>true</code> is returned, the given node's child
195      * nodes will be visited next; however, if <code>false</code> is
196      * returned, the given node's child nodes will not be visited.
197      */

198     public boolean visit(ReplaceEdit edit) {
199         return visitNode(edit);
200     }
201
202     /**
203      * Visits a <code>UndoEdit</code> instance.
204      *
205      * @param edit the node to visit
206      * @return If <code>true</code> is returned, the given node's child
207      * nodes will be visited next; however, if <code>false</code> is
208      * returned, the given node's child nodes will not be visited.
209      */

210     public boolean visit(UndoEdit edit) {
211         return visitNode(edit);
212     }
213
214     /**
215      * Visits a <code>MultiTextEdit</code> instance.
216      *
217      * @param edit the node to visit
218      * @return If <code>true</code> is returned, the given node's child
219      * nodes will be visited next; however, if <code>false</code> is
220      * returned, the given node's child nodes will not be visited.
221      */

222     public boolean visit(MultiTextEdit edit) {
223         return visitNode(edit);
224     }
225 }
226
Popular Tags