001: /*
002: * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javac.tree;
027:
028: import com.sun.tools.javac.util.*;
029: import com.sun.tools.javac.tree.JCTree.*;
030:
031: /** A subclass of Tree.Visitor, this class defines
032: * a general tree scanner pattern. Translation proceeds recursively in
033: * left-to-right order down a tree. There is one visitor method in this class
034: * for every possible kind of tree node. To obtain a specific
035: * scanner, it suffices to override those visitor methods which
036: * do some interesting work. The scanner class itself takes care of all
037: * navigational aspects.
038: *
039: * <p><b>This is NOT part of any API supported by Sun Microsystems. If
040: * you write code that depends on this, you do so at your own risk.
041: * This code and its internal interfaces are subject to change or
042: * deletion without notice.</b>
043: */
044: @Version("@(#)TreeScanner.java 1.32 07/05/05")
045: public class TreeScanner extends Visitor {
046:
047: /** Visitor method: Scan a single node.
048: */
049: public void scan(JCTree tree) {
050: if (tree != null)
051: tree.accept(this );
052: }
053:
054: /** Visitor method: scan a list of nodes.
055: */
056: public void scan(List<? extends JCTree> trees) {
057: if (trees != null)
058: for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
059: scan(l.head);
060: }
061:
062: /* ***************************************************************************
063: * Visitor methods
064: ****************************************************************************/
065:
066: public void visitTopLevel(JCCompilationUnit tree) {
067: scan(tree.packageAnnotations);
068: scan(tree.pid);
069: scan(tree.defs);
070: }
071:
072: public void visitImport(JCImport tree) {
073: scan(tree.qualid);
074: }
075:
076: public void visitClassDef(JCClassDecl tree) {
077: scan(tree.mods);
078: scan(tree.typarams);
079: scan(tree.extending);
080: scan(tree.implementing);
081: scan(tree.defs);
082: }
083:
084: public void visitMethodDef(JCMethodDecl tree) {
085: scan(tree.mods);
086: scan(tree.restype);
087: scan(tree.typarams);
088: scan(tree.params);
089: scan(tree.thrown);
090: scan(tree.body);
091: }
092:
093: public void visitVarDef(JCVariableDecl tree) {
094: scan(tree.mods);
095: scan(tree.vartype);
096: scan(tree.init);
097: }
098:
099: public void visitSkip(JCSkip tree) {
100: }
101:
102: public void visitBlock(JCBlock tree) {
103: scan(tree.stats);
104: }
105:
106: public void visitDoLoop(JCDoWhileLoop tree) {
107: scan(tree.body);
108: scan(tree.cond);
109: }
110:
111: public void visitWhileLoop(JCWhileLoop tree) {
112: scan(tree.cond);
113: scan(tree.body);
114: }
115:
116: public void visitForLoop(JCForLoop tree) {
117: scan(tree.init);
118: scan(tree.cond);
119: scan(tree.step);
120: scan(tree.body);
121: }
122:
123: public void visitForeachLoop(JCEnhancedForLoop tree) {
124: scan(tree.var);
125: scan(tree.expr);
126: scan(tree.body);
127: }
128:
129: public void visitLabelled(JCLabeledStatement tree) {
130: scan(tree.body);
131: }
132:
133: public void visitSwitch(JCSwitch tree) {
134: scan(tree.selector);
135: scan(tree.cases);
136: }
137:
138: public void visitCase(JCCase tree) {
139: scan(tree.pat);
140: scan(tree.stats);
141: }
142:
143: public void visitSynchronized(JCSynchronized tree) {
144: scan(tree.lock);
145: scan(tree.body);
146: }
147:
148: public void visitTry(JCTry tree) {
149: scan(tree.body);
150: scan(tree.catchers);
151: scan(tree.finalizer);
152: }
153:
154: public void visitCatch(JCCatch tree) {
155: scan(tree.param);
156: scan(tree.body);
157: }
158:
159: public void visitConditional(JCConditional tree) {
160: scan(tree.cond);
161: scan(tree.truepart);
162: scan(tree.falsepart);
163: }
164:
165: public void visitIf(JCIf tree) {
166: scan(tree.cond);
167: scan(tree.thenpart);
168: scan(tree.elsepart);
169: }
170:
171: public void visitExec(JCExpressionStatement tree) {
172: scan(tree.expr);
173: }
174:
175: public void visitBreak(JCBreak tree) {
176: }
177:
178: public void visitContinue(JCContinue tree) {
179: }
180:
181: public void visitReturn(JCReturn tree) {
182: scan(tree.expr);
183: }
184:
185: public void visitThrow(JCThrow tree) {
186: scan(tree.expr);
187: }
188:
189: public void visitAssert(JCAssert tree) {
190: scan(tree.cond);
191: scan(tree.detail);
192: }
193:
194: public void visitApply(JCMethodInvocation tree) {
195: scan(tree.meth);
196: scan(tree.args);
197: }
198:
199: public void visitNewClass(JCNewClass tree) {
200: scan(tree.encl);
201: scan(tree.clazz);
202: scan(tree.args);
203: scan(tree.def);
204: }
205:
206: public void visitNewArray(JCNewArray tree) {
207: scan(tree.elemtype);
208: scan(tree.dims);
209: scan(tree.elems);
210: }
211:
212: public void visitParens(JCParens tree) {
213: scan(tree.expr);
214: }
215:
216: public void visitAssign(JCAssign tree) {
217: scan(tree.lhs);
218: scan(tree.rhs);
219: }
220:
221: public void visitAssignop(JCAssignOp tree) {
222: scan(tree.lhs);
223: scan(tree.rhs);
224: }
225:
226: public void visitUnary(JCUnary tree) {
227: scan(tree.arg);
228: }
229:
230: public void visitBinary(JCBinary tree) {
231: scan(tree.lhs);
232: scan(tree.rhs);
233: }
234:
235: public void visitTypeCast(JCTypeCast tree) {
236: scan(tree.clazz);
237: scan(tree.expr);
238: }
239:
240: public void visitTypeTest(JCInstanceOf tree) {
241: scan(tree.expr);
242: scan(tree.clazz);
243: }
244:
245: public void visitIndexed(JCArrayAccess tree) {
246: scan(tree.indexed);
247: scan(tree.index);
248: }
249:
250: public void visitSelect(JCFieldAccess tree) {
251: scan(tree.selected);
252: }
253:
254: public void visitIdent(JCIdent tree) {
255: }
256:
257: public void visitLiteral(JCLiteral tree) {
258: }
259:
260: public void visitTypeIdent(JCPrimitiveTypeTree tree) {
261: }
262:
263: public void visitTypeArray(JCArrayTypeTree tree) {
264: scan(tree.elemtype);
265: }
266:
267: public void visitTypeApply(JCTypeApply tree) {
268: scan(tree.clazz);
269: scan(tree.arguments);
270: }
271:
272: public void visitTypeParameter(JCTypeParameter tree) {
273: scan(tree.bounds);
274: }
275:
276: @Override
277: public void visitWildcard(JCWildcard tree) {
278: scan(tree.kind);
279: if (tree.inner != null)
280: scan(tree.inner);
281: }
282:
283: @Override
284: public void visitTypeBoundKind(TypeBoundKind that) {
285: }
286:
287: public void visitModifiers(JCModifiers tree) {
288: scan(tree.annotations);
289: }
290:
291: public void visitAnnotation(JCAnnotation tree) {
292: scan(tree.annotationType);
293: scan(tree.args);
294: }
295:
296: public void visitErroneous(JCErroneous tree) {
297: }
298:
299: public void visitLetExpr(LetExpr tree) {
300: scan(tree.defs);
301: scan(tree.expr);
302: }
303:
304: public void visitTree(JCTree tree) {
305: assert false;
306: }
307: }
|