langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 33707 d74fef6b01e0
child 37848 3c8ff4204d2d
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
     2
 * Copyright (c) 2006, 2015, 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.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    30
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    31
import com.sun.tools.javac.util.DefinedBy.Api;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.ListBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Creates a copy of a tree, using a given TreeMaker.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * Names, literal values, etc are shared with the original.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    39
 *  <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
    40
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    private TreeMaker M;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /** Creates a new instance of TreeCopier */
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    public TreeCopier(TreeMaker M) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        this.M = M;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    public <T extends JCTree> T copy(T tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        return copy(tree, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    @SuppressWarnings("unchecked")
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    public <T extends JCTree> T copy(T tree, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        if (tree == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        return (T) (tree.accept(this, p));
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public <T extends JCTree> List<T> copy(List<T> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        return copy(trees, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public <T extends JCTree> List<T> copy(List<T> trees, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        if (trees == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
            return null;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 20243
diff changeset
    70
        ListBuffer<T> lb = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        for (T tree: trees)
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            lb.append(copy(tree, p));
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        return lb.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    76
    @DefinedBy(Api.COMPILER_TREE)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    77
    public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    78
        JCAnnotatedType t = (JCAnnotatedType) node;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    79
        List<JCAnnotation> annotations = copy(t.annotations, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    80
        JCExpression underlyingType = copy(t.underlyingType, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    81
        return M.at(t.pos).AnnotatedType(annotations, underlyingType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    82
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    83
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    84
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    public JCTree visitAnnotation(AnnotationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        JCAnnotation t = (JCAnnotation) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        JCTree annotationType = copy(t.annotationType, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        List<JCExpression> args = copy(t.args, p);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    89
        if (t.getKind() == Tree.Kind.TYPE_ANNOTATION) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    90
            JCAnnotation newTA = M.at(t.pos).TypeAnnotation(annotationType, args);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    91
            newTA.attribute = t.attribute;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    92
            return newTA;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    93
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    94
            JCAnnotation newT = M.at(t.pos).Annotation(annotationType, args);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    95
            newT.attribute = t.attribute;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    96
            return newT;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
    97
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   100
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public JCTree visitAssert(AssertTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        JCAssert t = (JCAssert) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        JCExpression detail = copy(t.detail, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        return M.at(t.pos).Assert(cond, detail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   108
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public JCTree visitAssignment(AssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        JCAssign t = (JCAssign) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        JCExpression lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        JCExpression rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        return M.at(t.pos).Assign(lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   116
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        JCAssignOp t = (JCAssignOp) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        JCTree lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        JCTree rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   124
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public JCTree visitBinary(BinaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        JCBinary t = (JCBinary) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        JCExpression lhs = copy(t.lhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        JCExpression rhs = copy(t.rhs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        return M.at(t.pos).Binary(t.getTag(), lhs, rhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   132
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    public JCTree visitBlock(BlockTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        JCBlock t = (JCBlock) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        List<JCStatement> stats = copy(t.stats, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        return M.at(t.pos).Block(t.flags, stats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   139
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    public JCTree visitBreak(BreakTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        JCBreak t = (JCBreak) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        return M.at(t.pos).Break(t.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   145
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    public JCTree visitCase(CaseTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        JCCase t = (JCCase) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        JCExpression pat = copy(t.pat, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        List<JCStatement> stats = copy(t.stats, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        return M.at(t.pos).Case(pat, stats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   153
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    public JCTree visitCatch(CatchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        JCCatch t = (JCCatch) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        JCVariableDecl param = copy(t.param, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        return M.at(t.pos).Catch(param, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   161
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public JCTree visitClass(ClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        JCClassDecl t = (JCClassDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        List<JCTypeParameter> typarams = copy(t.typarams, p);
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8031
diff changeset
   166
        JCExpression extending = copy(t.extending, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        List<JCExpression> implementing = copy(t.implementing, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        List<JCTree> defs = copy(t.defs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   172
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        JCConditional t = (JCConditional) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        JCExpression truepart = copy(t.truepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        JCExpression falsepart = copy(t.falsepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        return M.at(t.pos).Conditional(cond, truepart, falsepart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   181
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    public JCTree visitContinue(ContinueTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        JCContinue t = (JCContinue) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        return M.at(t.pos).Continue(t.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   187
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        JCDoWhileLoop t = (JCDoWhileLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        return M.at(t.pos).DoLoop(body, cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   195
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    public JCTree visitErroneous(ErroneousTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        JCErroneous t = (JCErroneous) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        List<? extends JCTree> errs = copy(t.errs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        return M.at(t.pos).Erroneous(errs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   202
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        JCExpressionStatement t = (JCExpressionStatement) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        return M.at(t.pos).Exec(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   209
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        JCEnhancedForLoop t = (JCEnhancedForLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        JCVariableDecl var = copy(t.var, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        return M.at(t.pos).ForeachLoop(var, expr, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   218
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    public JCTree visitForLoop(ForLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        JCForLoop t = (JCForLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        List<JCStatement> init = copy(t.init, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        List<JCExpressionStatement> step = copy(t.step, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        return M.at(t.pos).ForLoop(init, cond, step, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   228
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    public JCTree visitIdentifier(IdentifierTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        JCIdent t = (JCIdent) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        return M.at(t.pos).Ident(t.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   234
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    public JCTree visitIf(IfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        JCIf t = (JCIf) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        JCStatement thenpart = copy(t.thenpart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        JCStatement elsepart = copy(t.elsepart, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        return M.at(t.pos).If(cond, thenpart, elsepart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   243
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    public JCTree visitImport(ImportTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        JCImport t = (JCImport) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        JCTree qualid = copy(t.qualid, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        return M.at(t.pos).Import(qualid, t.staticImport);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   250
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    public JCTree visitArrayAccess(ArrayAccessTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        JCArrayAccess t = (JCArrayAccess) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        JCExpression indexed = copy(t.indexed, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        JCExpression index = copy(t.index, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        return M.at(t.pos).Indexed(indexed, index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   258
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    public JCTree visitLabeledStatement(LabeledStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        JCLabeledStatement t = (JCLabeledStatement) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        JCStatement body = copy(t.body, p);
20243
21740b37e9aa 8025110: TreeCopier does not correctly copy LabeledStatementTree
jjg
parents: 17807
diff changeset
   262
        return M.at(t.pos).Labelled(t.label, body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   265
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    public JCTree visitLiteral(LiteralTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        JCLiteral t = (JCLiteral) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        return M.at(t.pos).Literal(t.typetag, t.value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   271
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    public JCTree visitMethod(MethodTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        JCMethodDecl t  = (JCMethodDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        JCExpression restype = copy(t.restype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        List<JCTypeParameter> typarams = copy(t.typarams, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        List<JCVariableDecl> params = copy(t.params, p);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   278
        JCVariableDecl recvparam = copy(t.recvparam, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        List<JCExpression> thrown = copy(t.thrown, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        JCExpression defaultValue = copy(t.defaultValue, p);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   282
        return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   285
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    public JCTree visitMethodInvocation(MethodInvocationTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        JCMethodInvocation t = (JCMethodInvocation) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        List<JCExpression> typeargs = copy(t.typeargs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        JCExpression meth = copy(t.meth, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        List<JCExpression> args = copy(t.args, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        return M.at(t.pos).Apply(typeargs, meth, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   294
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    public JCTree visitModifiers(ModifiersTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        JCModifiers t = (JCModifiers) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        List<JCAnnotation> annotations = copy(t.annotations, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        return M.at(t.pos).Modifiers(t.flags, annotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   301
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    public JCTree visitNewArray(NewArrayTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        JCNewArray t = (JCNewArray) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        JCExpression elemtype = copy(t.elemtype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        List<JCExpression> dims = copy(t.dims, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        List<JCExpression> elems = copy(t.elems, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        return M.at(t.pos).NewArray(elemtype, dims, elems);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   310
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    public JCTree visitNewClass(NewClassTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        JCNewClass t = (JCNewClass) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        JCExpression encl = copy(t.encl, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        List<JCExpression> typeargs = copy(t.typeargs, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        JCExpression clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        List<JCExpression> args = copy(t.args, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        JCClassDecl def = copy(t.def, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   321
    @DefinedBy(Api.COMPILER_TREE)
11141
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   322
    public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   323
        JCLambda t = (JCLambda) node;
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   324
        List<JCVariableDecl> params = copy(t.params, p);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   325
        JCTree body = copy(t.body, p);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   326
        return M.at(t.pos).Lambda(params, body);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   327
    }
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
   328
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   329
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    public JCTree visitParenthesized(ParenthesizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        JCParens t = (JCParens) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        return M.at(t.pos).Parens(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   336
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    public JCTree visitReturn(ReturnTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        JCReturn t = (JCReturn) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        return M.at(t.pos).Return(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   343
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    public JCTree visitMemberSelect(MemberSelectTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        JCFieldAccess t = (JCFieldAccess) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        JCExpression selected = copy(t.selected, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        return M.at(t.pos).Select(selected, t.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   350
    @DefinedBy(Api.COMPILER_TREE)
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   351
    public JCTree visitMemberReference(MemberReferenceTree node, P p) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   352
        JCMemberReference t = (JCMemberReference) node;
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   353
        JCExpression expr = copy(t.expr, p);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   354
        List<JCExpression> typeargs = copy(t.typeargs, p);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   355
        return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   356
    }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
   357
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   358
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    public JCTree visitEmptyStatement(EmptyStatementTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        JCSkip t = (JCSkip) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        return M.at(t.pos).Skip();
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   364
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    public JCTree visitSwitch(SwitchTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        JCSwitch t = (JCSwitch) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        JCExpression selector = copy(t.selector, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        List<JCCase> cases = copy(t.cases, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        return M.at(t.pos).Switch(selector, cases);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   372
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    public JCTree visitSynchronized(SynchronizedTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        JCSynchronized t = (JCSynchronized) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        JCExpression lock = copy(t.lock, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        return M.at(t.pos).Synchronized(lock, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   380
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    public JCTree visitThrow(ThrowTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        JCThrow t = (JCThrow) node;
17807
36cff8c58cdf 7030476: Fix conflicting use of JCTree/JCExpression
vromero
parents: 17578
diff changeset
   383
        JCExpression expr = copy(t.expr, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        return M.at(t.pos).Throw(expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   387
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    public JCTree visitCompilationUnit(CompilationUnitTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        JCCompilationUnit t = (JCCompilationUnit) node;
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   390
        List<JCTree> defs = copy(t.defs, p);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   391
        return M.at(t.pos).TopLevel(defs);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   392
    }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   393
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   394
    @DefinedBy(Api.COMPILER_TREE)
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   395
    public JCTree visitPackage(PackageTree node, P p) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   396
        JCPackageDecl t = (JCPackageDecl) node;
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   397
        List<JCAnnotation> annotations = copy(t.annotations, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        JCExpression pid = copy(t.pid, p);
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 22163
diff changeset
   399
        return M.at(t.pos).PackageDecl(annotations, pid);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   402
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    public JCTree visitTry(TryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        JCTry t = (JCTry) node;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   405
        List<JCTree> resources = copy(t.resources, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        JCBlock body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        List<JCCatch> catchers = copy(t.catchers, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        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
   409
        return M.at(t.pos).Try(resources, body, catchers, finalizer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   412
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        JCTypeApply t = (JCTypeApply) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        JCExpression clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        List<JCExpression> arguments = copy(t.arguments, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        return M.at(t.pos).TypeApply(clazz, arguments);
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   420
    @DefinedBy(Api.COMPILER_TREE)
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   421
    public JCTree visitUnionType(UnionTypeTree node, P p) {
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   422
        JCTypeUnion t = (JCTypeUnion) node;
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 7072
diff changeset
   423
        List<JCExpression> components = copy(t.alternatives, p);
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8625
diff changeset
   424
        return M.at(t.pos).TypeUnion(components);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   425
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   426
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   427
    @DefinedBy(Api.COMPILER_TREE)
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   428
    public JCTree visitIntersectionType(IntersectionTypeTree node, P p) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   429
        JCTypeIntersection t = (JCTypeIntersection) node;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   430
        List<JCExpression> bounds = copy(t.bounds, p);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   431
        return M.at(t.pos).TypeIntersection(bounds);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   432
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 11142
diff changeset
   433
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   434
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    public JCTree visitArrayType(ArrayTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        JCArrayTypeTree t = (JCArrayTypeTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        JCExpression elemtype = copy(t.elemtype, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        return M.at(t.pos).TypeArray(elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   441
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    public JCTree visitTypeCast(TypeCastTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        JCTypeCast t = (JCTypeCast) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        JCTree clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        return M.at(t.pos).TypeCast(clazz, expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   449
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        return M.at(t.pos).TypeIdent(t.typetag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   455
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    public JCTree visitTypeParameter(TypeParameterTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        JCTypeParameter t = (JCTypeParameter) node;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   458
        List<JCAnnotation> annos = copy(t.annotations, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        List<JCExpression> bounds = copy(t.bounds, p);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14725
diff changeset
   460
        return M.at(t.pos).TypeParameter(t.name, bounds, annos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   463
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
    public JCTree visitInstanceOf(InstanceOfTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        JCInstanceOf t = (JCInstanceOf) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        JCExpression expr = copy(t.expr, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        JCTree clazz = copy(t.clazz, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        return M.at(t.pos).TypeTest(expr, clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   471
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    public JCTree visitUnary(UnaryTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        JCUnary t = (JCUnary) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        JCExpression arg = copy(t.arg, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        return M.at(t.pos).Unary(t.getTag(), arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   478
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    public JCTree visitVariable(VariableTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        JCVariableDecl t = (JCVariableDecl) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        JCModifiers mods = copy(t.mods, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        JCExpression vartype = copy(t.vartype, p);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   483
        if (t.nameexpr == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   484
            JCExpression init = copy(t.init, p);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   485
            return M.at(t.pos).VarDef(mods, t.name, vartype, init);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   486
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   487
            JCExpression nameexpr = copy(t.nameexpr, p);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   488
            return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   489
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   492
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    public JCTree visitWhileLoop(WhileLoopTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        JCWhileLoop t = (JCWhileLoop) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        JCStatement body = copy(t.body, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        JCExpression cond = copy(t.cond, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        return M.at(t.pos).WhileLoop(cond, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   500
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    public JCTree visitWildcard(WildcardTree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        JCWildcard t = (JCWildcard) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        JCTree inner = copy(t.inner, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        return M.at(t.pos).Wildcard(kind, inner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   508
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   509
    public JCTree visitModule(ModuleTree node, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   510
        JCModuleDecl t = (JCModuleDecl) node;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   511
        JCExpression qualId = copy(t.qualId);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   512
        List<JCDirective> directives = copy(t.directives);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   513
        return M.at(t.pos).ModuleDef(qualId, directives);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   514
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   515
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   516
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   517
    public JCExports visitExports(ExportsTree node, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   518
        JCExports t = (JCExports) node;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   519
        JCExpression qualId = copy(t.qualid, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   520
        List<JCExpression> moduleNames = copy(t.moduleNames, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   521
        return M.at(t.pos).Exports(qualId, moduleNames);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   522
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   523
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   524
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   525
    public JCProvides visitProvides(ProvidesTree node, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   526
        JCProvides t = (JCProvides) node;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   527
        JCExpression serviceName = copy(t.serviceName, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   528
        JCExpression implName = copy(t.implName, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   529
        return M.at(t.pos).Provides(serviceName, implName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   530
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   531
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   532
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   533
    public JCRequires visitRequires(RequiresTree node, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   534
        JCRequires t = (JCRequires) node;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   535
        JCExpression moduleName = copy(t.moduleName, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   536
        return M.at(t.pos).Requires(t.isPublic, moduleName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   537
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   538
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   539
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   540
    public JCUses visitUses(UsesTree node, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   541
        JCUses t = (JCUses) node;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   542
        JCExpression serviceName = copy(t.qualid, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   543
        return M.at(t.pos).Uses(serviceName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   544
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 33707
diff changeset
   545
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   546
    @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    public JCTree visitOther(Tree node, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        JCTree tree = (JCTree) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        switch (tree.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   550
            case LETEXPR: {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
                LetExpr t = (LetExpr) node;
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
                List<JCVariableDecl> defs = copy(t.defs, p);
33707
d74fef6b01e0 8141639: Signatures in Lower could be made tighter by using JCExpression instead of JCTree
mcimadamore
parents: 26266
diff changeset
   553
                JCExpression expr = copy(t.expr, p);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                return M.at(t.pos).LetExpr(defs, expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                throw new AssertionError("unknown tree tag: " + tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
}