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