langtools/src/share/classes/com/sun/source/util/TreeScanner.java
author jjg
Wed, 23 Jan 2013 13:27:24 -0800
changeset 15385 ee1eebe7e210
parent 14725 65836e833f59
child 16303 b5dca0b42963
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.source.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.source.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * A TreeVisitor that visits all the child tree nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * To visit nodes of a particular type, just override the
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * corresponding visitXYZ method.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Inside your method, call super.visitXYZ to visit descendant
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * <p>The default implementation of the visitXYZ methods will determine
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * a result as follows:
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * <li>If the node being visited has no children, the result will be null.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * <li>If the node being visited has one child, the result will be the
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * result of calling {@code scan} on that child. The child may be a simple node
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * or itself a list of nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * <li> If the node being visited has more than one child, the result will
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * be determined by calling {@code scan} each child in turn, and then combining the
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * result of each scan after the first with the cumulative result
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * so far, as determined by the {@link #reduce} method. Each child may be either
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * a simple node of a list of nodes. The default behavior of the {@code reduce}
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * method is such that the result of the visitXYZ method will be the result of
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * the last child scanned.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * <p>Here is an example to count the number of identifier nodes in a tree:
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * <pre>
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 11142
diff changeset
    55
 *   class CountIdentifiers extends TreeScanner&lt;Integer,Void&gt; {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *      {@literal @}Override
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *      public Integer visitIdentifier(IdentifierTree node, Void p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *          return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *      }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *      {@literal @}Override
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *      public Integer reduce(Integer r1, Integer r2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *          return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *      }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *   }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * @author Jonathan Gibbons
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
public class TreeScanner<R,P> implements TreeVisitor<R,P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /** Scan a single node.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public R scan(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        return (node == null) ? null : node.accept(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    private R scanAndReduce(Tree node, P p, R r) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        return reduce(scan(node, p), r);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    /** Scan a list of nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    public R scan(Iterable<? extends Tree> nodes, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        R r = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        if (nodes != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
            for (Tree node : nodes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                r = (first ? scan(node, p) : scanAndReduce(node, p, r));
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        return reduce(scan(nodes, p), r);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * Reduces two results into a combined result.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * The default implementation is to return the first parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * The general contract of the method is that it may take any action whatsoever.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    public R reduce(R r1, R r2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        return r1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 * Visitor methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    public R visitCompilationUnit(CompilationUnitTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        R r = scan(node.getPackageAnnotations(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        r = scanAndReduce(node.getPackageName(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        r = scanAndReduce(node.getImports(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        r = scanAndReduce(node.getTypeDecls(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    public R visitImport(ImportTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return scan(node.getQualifiedIdentifier(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public R visitClass(ClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        r = scanAndReduce(node.getTypeParameters(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        r = scanAndReduce(node.getExtendsClause(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        r = scanAndReduce(node.getImplementsClause(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        r = scanAndReduce(node.getMembers(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    public R visitMethod(MethodTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        r = scanAndReduce(node.getReturnType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        r = scanAndReduce(node.getTypeParameters(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        r = scanAndReduce(node.getParameters(), p, r);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   141
        r = scanAndReduce(node.getReceiverParameter(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        r = scanAndReduce(node.getThrows(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        r = scanAndReduce(node.getBody(), p, r);
6597
9367c22c445f 6983239: TreeScanner does not scan default value for method
jjg
parents: 6148
diff changeset
   144
        r = scanAndReduce(node.getDefaultValue(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    public R visitVariable(VariableTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        r = scanAndReduce(node.getInitializer(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public R visitEmptyStatement(EmptyStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    public R visitBlock(BlockTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return scan(node.getStatements(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        R r = scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public R visitWhileLoop(WhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    public R visitForLoop(ForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        R r = scan(node.getInitializer(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        r = scanAndReduce(node.getUpdate(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public R visitLabeledStatement(LabeledStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        return scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    public R visitSwitch(SwitchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        r = scanAndReduce(node.getCases(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    public R visitCase(CaseTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        r = scanAndReduce(node.getStatements(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    public R visitSynchronized(SynchronizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    public R visitTry(TryTree node, P p) {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5520
diff changeset
   213
        R r = scan(node.getResources(), p);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5520
diff changeset
   214
        r = scanAndReduce(node.getBlock(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        r = scanAndReduce(node.getCatches(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        r = scanAndReduce(node.getFinallyBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    public R visitCatch(CatchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        R r = scan(node.getParameter(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        r = scanAndReduce(node.getTrueExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        r = scanAndReduce(node.getFalseExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    public R visitIf(IfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        r = scanAndReduce(node.getThenStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        r = scanAndReduce(node.getElseStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    public R visitExpressionStatement(ExpressionStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    public R visitBreak(BreakTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    public R visitContinue(ContinueTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    public R visitReturn(ReturnTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    public R visitThrow(ThrowTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    public R visitAssert(AssertTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        r = scanAndReduce(node.getDetail(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    public R visitMethodInvocation(MethodInvocationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        R r = scan(node.getTypeArguments(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        r = scanAndReduce(node.getMethodSelect(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    public R visitNewClass(NewClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        R r = scan(node.getEnclosingExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        r = scanAndReduce(node.getIdentifier(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        r = scanAndReduce(node.getClassBody(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    public R visitNewArray(NewArrayTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        r = scanAndReduce(node.getDimensions(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        r = scanAndReduce(node.getInitializers(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
11141
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   289
    public R visitLambdaExpression(LambdaExpressionTree node, P p) {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   290
        R r = scan(node.getParameters(), p);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   291
        r = scanAndReduce(node.getBody(), p, r);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   292
        return r;
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   293
    }
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   294
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    public R visitParenthesized(ParenthesizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    public R visitAssignment(AssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    public R visitUnary(UnaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    public R visitBinary(BinaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        R r = scan(node.getLeftOperand(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        r = scanAndReduce(node.getRightOperand(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    public R visitTypeCast(TypeCastTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    public R visitInstanceOf(InstanceOfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    public R visitArrayAccess(ArrayAccessTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        r = scanAndReduce(node.getIndex(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    public R visitMemberSelect(MemberSelectTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   343
    public R visitMemberReference(MemberReferenceTree node, P p) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   344
        R r = scan(node.getQualifierExpression(), p);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   345
        r = scanAndReduce(node.getTypeArguments(), p, r);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   346
        return r;
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   347
    }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   348
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    public R visitIdentifier(IdentifierTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    public R visitLiteral(LiteralTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    public R visitArrayType(ArrayTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        return scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    public R visitParameterizedType(ParameterizedTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8031
diff changeset
   371
    public R visitUnionType(UnionTypeTree node, P p) {
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 7072
diff changeset
   372
        return scan(node.getTypeAlternatives(), p);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   373
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   374
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   375
    public R visitIntersectionType(IntersectionTypeTree node, P p) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   376
        return scan(node.getBounds(), p);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   377
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   378
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    public R visitTypeParameter(TypeParameterTree node, P p) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   380
        R r = scan(node.getAnnotations(), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   381
        r = scanAndReduce(node.getBounds(), p, r);
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 10
diff changeset
   382
        return r;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    public R visitWildcard(WildcardTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        return scan(node.getBound(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    public R visitModifiers(ModifiersTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        return scan(node.getAnnotations(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    public R visitAnnotation(AnnotationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        R r = scan(node.getAnnotationType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   399
   public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   400
       R r = scan(node.getAnnotations(), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   401
       r = scanAndReduce(node.getUnderlyingType(), p, r);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   402
       return r;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   403
   }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   404
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    public R visitOther(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    public R visitErroneous(ErroneousTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
}