langtools/src/share/classes/com/sun/source/util/TreeScanner.java
author jjg
Tue, 19 Mar 2013 15:13:44 -0700
changeset 16559 e927a4e65b0c
parent 16303 b5dca0b42963
child 17580 6696a7abec02
permissions -rw-r--r--
8010315: doclint errors in javac public API Reviewed-by: darcy
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
 */
16303
b5dca0b42963 8008267: Add @Supported annotation to com.sun.source types
darcy
parents: 15385
diff changeset
    71
@jdk.Supported
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
public class TreeScanner<R,P> implements TreeVisitor<R,P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** Scan a single node.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    public R scan(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        return (node == null) ? null : node.accept(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private R scanAndReduce(Tree node, P p, R r) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        return reduce(scan(node, p), r);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /** Scan a list of nodes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    public R scan(Iterable<? extends Tree> nodes, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        R r = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        if (nodes != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
            boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            for (Tree node : nodes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                r = (first ? scan(node, p) : scanAndReduce(node, p, r));
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    private R scanAndReduce(Iterable<? extends Tree> nodes, P p, R r) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        return reduce(scan(nodes, p), r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * Reduces two results into a combined result.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * The default implementation is to return the first parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * The general contract of the method is that it may take any action whatsoever.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    public R reduce(R r1, R r2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        return r1;
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
/* ***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 * Visitor methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 ****************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public R visitCompilationUnit(CompilationUnitTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        R r = scan(node.getPackageAnnotations(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        r = scanAndReduce(node.getPackageName(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        r = scanAndReduce(node.getImports(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        r = scanAndReduce(node.getTypeDecls(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    public R visitImport(ImportTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        return scan(node.getQualifiedIdentifier(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    public R visitClass(ClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        r = scanAndReduce(node.getTypeParameters(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        r = scanAndReduce(node.getExtendsClause(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        r = scanAndReduce(node.getImplementsClause(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        r = scanAndReduce(node.getMembers(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    public R visitMethod(MethodTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        r = scanAndReduce(node.getReturnType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        r = scanAndReduce(node.getTypeParameters(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        r = scanAndReduce(node.getParameters(), p, r);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   142
        r = scanAndReduce(node.getReceiverParameter(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        r = scanAndReduce(node.getThrows(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        r = scanAndReduce(node.getBody(), p, r);
6597
9367c22c445f 6983239: TreeScanner does not scan default value for method
jjg
parents: 6148
diff changeset
   145
        r = scanAndReduce(node.getDefaultValue(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public R visitVariable(VariableTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        r = scanAndReduce(node.getInitializer(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public R visitEmptyStatement(EmptyStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    public R visitBlock(BlockTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        return scan(node.getStatements(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        R r = scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    public R visitWhileLoop(WhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public R visitForLoop(ForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        R r = scan(node.getInitializer(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        r = scanAndReduce(node.getUpdate(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    public R visitLabeledStatement(LabeledStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        return scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    public R visitSwitch(SwitchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        r = scanAndReduce(node.getCases(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    public R visitCase(CaseTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        r = scanAndReduce(node.getStatements(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    public R visitSynchronized(SynchronizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    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
   214
        R r = scan(node.getResources(), p);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5520
diff changeset
   215
        r = scanAndReduce(node.getBlock(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        r = scanAndReduce(node.getCatches(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        r = scanAndReduce(node.getFinallyBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    public R visitCatch(CatchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        R r = scan(node.getParameter(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        r = scanAndReduce(node.getTrueExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        r = scanAndReduce(node.getFalseExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    public R visitIf(IfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        r = scanAndReduce(node.getThenStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        r = scanAndReduce(node.getElseStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    public R visitExpressionStatement(ExpressionStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    public R visitBreak(BreakTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public R visitContinue(ContinueTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    public R visitReturn(ReturnTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    public R visitThrow(ThrowTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    public R visitAssert(AssertTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        r = scanAndReduce(node.getDetail(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    public R visitMethodInvocation(MethodInvocationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        R r = scan(node.getTypeArguments(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        r = scanAndReduce(node.getMethodSelect(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    public R visitNewClass(NewClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        R r = scan(node.getEnclosingExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        r = scanAndReduce(node.getIdentifier(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        r = scanAndReduce(node.getClassBody(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    public R visitNewArray(NewArrayTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        r = scanAndReduce(node.getDimensions(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        r = scanAndReduce(node.getInitializers(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
11141
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   290
    public R visitLambdaExpression(LambdaExpressionTree node, P p) {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   291
        R r = scan(node.getParameters(), p);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   292
        r = scanAndReduce(node.getBody(), p, r);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   293
        return r;
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   294
    }
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 9300
diff changeset
   295
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    public R visitParenthesized(ParenthesizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    public R visitAssignment(AssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    public R visitUnary(UnaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    public R visitBinary(BinaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        R r = scan(node.getLeftOperand(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        r = scanAndReduce(node.getRightOperand(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    public R visitTypeCast(TypeCastTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    public R visitInstanceOf(InstanceOfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    public R visitArrayAccess(ArrayAccessTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        r = scanAndReduce(node.getIndex(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    public R visitMemberSelect(MemberSelectTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   344
    public R visitMemberReference(MemberReferenceTree node, P p) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   345
        R r = scan(node.getQualifierExpression(), p);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   346
        r = scanAndReduce(node.getTypeArguments(), p, r);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   347
        return r;
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   348
    }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   349
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    public R visitIdentifier(IdentifierTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    public R visitLiteral(LiteralTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    public R visitArrayType(ArrayTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        return scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    public R visitParameterizedType(ParameterizedTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8031
diff changeset
   372
    public R visitUnionType(UnionTypeTree node, P p) {
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 7072
diff changeset
   373
        return scan(node.getTypeAlternatives(), p);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   374
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   375
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   376
    public R visitIntersectionType(IntersectionTypeTree node, P p) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   377
        return scan(node.getBounds(), p);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   378
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 13844
diff changeset
   379
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    public R visitTypeParameter(TypeParameterTree node, P p) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   381
        R r = scan(node.getAnnotations(), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   382
        r = scanAndReduce(node.getBounds(), p, r);
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 10
diff changeset
   383
        return r;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    public R visitWildcard(WildcardTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        return scan(node.getBound(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    public R visitModifiers(ModifiersTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        return scan(node.getAnnotations(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    public R visitAnnotation(AnnotationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        R r = scan(node.getAnnotationType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   400
   public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   401
       R r = scan(node.getAnnotations(), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   402
       r = scanAndReduce(node.getUnderlyingType(), p, r);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   403
       return r;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   404
   }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   405
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    public R visitOther(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    public R visitErroneous(ErroneousTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
}