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

Thu, 04 Aug 2016 23:35:54 -0700

author
asaha
date
Thu, 04 Aug 2016 23:35:54 -0700
changeset 3269
faed7e254d11
parent 1755
ddb4a2bfcd82
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8162510: 8u112 L10n resource file updates
Summary: 8u112 L10n resource file updates
Reviewed-by: coffeys
Contributed-by: li.jiang@oracle.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.nameexpr);
    98         scan(tree.init);
    99     }
   101     public void visitSkip(JCSkip tree) {
   102     }
   104     public void visitBlock(JCBlock tree) {
   105         scan(tree.stats);
   106     }
   108     public void visitDoLoop(JCDoWhileLoop tree) {
   109         scan(tree.body);
   110         scan(tree.cond);
   111     }
   113     public void visitWhileLoop(JCWhileLoop tree) {
   114         scan(tree.cond);
   115         scan(tree.body);
   116     }
   118     public void visitForLoop(JCForLoop tree) {
   119         scan(tree.init);
   120         scan(tree.cond);
   121         scan(tree.step);
   122         scan(tree.body);
   123     }
   125     public void visitForeachLoop(JCEnhancedForLoop tree) {
   126         scan(tree.var);
   127         scan(tree.expr);
   128         scan(tree.body);
   129     }
   131     public void visitLabelled(JCLabeledStatement tree) {
   132         scan(tree.body);
   133     }
   135     public void visitSwitch(JCSwitch tree) {
   136         scan(tree.selector);
   137         scan(tree.cases);
   138     }
   140     public void visitCase(JCCase tree) {
   141         scan(tree.pat);
   142         scan(tree.stats);
   143     }
   145     public void visitSynchronized(JCSynchronized tree) {
   146         scan(tree.lock);
   147         scan(tree.body);
   148     }
   150     public void visitTry(JCTry tree) {
   151         scan(tree.resources);
   152         scan(tree.body);
   153         scan(tree.catchers);
   154         scan(tree.finalizer);
   155     }
   157     public void visitCatch(JCCatch tree) {
   158         scan(tree.param);
   159         scan(tree.body);
   160     }
   162     public void visitConditional(JCConditional tree) {
   163         scan(tree.cond);
   164         scan(tree.truepart);
   165         scan(tree.falsepart);
   166     }
   168     public void visitIf(JCIf tree) {
   169         scan(tree.cond);
   170         scan(tree.thenpart);
   171         scan(tree.elsepart);
   172     }
   174     public void visitExec(JCExpressionStatement tree) {
   175         scan(tree.expr);
   176     }
   178     public void visitBreak(JCBreak tree) {
   179     }
   181     public void visitContinue(JCContinue tree) {
   182     }
   184     public void visitReturn(JCReturn tree) {
   185         scan(tree.expr);
   186     }
   188     public void visitThrow(JCThrow tree) {
   189         scan(tree.expr);
   190     }
   192     public void visitAssert(JCAssert tree) {
   193         scan(tree.cond);
   194         scan(tree.detail);
   195     }
   197     public void visitApply(JCMethodInvocation tree) {
   198         scan(tree.typeargs);
   199         scan(tree.meth);
   200         scan(tree.args);
   201     }
   203     public void visitNewClass(JCNewClass tree) {
   204         scan(tree.encl);
   205         scan(tree.typeargs);
   206         scan(tree.clazz);
   207         scan(tree.args);
   208         scan(tree.def);
   209     }
   211     public void visitNewArray(JCNewArray tree) {
   212         scan(tree.annotations);
   213         scan(tree.elemtype);
   214         scan(tree.dims);
   215         for (List<JCAnnotation> annos : tree.dimAnnotations)
   216             scan(annos);
   217         scan(tree.elems);
   218     }
   220     public void visitLambda(JCLambda tree) {
   221         scan(tree.body);
   222         scan(tree.params);
   223     }
   225     public void visitParens(JCParens tree) {
   226         scan(tree.expr);
   227     }
   229     public void visitAssign(JCAssign tree) {
   230         scan(tree.lhs);
   231         scan(tree.rhs);
   232     }
   234     public void visitAssignop(JCAssignOp tree) {
   235         scan(tree.lhs);
   236         scan(tree.rhs);
   237     }
   239     public void visitUnary(JCUnary tree) {
   240         scan(tree.arg);
   241     }
   243     public void visitBinary(JCBinary tree) {
   244         scan(tree.lhs);
   245         scan(tree.rhs);
   246     }
   248     public void visitTypeCast(JCTypeCast tree) {
   249         scan(tree.clazz);
   250         scan(tree.expr);
   251     }
   253     public void visitTypeTest(JCInstanceOf tree) {
   254         scan(tree.expr);
   255         scan(tree.clazz);
   256     }
   258     public void visitIndexed(JCArrayAccess tree) {
   259         scan(tree.indexed);
   260         scan(tree.index);
   261     }
   263     public void visitSelect(JCFieldAccess tree) {
   264         scan(tree.selected);
   265     }
   267     public void visitReference(JCMemberReference tree) {
   268         scan(tree.expr);
   269         scan(tree.typeargs);
   270     }
   272     public void visitIdent(JCIdent tree) {
   273     }
   275     public void visitLiteral(JCLiteral tree) {
   276     }
   278     public void visitTypeIdent(JCPrimitiveTypeTree tree) {
   279     }
   281     public void visitTypeArray(JCArrayTypeTree tree) {
   282         scan(tree.elemtype);
   283     }
   285     public void visitTypeApply(JCTypeApply tree) {
   286         scan(tree.clazz);
   287         scan(tree.arguments);
   288     }
   290     public void visitTypeUnion(JCTypeUnion tree) {
   291         scan(tree.alternatives);
   292     }
   294     public void visitTypeIntersection(JCTypeIntersection tree) {
   295         scan(tree.bounds);
   296     }
   298     public void visitTypeParameter(JCTypeParameter tree) {
   299         scan(tree.annotations);
   300         scan(tree.bounds);
   301     }
   303     @Override
   304     public void visitWildcard(JCWildcard tree) {
   305         scan(tree.kind);
   306         if (tree.inner != null)
   307             scan(tree.inner);
   308     }
   310     @Override
   311     public void visitTypeBoundKind(TypeBoundKind that) {
   312     }
   314     public void visitModifiers(JCModifiers tree) {
   315         scan(tree.annotations);
   316     }
   318     public void visitAnnotation(JCAnnotation tree) {
   319         scan(tree.annotationType);
   320         scan(tree.args);
   321     }
   323     public void visitAnnotatedType(JCAnnotatedType tree) {
   324         scan(tree.annotations);
   325         scan(tree.underlyingType);
   326     }
   328     public void visitErroneous(JCErroneous tree) {
   329     }
   331     public void visitLetExpr(LetExpr tree) {
   332         scan(tree.defs);
   333         scan(tree.expr);
   334     }
   336     public void visitTree(JCTree tree) {
   337         Assert.error();
   338     }
   339 }

mercurial