/* * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ package com.sun.tools.javac.tree; import com.sun.tools.javac.util.*; import com.sun.tools.javac.tree.JCTree.*; /** A subclass of Tree.Visitor, this class defines * a general tree scanner pattern. Translation proceeds recursively in * left-to-right order down a tree. There is one visitor method in this class * for every possible kind of tree node. To obtain a specific * scanner, it suffices to override those visitor methods which * do some interesting work. The scanner class itself takes care of all * navigational aspects. * *
This is NOT part of any API supported by Sun Microsystems. If
* you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*/
public class TreeScanner extends Visitor {
/** Visitor method: Scan a single node.
*/
public void scan(JCTree tree) {
if(tree!=null) tree.accept(this);
}
/** Visitor method: scan a list of nodes.
*/
public void scan(List extends JCTree> trees) {
if (trees != null)
for (List extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
scan(l.head);
}
/* ***************************************************************************
* Visitor methods
****************************************************************************/
public void visitTopLevel(JCCompilationUnit tree) {
scan(tree.packageAnnotations);
scan(tree.pid);
scan(tree.defs);
}
public void visitImport(JCImport tree) {
scan(tree.qualid);
}
public void visitClassDef(JCClassDecl tree) {
scan(tree.mods);
scan(tree.typarams);
scan(tree.extending);
scan(tree.implementing);
scan(tree.defs);
}
public void visitMethodDef(JCMethodDecl tree) {
scan(tree.mods);
scan(tree.restype);
scan(tree.typarams);
scan(tree.params);
scan(tree.receiverAnnotations);
scan(tree.thrown);
scan(tree.defaultValue);
scan(tree.body);
}
public void visitVarDef(JCVariableDecl tree) {
scan(tree.mods);
scan(tree.vartype);
scan(tree.init);
}
public void visitSkip(JCSkip tree) {
}
public void visitBlock(JCBlock tree) {
scan(tree.stats);
}
public void visitDoLoop(JCDoWhileLoop tree) {
scan(tree.body);
scan(tree.cond);
}
public void visitWhileLoop(JCWhileLoop tree) {
scan(tree.cond);
scan(tree.body);
}
public void visitForLoop(JCForLoop tree) {
scan(tree.init);
scan(tree.cond);
scan(tree.step);
scan(tree.body);
}
public void visitForeachLoop(JCEnhancedForLoop tree) {
scan(tree.var);
scan(tree.expr);
scan(tree.body);
}
public void visitLabelled(JCLabeledStatement tree) {
scan(tree.body);
}
public void visitSwitch(JCSwitch tree) {
scan(tree.selector);
scan(tree.cases);
}
public void visitCase(JCCase tree) {
scan(tree.pat);
scan(tree.stats);
}
public void visitSynchronized(JCSynchronized tree) {
scan(tree.lock);
scan(tree.body);
}
public void visitTry(JCTry tree) {
scan(tree.body);
scan(tree.catchers);
scan(tree.finalizer);
}
public void visitCatch(JCCatch tree) {
scan(tree.param);
scan(tree.body);
}
public void visitConditional(JCConditional tree) {
scan(tree.cond);
scan(tree.truepart);
scan(tree.falsepart);
}
public void visitIf(JCIf tree) {
scan(tree.cond);
scan(tree.thenpart);
scan(tree.elsepart);
}
public void visitExec(JCExpressionStatement tree) {
scan(tree.expr);
}
public void visitBreak(JCBreak tree) {
}
public void visitContinue(JCContinue tree) {
}
public void visitReturn(JCReturn tree) {
scan(tree.expr);
}
public void visitThrow(JCThrow tree) {
scan(tree.expr);
}
public void visitAssert(JCAssert tree) {
scan(tree.cond);
scan(tree.detail);
}
public void visitApply(JCMethodInvocation tree) {
scan(tree.meth);
scan(tree.args);
}
public void visitNewClass(JCNewClass tree) {
scan(tree.encl);
scan(tree.clazz);
scan(tree.args);
scan(tree.def);
}
public void visitNewArray(JCNewArray tree) {
scan(tree.annotations);
scan(tree.elemtype);
scan(tree.dims);
for (List