langtools/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java
author darcy
Wed, 06 Apr 2011 19:30:57 -0700
changeset 9300 c2de4dd9853b
parent 8625 6b51ef804d49
child 10950 e87b50888909
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) 2006, 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.tools.javac.tree;
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
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.ListBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Creates a copy of a tree, using a given TreeMaker.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Names, literal values, etc are shared with the original.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    37
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    38
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    private TreeMaker M;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /** Creates a new instance of TreeCopier */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    public TreeCopier(TreeMaker M) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        this.M = M;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public <T extends JCTree> T copy(T tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        return copy(tree, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    @SuppressWarnings("unchecked")
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public <T extends JCTree> T copy(T tree, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        if (tree == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        return (T) (tree.accept(this, p));
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public <T extends JCTree> List<T> copy(List<T> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        return copy(trees, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    public <T extends JCTree> List<T> copy(List<T> trees, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        if (trees == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        ListBuffer<T> lb = new ListBuffer<T>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        for (T tree: trees)
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            lb.append(copy(tree, p));
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        return lb.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    public JCTree visitAnnotation(AnnotationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        JCAnnotation t = (JCAnnotation) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        JCTree annotationType = copy(t.annotationType, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        List<JCExpression> args = copy(t.args, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        return M.at(t.pos).Annotation(annotationType, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    public JCTree visitAssert(AssertTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        JCAssert t = (JCAssert) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        JCExpression detail = copy(t.detail, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        return M.at(t.pos).Assert(cond, detail);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    public JCTree visitAssignment(AssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        JCAssign t = (JCAssign) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        JCExpression lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        JCExpression rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return M.at(t.pos).Assign(lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        JCAssignOp t = (JCAssignOp) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        JCTree lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        JCTree rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    public JCTree visitBinary(BinaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        JCBinary t = (JCBinary) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        JCExpression lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        JCExpression rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        return M.at(t.pos).Binary(t.getTag(), lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public JCTree visitBlock(BlockTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        JCBlock t = (JCBlock) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        List<JCStatement> stats = copy(t.stats, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        return M.at(t.pos).Block(t.flags, stats);
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 JCTree visitBreak(BreakTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        JCBreak t = (JCBreak) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return M.at(t.pos).Break(t.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    public JCTree visitCase(CaseTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        JCCase t = (JCCase) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        JCExpression pat = copy(t.pat, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        List<JCStatement> stats = copy(t.stats, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return M.at(t.pos).Case(pat, stats);
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 JCTree visitCatch(CatchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        JCCatch t = (JCCatch) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        JCVariableDecl param = copy(t.param, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        return M.at(t.pos).Catch(param, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    public JCTree visitClass(ClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        JCClassDecl t = (JCClassDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        List<JCTypeParameter> typarams = copy(t.typarams, p);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8031
diff changeset
   138
        JCExpression extending = copy(t.extending, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        List<JCExpression> implementing = copy(t.implementing, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        List<JCTree> defs = copy(t.defs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        JCConditional t = (JCConditional) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        JCExpression truepart = copy(t.truepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        JCExpression falsepart = copy(t.falsepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        return M.at(t.pos).Conditional(cond, truepart, falsepart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public JCTree visitContinue(ContinueTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        JCContinue t = (JCContinue) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        return M.at(t.pos).Continue(t.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        JCDoWhileLoop t = (JCDoWhileLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        return M.at(t.pos).DoLoop(body, cond);
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 JCTree visitErroneous(ErroneousTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        JCErroneous t = (JCErroneous) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        List<? extends JCTree> errs = copy(t.errs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        return M.at(t.pos).Erroneous(errs);
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 JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        JCExpressionStatement t = (JCExpressionStatement) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return M.at(t.pos).Exec(expr);
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 JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        JCEnhancedForLoop t = (JCEnhancedForLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        JCVariableDecl var = copy(t.var, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return M.at(t.pos).ForeachLoop(var, expr, body);
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 JCTree visitForLoop(ForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        JCForLoop t = (JCForLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        List<JCStatement> init = copy(t.init, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        List<JCExpressionStatement> step = copy(t.step, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        return M.at(t.pos).ForLoop(init, cond, step, body);
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 JCTree visitIdentifier(IdentifierTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        JCIdent t = (JCIdent) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        return M.at(t.pos).Ident(t.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public JCTree visitIf(IfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        JCIf t = (JCIf) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        JCStatement thenpart = copy(t.thenpart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        JCStatement elsepart = copy(t.elsepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        return M.at(t.pos).If(cond, thenpart, elsepart);
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 JCTree visitImport(ImportTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        JCImport t = (JCImport) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        JCTree qualid = copy(t.qualid, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        return M.at(t.pos).Import(qualid, t.staticImport);
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 JCTree visitArrayAccess(ArrayAccessTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        JCArrayAccess t = (JCArrayAccess) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        JCExpression indexed = copy(t.indexed, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        JCExpression index = copy(t.index, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        return M.at(t.pos).Indexed(indexed, index);
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 JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        JCLabeledStatement t = (JCLabeledStatement) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        return M.at(t.pos).Labelled(t.label, t.body);
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 JCTree visitLiteral(LiteralTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        JCLiteral t = (JCLiteral) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        return M.at(t.pos).Literal(t.typetag, t.value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public JCTree visitMethod(MethodTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        JCMethodDecl t  = (JCMethodDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        JCExpression restype = copy(t.restype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        List<JCTypeParameter> typarams = copy(t.typarams, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        List<JCVariableDecl> params = copy(t.params, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        List<JCExpression> thrown = copy(t.thrown, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        JCExpression defaultValue = copy(t.defaultValue, p);
8031
d5fe2c1cecfc 6992999: fully remove JSR 308 from langtools
jjg
parents: 7681
diff changeset
   239
        return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, params, thrown, body, defaultValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        JCMethodInvocation t = (JCMethodInvocation) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        List<JCExpression> typeargs = copy(t.typeargs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        JCExpression meth = copy(t.meth, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        List<JCExpression> args = copy(t.args, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        return M.at(t.pos).Apply(typeargs, meth, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    public JCTree visitModifiers(ModifiersTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        JCModifiers t = (JCModifiers) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        List<JCAnnotation> annotations = copy(t.annotations, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        return M.at(t.pos).Modifiers(t.flags, annotations);
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 JCTree visitNewArray(NewArrayTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        JCNewArray t = (JCNewArray) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        JCExpression elemtype = copy(t.elemtype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        List<JCExpression> dims = copy(t.dims, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        List<JCExpression> elems = copy(t.elems, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        return M.at(t.pos).NewArray(elemtype, dims, elems);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    public JCTree visitNewClass(NewClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        JCNewClass t = (JCNewClass) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        JCExpression encl = copy(t.encl, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        List<JCExpression> typeargs = copy(t.typeargs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        JCExpression clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        List<JCExpression> args = copy(t.args, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        JCClassDecl def = copy(t.def, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
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 JCTree visitParenthesized(ParenthesizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        JCParens t = (JCParens) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        return M.at(t.pos).Parens(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    public JCTree visitReturn(ReturnTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        JCReturn t = (JCReturn) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        return M.at(t.pos).Return(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    public JCTree visitMemberSelect(MemberSelectTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        JCFieldAccess t = (JCFieldAccess) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        JCExpression selected = copy(t.selected, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        return M.at(t.pos).Select(selected, t.name);
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 JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        JCSkip t = (JCSkip) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        return M.at(t.pos).Skip();
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    public JCTree visitSwitch(SwitchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        JCSwitch t = (JCSwitch) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        JCExpression selector = copy(t.selector, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        List<JCCase> cases = copy(t.cases, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        return M.at(t.pos).Switch(selector, cases);
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 JCTree visitSynchronized(SynchronizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        JCSynchronized t = (JCSynchronized) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        JCExpression lock = copy(t.lock, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        return M.at(t.pos).Synchronized(lock, body);
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 JCTree visitThrow(ThrowTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        JCThrow t = (JCThrow) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        JCTree expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        return M.at(t.pos).Throw(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        JCCompilationUnit t = (JCCompilationUnit) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        List<JCAnnotation> packageAnnotations = copy(t.packageAnnotations, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        JCExpression pid = copy(t.pid, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        List<JCTree> defs = copy(t.defs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        return M.at(t.pos).TopLevel(packageAnnotations, pid, defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    public JCTree visitTry(TryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        JCTry t = (JCTry) node;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   327
        List<JCTree> resources = copy(t.resources, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        List<JCCatch> catchers = copy(t.catchers, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        JCBlock finalizer = copy(t.finalizer, p);
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   331
        return M.at(t.pos).Try(resources, body, catchers, finalizer);
10
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 JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        JCTypeApply t = (JCTypeApply) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        JCExpression clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        List<JCExpression> arguments = copy(t.arguments, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        return M.at(t.pos).TypeApply(clazz, arguments);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   341
    public JCTree visitUnionType(UnionTypeTree node, P p) {
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   342
        JCTypeUnion t = (JCTypeUnion) node;
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 7072
diff changeset
   343
        List<JCExpression> components = copy(t.alternatives, p);
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   344
        return M.at(t.pos).TypeUnion(components);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   345
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   346
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    public JCTree visitArrayType(ArrayTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        JCArrayTypeTree t = (JCArrayTypeTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        JCExpression elemtype = copy(t.elemtype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        return M.at(t.pos).TypeArray(elemtype);
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 JCTree visitTypeCast(TypeCastTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        JCTypeCast t = (JCTypeCast) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        JCTree clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        return M.at(t.pos).TypeCast(clazz, expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        return M.at(t.pos).TypeIdent(t.typetag);
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 JCTree visitTypeParameter(TypeParameterTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        JCTypeParameter t = (JCTypeParameter) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        List<JCExpression> bounds = copy(t.bounds, p);
8031
d5fe2c1cecfc 6992999: fully remove JSR 308 from langtools
jjg
parents: 7681
diff changeset
   368
        return M.at(t.pos).TypeParameter(t.name, bounds);
10
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 JCTree visitInstanceOf(InstanceOfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        JCInstanceOf t = (JCInstanceOf) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        JCTree clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        return M.at(t.pos).TypeTest(expr, clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    public JCTree visitUnary(UnaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        JCUnary t = (JCUnary) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        JCExpression arg = copy(t.arg, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        return M.at(t.pos).Unary(t.getTag(), arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    public JCTree visitVariable(VariableTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        JCVariableDecl t = (JCVariableDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        JCExpression vartype = copy(t.vartype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        JCExpression init = copy(t.init, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        return M.at(t.pos).VarDef(mods, t.name, vartype, init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    public JCTree visitWhileLoop(WhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        JCWhileLoop t = (JCWhileLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        return M.at(t.pos).WhileLoop(cond, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    public JCTree visitWildcard(WildcardTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        JCWildcard t = (JCWildcard) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        JCTree inner = copy(t.inner, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        return M.at(t.pos).Wildcard(kind, inner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    public JCTree visitOther(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        JCTree tree = (JCTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        switch (tree.getTag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            case JCTree.LETEXPR: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
                LetExpr t = (LetExpr) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
                List<JCVariableDecl> defs = copy(t.defs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                JCTree expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                return M.at(t.pos).LetExpr(defs, expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
                throw new AssertionError("unknown tree tag: " + tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
}