src/share/classes/com/sun/tools/javac/tree/TreeScanner.java

Wed, 23 Jan 2013 13:27:24 -0800

author
jjg
date
Wed, 23 Jan 2013 13:27:24 -0800
changeset 1521
71f35e4b93a5
parent 1436
f6f1fd261f57
child 1755
ddb4a2bfcd82
permissions
-rw-r--r--

8006775: JSR 308: Compiler changes in JDK8
Reviewed-by: jjg
Contributed-by: mernst@cs.washington.edu, wmdietl@cs.washington.edu, mpapi@csail.mit.edu, mahmood@notnoop.com

     1 /*
     2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javac.tree;
    28 import com.sun.tools.javac.util.*;
    29 import com.sun.tools.javac.tree.JCTree.*;
    31 /** A subclass of Tree.Visitor, this class defines
    32  *  a general tree scanner pattern. Translation proceeds recursively in
    33  *  left-to-right order down a tree. There is one visitor method in this class
    34  *  for every possible kind of tree node.  To obtain a specific
    35  *  scanner, it suffices to override those visitor methods which
    36  *  do some interesting work. The scanner class itself takes care of all
    37  *  navigational aspects.
    38  *
    39  *  <p><b>This is NOT part of any supported API.
    40  *  If you write code that depends on this, you do so at your own risk.
    41  *  This code and its internal interfaces are subject to change or
    42  *  deletion without notice.</b>
    43  */
    44 public class TreeScanner extends Visitor {
    46     /** Visitor method: Scan a single node.
    47      */
    48     public void scan(JCTree tree) {
    49         if(tree!=null) tree.accept(this);
    50     }
    52     /** Visitor method: scan a list of nodes.
    53      */
    54     public void scan(List<? extends JCTree> trees) {
    55         if (trees != null)
    56         for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
    57             scan(l.head);
    58     }
    61 /* ***************************************************************************
    62  * Visitor methods
    63  ****************************************************************************/
    65     public void visitTopLevel(JCCompilationUnit tree) {
    66         scan(tree.packageAnnotations);
    67         scan(tree.pid);
    68         scan(tree.defs);
    69     }
    71     public void visitImport(JCImport tree) {
    72         scan(tree.qualid);
    73     }
    75     public void visitClassDef(JCClassDecl tree) {
    76         scan(tree.mods);
    77         scan(tree.typarams);
    78         scan(tree.extending);
    79         scan(tree.implementing);
    80         scan(tree.defs);
    81     }
    83     public void visitMethodDef(JCMethodDecl tree) {
    84         scan(tree.mods);
    85         scan(tree.restype);
    86         scan(tree.typarams);
    87         scan(tree.recvparam);
    88         scan(tree.params);
    89         scan(tree.thrown);
    90         scan(tree.defaultValue);
    91         scan(tree.body);
    92     }
    94     public void visitVarDef(JCVariableDecl tree) {
    95         scan(tree.mods);
    96         scan(tree.vartype);
    97         scan(tree.init);
    98     }
   100     public void visitSkip(JCSkip tree) {
   101     }
   103     public void visitBlock(JCBlock tree) {
   104         scan(tree.stats);
   105     }
   107     public void visitDoLoop(JCDoWhileLoop tree) {
   108         scan(tree.body);
   109         scan(tree.cond);
   110     }
   112     public void visitWhileLoop(JCWhileLoop tree) {
   113         scan(tree.cond);
   114         scan(tree.body);
   115     }
   117     public void visitForLoop(JCForLoop tree) {
   118         scan(tree.init);
   119         scan(tree.cond);
   120         scan(tree.step);
   121         scan(tree.body);
   122     }
   124     public void visitForeachLoop(JCEnhancedForLoop tree) {
   125         scan(tree.var);
   126         scan(tree.expr);
   127         scan(tree.body);
   128     }
   130     public void visitLabelled(JCLabeledStatement tree) {
   131         scan(tree.body);
   132     }
   134     public void visitSwitch(JCSwitch tree) {
   135         scan(tree.selector);
   136         scan(tree.cases);
   137     }
   139     public void visitCase(JCCase tree) {
   140         scan(tree.pat);
   141         scan(tree.stats);
   142     }
   144     public void visitSynchronized(JCSynchronized tree) {
   145         scan(tree.lock);
   146         scan(tree.body);
   147     }
   149     public void visitTry(JCTry tree) {
   150         scan(tree.resources);
   151         scan(tree.body);
   152         scan(tree.catchers);
   153         scan(tree.finalizer);
   154     }
   156     public void visitCatch(JCCatch tree) {
   157         scan(tree.param);
   158         scan(tree.body);
   159     }
   161     public void visitConditional(JCConditional tree) {
   162         scan(tree.cond);
   163         scan(tree.truepart);
   164         scan(tree.falsepart);
   165     }
   167     public void visitIf(JCIf tree) {
   168         scan(tree.cond);
   169         scan(tree.thenpart);
   170         scan(tree.elsepart);
   171     }
   173     public void visitExec(JCExpressionStatement tree) {
   174         scan(tree.expr);
   175     }
   177     public void visitBreak(JCBreak tree) {
   178     }
   180     public void visitContinue(JCContinue tree) {
   181     }
   183     public void visitReturn(JCReturn tree) {
   184         scan(tree.expr);
   185     }
   187     public void visitThrow(JCThrow tree) {
   188         scan(tree.expr);
   189     }
   191     public void visitAssert(JCAssert tree) {
   192         scan(tree.cond);
   193         scan(tree.detail);
   194     }
   196     public void visitApply(JCMethodInvocation tree) {
   197         scan(tree.typeargs);
   198         scan(tree.meth);
   199         scan(tree.args);
   200     }
   202     public void visitNewClass(JCNewClass tree) {
   203         scan(tree.encl);
   204         scan(tree.typeargs);
   205         scan(tree.clazz);
   206         scan(tree.args);
   207         scan(tree.def);
   208     }
   210     public void visitNewArray(JCNewArray tree) {
   211         scan(tree.annotations);
   212         scan(tree.elemtype);
   213         scan(tree.dims);
   214         for (List<JCAnnotation> annos : tree.dimAnnotations)
   215             scan(annos);
   216         scan(tree.elems);
   217     }
   219     public void visitLambda(JCLambda tree) {
   220         scan(tree.body);
   221         scan(tree.params);
   222     }
   224     public void visitParens(JCParens tree) {
   225         scan(tree.expr);
   226     }
   228     public void visitAssign(JCAssign tree) {
   229         scan(tree.lhs);
   230         scan(tree.rhs);
   231     }
   233     public void visitAssignop(JCAssignOp tree) {
   234         scan(tree.lhs);
   235         scan(tree.rhs);
   236     }
   238     public void visitUnary(JCUnary tree) {
   239         scan(tree.arg);
   240     }
   242     public void visitBinary(JCBinary tree) {
   243         scan(tree.lhs);
   244         scan(tree.rhs);
   245     }
   247     public void visitTypeCast(JCTypeCast tree) {
   248         scan(tree.clazz);
   249         scan(tree.expr);
   250     }
   252     public void visitTypeTest(JCInstanceOf tree) {
   253         scan(tree.expr);
   254         scan(tree.clazz);
   255     }
   257     public void visitIndexed(JCArrayAccess tree) {
   258         scan(tree.indexed);
   259         scan(tree.index);
   260     }
   262     public void visitSelect(JCFieldAccess tree) {
   263         scan(tree.selected);
   264     }
   266     public void visitReference(JCMemberReference tree) {
   267         scan(tree.expr);
   268         scan(tree.typeargs);
   269     }
   271     public void visitIdent(JCIdent tree) {
   272     }
   274     public void visitLiteral(JCLiteral tree) {
   275     }
   277     public void visitTypeIdent(JCPrimitiveTypeTree tree) {
   278     }
   280     public void visitTypeArray(JCArrayTypeTree tree) {
   281         scan(tree.elemtype);
   282     }
   284     public void visitTypeApply(JCTypeApply tree) {
   285         scan(tree.clazz);
   286         scan(tree.arguments);
   287     }
   289     public void visitTypeUnion(JCTypeUnion tree) {
   290         scan(tree.alternatives);
   291     }
   293     public void visitTypeIntersection(JCTypeIntersection tree) {
   294         scan(tree.bounds);
   295     }
   297     public void visitTypeParameter(JCTypeParameter tree) {
   298         scan(tree.annotations);
   299         scan(tree.bounds);
   300     }
   302     @Override
   303     public void visitWildcard(JCWildcard tree) {
   304         scan(tree.kind);
   305         if (tree.inner != null)
   306             scan(tree.inner);
   307     }
   309     @Override
   310     public void visitTypeBoundKind(TypeBoundKind that) {
   311     }
   313     public void visitModifiers(JCModifiers tree) {
   314         scan(tree.annotations);
   315     }
   317     public void visitAnnotation(JCAnnotation tree) {
   318         scan(tree.annotationType);
   319         scan(tree.args);
   320     }
   322     public void visitAnnotatedType(JCAnnotatedType tree) {
   323         scan(tree.annotations);
   324         scan(tree.underlyingType);
   325     }
   327     public void visitErroneous(JCErroneous tree) {
   328     }
   330     public void visitLetExpr(LetExpr tree) {
   331         scan(tree.defs);
   332         scan(tree.expr);
   333     }
   335     public void visitTree(JCTree tree) {
   336         Assert.error();
   337     }
   338 }

mercurial