001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.text.edits;
011:
012: /**
013: * A visitor for text edits.
014: * <p>
015: * For each different concrete text edit type <it>T</it> there is a method:
016: * <ul>
017: * <li><code>public boolean visit(<it>T</it> node)</code> - Visits the given edit to
018: * perform some arbitrary operation. If <code>true </code> is returned, the given edit's
019: * child edits will be visited next; however, if <code>false</code> is returned, the
020: * given edit's child edits will not be visited. The default implementation provided by
021: * this class calls a generic method <code>visitNode(<it>TextEdit</it> node)</code>.
022: * Subclasses may reimplement these method as needed.</li>
023: * </ul>
024: * </p>
025: * <p>
026: * In addition, there are methods for visiting text edits in the
027: * abstract, regardless of node type:
028: * <ul>
029: * <li><code>public void preVisit(TextEdit edit)</code> - Visits
030: * the given edit to perform some arbitrary operation.
031: * This method is invoked prior to the appropriate type-specific
032: * <code>visit</code> method.
033: * The default implementation of this method does nothing.
034: * Subclasses may reimplement this method as needed.</li>
035: *
036: * <li><code>public void postVisit(TextEdit edit)</code> - Visits
037: * the given edit to perform some arbitrary operation.
038: * This method is invoked after the appropriate type-specific
039: * <code>endVisit</code> method.
040: * The default implementation of this method does nothing.
041: * Subclasses may reimplement this method as needed.</li>
042: * </ul>
043: * </p>
044: * <p>
045: * For edits with children, the child nodes are visited in increasing order.
046: * </p>
047: *
048: * @see TextEdit#accept(TextEditVisitor)
049: * @since 3.0
050: */
051: public class TextEditVisitor {
052:
053: /**
054: * Visits the given text edit prior to the type-specific visit.
055: * (before <code>visit</code>).
056: * <p>
057: * The default implementation does nothing. Subclasses may reimplement.
058: * </p>
059: *
060: * @param edit the node to visit
061: */
062: public void preVisit(TextEdit edit) {
063: // default implementation: do nothing
064: }
065:
066: /**
067: * Visits the given text edit following the type-specific visit
068: * (after <code>endVisit</code>).
069: * <p>
070: * The default implementation does nothing. Subclasses may reimplement.
071: * </p>
072: *
073: * @param edit the node to visit
074: */
075: public void postVisit(TextEdit edit) {
076: // default implementation: do nothing
077: }
078:
079: /**
080: * Visits the given text edit. This method is called by default from
081: * type-specific visits. It is not called by an edit's accept method.
082: * The default implementation returns <code>true</code>.
083: *
084: * @param edit the node to visit
085: * @return If <code>true</code> is returned, the given node's child
086: * nodes will be visited next; however, if <code>false</code> is
087: * returned, the given node's child nodes will not be visited.
088: */
089: public boolean visitNode(TextEdit edit) {
090: return true;
091: }
092:
093: /**
094: * Visits a <code>CopySourceEdit</code> instance.
095: *
096: * @param edit the node to visit
097: * @return If <code>true</code> is returned, the given node's child
098: * nodes will be visited next; however, if <code>false</code> is
099: * returned, the given node's child nodes will not be visited.
100: */
101: public boolean visit(CopySourceEdit edit) {
102: return visitNode(edit);
103: }
104:
105: /**
106: * Visits a <code>CopyTargetEdit</code> instance.
107: *
108: * @param edit the node to visit
109: * @return If <code>true</code> is returned, the given node's child
110: * nodes will be visited next; however, if <code>false</code> is
111: * returned, the given node's child nodes will not be visited.
112: */
113: public boolean visit(CopyTargetEdit edit) {
114: return visitNode(edit);
115: }
116:
117: /**
118: * Visits a <code>MoveSourceEdit</code> instance.
119: *
120: * @param edit the node to visit
121: * @return If <code>true</code> is returned, the given node's child
122: * nodes will be visited next; however, if <code>false</code> is
123: * returned, the given node's child nodes will not be visited.
124: */
125: public boolean visit(MoveSourceEdit edit) {
126: return visitNode(edit);
127: }
128:
129: /**
130: * Visits a <code>MoveTargetEdit</code> instance.
131: *
132: * @param edit the node to visit
133: * @return If <code>true</code> is returned, the given node's child
134: * nodes will be visited next; however, if <code>false</code> is
135: * returned, the given node's child nodes will not be visited.
136: */
137: public boolean visit(MoveTargetEdit edit) {
138: return visitNode(edit);
139: }
140:
141: /**
142: * Visits a <code>RangeMarker</code> instance.
143: *
144: * @param edit the node to visit
145: * @return If <code>true</code> is returned, the given node's child
146: * nodes will be visited next; however, if <code>false</code> is
147: * returned, the given node's child nodes will not be visited.
148: */
149: public boolean visit(RangeMarker edit) {
150: return visitNode(edit);
151: }
152:
153: /**
154: * Visits a <code>CopyingRangeMarker</code> instance.
155: *
156: * @param edit the node to visit
157: * @return If <code>true</code> is returned, the given node's child
158: * nodes will be visited next; however, if <code>false</code> is
159: * returned, the given node's child nodes will not be visited.
160: */
161: public boolean visit(CopyingRangeMarker edit) {
162: return visitNode(edit);
163: }
164:
165: /**
166: * Visits a <code>DeleteEdit</code> instance.
167: *
168: * @param edit the node to visit
169: * @return If <code>true</code> is returned, the given node's child
170: * nodes will be visited next; however, if <code>false</code> is
171: * returned, the given node's child nodes will not be visited.
172: */
173: public boolean visit(DeleteEdit edit) {
174: return visitNode(edit);
175: }
176:
177: /**
178: * Visits a <code>InsertEdit</code> instance.
179: *
180: * @param edit the node to visit
181: * @return If <code>true</code> is returned, the given node's child
182: * nodes will be visited next; however, if <code>false</code> is
183: * returned, the given node's child nodes will not be visited.
184: */
185: public boolean visit(InsertEdit edit) {
186: return visitNode(edit);
187: }
188:
189: /**
190: * Visits a <code>ReplaceEdit</code> instance.
191: *
192: * @param edit the node to visit
193: * @return If <code>true</code> is returned, the given node's child
194: * nodes will be visited next; however, if <code>false</code> is
195: * returned, the given node's child nodes will not be visited.
196: */
197: public boolean visit(ReplaceEdit edit) {
198: return visitNode(edit);
199: }
200:
201: /**
202: * Visits a <code>UndoEdit</code> instance.
203: *
204: * @param edit the node to visit
205: * @return If <code>true</code> is returned, the given node's child
206: * nodes will be visited next; however, if <code>false</code> is
207: * returned, the given node's child nodes will not be visited.
208: */
209: public boolean visit(UndoEdit edit) {
210: return visitNode(edit);
211: }
212:
213: /**
214: * Visits a <code>MultiTextEdit</code> instance.
215: *
216: * @param edit the node to visit
217: * @return If <code>true</code> is returned, the given node's child
218: * nodes will be visited next; however, if <code>false</code> is
219: * returned, the given node's child nodes will not be visited.
220: */
221: public boolean visit(MultiTextEdit edit) {
222: return visitNode(edit);
223: }
224: }
|