langtools/src/share/classes/com/sun/source/util/TreeScanner.java
author darcy
Wed, 06 Apr 2011 19:30:57 -0700
changeset 9300 c2de4dd9853b
parent 8031 d5fe2c1cecfc
child 11141 7d112a1ecd0f
permissions -rw-r--r--
7033809: Rename "disjunctive" to "union" in javax.lang.model Reviewed-by: mcimadamore, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
8031
d5fe2c1cecfc 6992999: fully remove JSR 308 from langtools
jjg
parents: 7681
diff changeset
     2
 * Copyright (c) 2005, 2011, 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>
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *   class CountIdentifiers extends TreeScanner<Integer,Void> {
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);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        r = scanAndReduce(node.getThrows(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        r = scanAndReduce(node.getBody(), p, r);
6597
9367c22c445f 6983239: TreeScanner does not scan default value for method
jjg
parents: 6148
diff changeset
   143
        r = scanAndReduce(node.getDefaultValue(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    public R visitVariable(VariableTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        R r = scan(node.getModifiers(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        r = scanAndReduce(node.getInitializer(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    public R visitEmptyStatement(EmptyStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    public R visitBlock(BlockTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        return scan(node.getStatements(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        R r = scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public R visitWhileLoop(WhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    public R visitForLoop(ForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        R r = scan(node.getInitializer(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        r = scanAndReduce(node.getCondition(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        r = scanAndReduce(node.getUpdate(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        r = scanAndReduce(node.getStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public R visitLabeledStatement(LabeledStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        return scan(node.getStatement(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    public R visitSwitch(SwitchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        r = scanAndReduce(node.getCases(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    public R visitCase(CaseTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        r = scanAndReduce(node.getStatements(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    public R visitSynchronized(SynchronizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    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
   212
        R r = scan(node.getResources(), p);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5520
diff changeset
   213
        r = scanAndReduce(node.getBlock(), p, r);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        r = scanAndReduce(node.getCatches(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        r = scanAndReduce(node.getFinallyBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    public R visitCatch(CatchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        R r = scan(node.getParameter(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        r = scanAndReduce(node.getBlock(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        r = scanAndReduce(node.getTrueExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        r = scanAndReduce(node.getFalseExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    public R visitIf(IfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        r = scanAndReduce(node.getThenStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        r = scanAndReduce(node.getElseStatement(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    public R visitExpressionStatement(ExpressionStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    public R visitBreak(BreakTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public R visitContinue(ContinueTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    public R visitReturn(ReturnTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    public R visitThrow(ThrowTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    public R visitAssert(AssertTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        R r = scan(node.getCondition(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        r = scanAndReduce(node.getDetail(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    public R visitMethodInvocation(MethodInvocationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        R r = scan(node.getTypeArguments(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        r = scanAndReduce(node.getMethodSelect(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    public R visitNewClass(NewClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        R r = scan(node.getEnclosingExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        r = scanAndReduce(node.getIdentifier(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        r = scanAndReduce(node.getClassBody(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    public R visitNewArray(NewArrayTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        r = scanAndReduce(node.getDimensions(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        r = scanAndReduce(node.getInitializers(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    public R visitParenthesized(ParenthesizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    public R visitAssignment(AssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        R r = scan(node.getVariable(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
    public R visitUnary(UnaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    public R visitBinary(BinaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        R r = scan(node.getLeftOperand(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        r = scanAndReduce(node.getRightOperand(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    public R visitTypeCast(TypeCastTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        r = scanAndReduce(node.getExpression(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    public R visitInstanceOf(InstanceOfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        r = scanAndReduce(node.getType(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    public R visitArrayAccess(ArrayAccessTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        R r = scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        r = scanAndReduce(node.getIndex(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    public R visitMemberSelect(MemberSelectTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        return scan(node.getExpression(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    public R visitIdentifier(IdentifierTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        return null;
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 visitLiteral(LiteralTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    public R visitArrayType(ArrayTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        return scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    public R visitParameterizedType(ParameterizedTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        R r = scan(node.getType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        r = scanAndReduce(node.getTypeArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8031
diff changeset
   358
    public R visitUnionType(UnionTypeTree node, P p) {
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 7072
diff changeset
   359
        return scan(node.getTypeAlternatives(), p);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   360
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   361
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    public R visitTypeParameter(TypeParameterTree node, P p) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6597
diff changeset
   363
        R r = scan(node.getBounds(), p);
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 10
diff changeset
   364
        return r;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    public R visitWildcard(WildcardTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        return scan(node.getBound(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    public R visitModifiers(ModifiersTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        return scan(node.getAnnotations(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    public R visitAnnotation(AnnotationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        R r = scan(node.getAnnotationType(), p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        r = scanAndReduce(node.getArguments(), p, r);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    public R visitOther(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        return null;
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 visitErroneous(ErroneousTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
}