langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 25874 83c19f00452c
child 39091 40820960fdb9
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: 25874
diff changeset
     2
 * Copyright (c) 1999, 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 java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
    30
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
    31
import com.sun.tools.javac.code.*;
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
    32
import com.sun.tools.javac.tree.JCTree.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
    36
import static com.sun.tools.javac.code.Flags.ANNOTATION;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
    37
import static com.sun.tools.javac.tree.JCTree.Tag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/** Prints out a tree as an indented Java source program.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    41
 *  <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
    42
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class Pretty extends JCTree.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    public Pretty(Writer out, boolean sourceOutput) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        this.out = out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
        this.sourceOutput = sourceOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** Set when we are producing source output.  If we're not
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     *  producing source output, we can sometimes give more detail in
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     *  the output even though that detail would not be valid java
4413
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
    56
     *  source.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    private final boolean sourceOutput;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /** The output stream on which trees are printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    Writer out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /** Indentation width (can be reassigned from outside).
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    public int width = 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /** The current left margin.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    int lmargin = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /** The enclosing class name.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    Name enclClassName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
    76
    /** A table mapping trees to their documentation comments
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *  (can be null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
    79
    DocCommentTable docComments = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    81
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    82
     * A string sequence to be used when Pretty output should be constrained
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    83
     * to fit into a given size
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    84
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    85
    private final static String trimSequence = "[...]";
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
    86
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    87
    /**
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    88
     * Max number of chars to be generated when output should fit into a single line
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    89
     */
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    90
    private final static int PREFERRED_LENGTH = 20;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    91
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** Align code to be indented to left margin.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    void align() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        for (int i = 0; i < lmargin; i++) out.write(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    /** Increase left margin by indentation width.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    void indent() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        lmargin = lmargin + width;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    /** Decrease left margin by indentation width.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    void undent() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        lmargin = lmargin - width;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /** Enter a new precedence level. Emit a `(' if new precedence level
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     *  is less than precedence level so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     *  @param contextPrec    The precedence level in force so far.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     *  @param ownPrec        The new precedence level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    void open(int contextPrec, int ownPrec) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        if (ownPrec < contextPrec) out.write("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** Leave precedence level. Emit a `(' if inner precedence level
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     *  is less than precedence level we revert to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *  @param contextPrec    The precedence level we revert to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     *  @param ownPrec        The inner precedence level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    void close(int contextPrec, int ownPrec) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        if (ownPrec < contextPrec) out.write(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /** Print string, replacing all non-ascii character with unicode escapes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    public void print(Object s) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        out.write(Convert.escapeUnicode(s.toString()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /** Print new line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    public void println() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        out.write(lineSep);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   140
    public static String toSimpleString(JCTree tree) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   141
        return toSimpleString(tree, PREFERRED_LENGTH);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   142
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   143
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   144
    public static String toSimpleString(JCTree tree, int maxLength) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   145
        StringWriter s = new StringWriter();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   146
        try {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   147
            new Pretty(s, false).printExpr(tree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   148
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   149
        catch (IOException e) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   150
            // should never happen, because StringWriter is defined
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   151
            // never to throw any IOExceptions
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   152
            throw new AssertionError(e);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   153
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   154
        //we need to (i) replace all line terminators with a space and (ii) remove
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   155
        //occurrences of 'missing' in the Pretty output (generated when types are missing)
15044
b3a4a1002b19 8006033: bug in Pretty.toSimpleString
jjg
parents: 14725
diff changeset
   156
        String res = s.toString().trim().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", "");
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   157
        if (res.length() < maxLength) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   158
            return res;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   159
        } else {
15044
b3a4a1002b19 8006033: bug in Pretty.toSimpleString
jjg
parents: 14725
diff changeset
   160
            int head = (maxLength - trimSequence.length()) * 2 / 3;
b3a4a1002b19 8006033: bug in Pretty.toSimpleString
jjg
parents: 14725
diff changeset
   161
            int tail = maxLength - trimSequence.length() - head;
b3a4a1002b19 8006033: bug in Pretty.toSimpleString
jjg
parents: 14725
diff changeset
   162
            return res.substring(0, head) + trimSequence + res.substring(res.length() - tail);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   163
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   164
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13844
diff changeset
   165
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    String lineSep = System.getProperty("line.separator");
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /**************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * Traversal methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    /** Exception to propogate IOException through visitXXX methods */
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    private static class UncheckedIOException extends Error {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        static final long serialVersionUID = -4032692679158424751L;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        UncheckedIOException(IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            super(e.getMessage(), e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /** Visitor argument: the current precedence level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    int prec;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /** Visitor method: print expression tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *  @param prec  The current precedence level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public void printExpr(JCTree tree, int prec) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        int prevPrec = this.prec;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            this.prec = prec;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            if (tree == null) print("/*missing*/");
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        } catch (UncheckedIOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            IOException e = new IOException(ex.getMessage());
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            e.initCause(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            throw e;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            this.prec = prevPrec;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    /** Derived visitor method: print expression tree at minimum precedence level
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     *  for expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    public void printExpr(JCTree tree) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        printExpr(tree, TreeInfo.noPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    /** Derived visitor method: print statement tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    public void printStat(JCTree tree) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        printExpr(tree, TreeInfo.notExpression);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /** Derived visitor method: print list of expression trees, separated by given string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     *  @param sep the separator string
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    public <T extends JCTree> void printExprs(List<T> trees, String sep) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        if (trees.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            printExpr(trees.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            for (List<T> l = trees.tail; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                print(sep);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                printExpr(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    /** Derived visitor method: print list of expression trees, separated by commas.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    public <T extends JCTree> void printExprs(List<T> trees) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        printExprs(trees, ", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    /** Derived visitor method: print list of statements, each on a separate line.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    public void printStats(List<? extends JCTree> trees) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /** Print a set of modifiers.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    public void printFlags(long flags) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        print(TreeInfo.flagNames(flags));
14267
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14258
diff changeset
   251
        if ((flags & ExtendedStandardFlags) != 0) print(" ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        if ((flags & ANNOTATION) != 0) print("@");
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    public void printAnnotations(List<JCAnnotation> trees) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   263
    public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   264
        for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   265
            printExpr(l.head);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   266
            print(" ");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   267
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   268
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   269
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /** Print documentation comment, if it exists
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *  @param tree    The tree for which a documentation comment should be printed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    public void printDocComment(JCTree tree) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        if (docComments != null) {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
   275
            String dc = docComments.getCommentText(tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            if (dc != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                print("/**"); println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                int pos = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                int endpos = lineEndPos(dc, pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                while (pos < dc.length()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                    align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                    print(" *");
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                    if (pos < dc.length() && dc.charAt(pos) > ' ') print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    print(dc.substring(pos, endpos)); println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                    pos = endpos + 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                    endpos = lineEndPos(dc, pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                align(); print(" */"); println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    static int lineEndPos(String s, int start) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        int pos = s.indexOf('\n', start);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        if (pos < 0) pos = s.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13077
diff changeset
   300
    /** If type parameter list is non-empty, print it enclosed in
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13077
diff changeset
   301
     *  {@literal "<...>"} brackets.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    public void printTypeParameters(List<JCTypeParameter> trees) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        if (trees.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            print("<");
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            printExprs(trees);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            print(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    /** Print a block.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    public void printBlock(List<? extends JCTree> stats) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        print("{");
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        indent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        printStats(stats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        undent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        print("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    /** Print a block.
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    public void printEnumBody(List<JCTree> stats) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        print("{");
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        indent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            if (isEnumerator(l.head)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                if (!first) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                    print(",");
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                    println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            if (!isEnumerator(l.head)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        undent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        print("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /** Is the given tree an enumerator definition? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    boolean isEnumerator(JCTree t) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   357
        return t.hasTag(VARDEF) && (((JCVariableDecl) t).mods.flags & ENUM) != 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    /** Print unit consisting of package clause and import statements in toplevel,
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     *  followed by class definition. if class definition == null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     *  print all definitions in toplevel.
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     *  @param tree     The toplevel tree
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
     *  @param cdef     The class definition, which is assumed to be part of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
     *                  toplevel tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        docComments = tree.docComments;
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        printDocComment(tree);
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   370
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        boolean firstImport = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        for (List<JCTree> l = tree.defs;
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   373
             l.nonEmpty() &&
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   374
                 (cdef == null ||
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   375
                  l.head.hasTag(IMPORT) || l.head.hasTag(PACKAGEDEF));
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   376
             l = l.tail) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   377
            if (l.head.hasTag(IMPORT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                JCImport imp = (JCImport)l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
                Name name = TreeInfo.name(imp.qualid);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   380
                if (name == name.table.names.asterisk ||
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                        cdef == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                        isUsed(TreeInfo.symbol(imp.qualid), cdef)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                    if (firstImport) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
                        firstImport = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
                        println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                    printStat(imp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        if (cdef != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
            printStat(cdef);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    boolean isUsed(final Symbol t, JCTree cdef) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        class UsedVisitor extends TreeScanner {
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            public void scan(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                if (tree!=null && !result) tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            boolean result = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
                if (tree.sym == t) result = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        UsedVisitor v = new UsedVisitor();
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        v.scan(cdef);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        return v.result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    /**************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     * Visitor methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    public void visitTopLevel(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            printUnit(tree, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
24069
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   426
    public void visitPackageDef(JCPackageDecl tree) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   427
        try {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   428
            printDocComment(tree);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   429
            printAnnotations(tree.annotations);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   430
            if (tree.pid != null) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   431
                print("package ");
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   432
                printExpr(tree.pid);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   433
                print(";");
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   434
                println();
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   435
            }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   436
        } catch (IOException e) {
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   437
            throw new UncheckedIOException(e);
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   438
        }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   439
    }
dfb8f11542fc 8034245: Refactor TopLevel tree node.
pgovereau
parents: 21004
diff changeset
   440
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   441
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   442
    public void visitModuleDef(JCModuleDecl tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   443
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   444
            print("module ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   445
            printExpr(tree.qualId);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   446
            if (tree.directives == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   447
                print(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   448
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   449
                printBlock(tree.directives);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   450
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   451
            println();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   452
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   453
            throw new UncheckedIOException(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   454
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   455
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   456
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   457
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   458
    public void visitExports(JCExports tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   459
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   460
            print("exports ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   461
            printExpr(tree.qualid);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   462
            if (tree.moduleNames != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   463
                print(" to ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   464
                printExprs(tree.moduleNames);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   465
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   466
            print(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   467
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   468
            throw new UncheckedIOException(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   469
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   470
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   471
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   472
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   473
    public void visitProvides(JCProvides tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   474
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   475
            print("provides ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   476
            printExpr(tree.serviceName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   477
            print(" with ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   478
            printExpr(tree.implName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   479
            print(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   480
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   481
            throw new UncheckedIOException(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   482
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   483
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   484
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   485
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   486
    public void visitRequires(JCRequires tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   487
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   488
            print("requires ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   489
            if (tree.isPublic)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   490
                print("public ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   491
            printExpr(tree.moduleName);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   492
            print(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   493
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   494
            throw new UncheckedIOException(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   495
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   496
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   497
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   498
    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   499
    public void visitUses(JCUses tree) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   500
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   501
            print("uses ");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   502
            printExpr(tree.qualid);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   503
            print(";");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   504
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   505
            throw new UncheckedIOException(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   506
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   507
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
   508
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    public void visitImport(JCImport tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
            print("import ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            if (tree.staticImport) print("static ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            printExpr(tree.qualid);
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
    public void visitClassDef(JCClassDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            println(); align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            printDocComment(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            printAnnotations(tree.mods.annotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            printFlags(tree.mods.flags & ~INTERFACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            Name enclClassNamePrev = enclClassName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            enclClassName = tree.name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
            if ((tree.mods.flags & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
                print("interface " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
                printTypeParameters(tree.typarams);
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                if (tree.implementing.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                    print(" extends ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                    printExprs(tree.implementing);
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                if ((tree.mods.flags & ENUM) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                    print("enum " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
                    print("class " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                printTypeParameters(tree.typarams);
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
                if (tree.extending != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
                    print(" extends ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                    printExpr(tree.extending);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
                if (tree.implementing.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                    print(" implements ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                    printExprs(tree.implementing);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            if ((tree.mods.flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                printEnumBody(tree.defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                printBlock(tree.defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
            enclClassName = enclClassNamePrev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    public void visitMethodDef(JCMethodDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            // when producing source output, omit anonymous constructors
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   566
            if (tree.name == tree.name.table.names.init &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
                    enclClassName == null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
                    sourceOutput) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            println(); align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
            printDocComment(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
            printExpr(tree.mods);
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
            printTypeParameters(tree.typarams);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   573
            if (tree.name == tree.name.table.names.init) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
                print(enclClassName != null ? enclClassName : tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
                printExpr(tree.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                print(" " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
            print("(");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   580
            if (tree.recvparam!=null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   581
                printExpr(tree.recvparam);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   582
                if (tree.params.size() > 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   583
                    print(", ");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   584
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   585
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            printExprs(tree.params);
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            if (tree.thrown.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
                print(" throws ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
                printExprs(tree.thrown);
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            }
4696
45b45d9c96dd 6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents: 4413
diff changeset
   592
            if (tree.defaultValue != null) {
45b45d9c96dd 6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents: 4413
diff changeset
   593
                print(" default ");
45b45d9c96dd 6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents: 4413
diff changeset
   594
                printExpr(tree.defaultValue);
45b45d9c96dd 6665791: com.sun.source.tree.MethodTree.toString() does not output default values
jjg
parents: 4413
diff changeset
   595
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            if (tree.body != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
                print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
    public void visitVarDef(JCVariableDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        try {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 11142
diff changeset
   609
            if (docComments != null && docComments.hasComment(tree)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                println(); align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            printDocComment(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
            if ((tree.mods.flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                print("/*public static final*/ ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                print(tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
                if (tree.init != null) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   617
                    if (sourceOutput && tree.init.hasTag(NEWCLASS)) {
4413
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   618
                        print(" /*enum*/ ");
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   619
                        JCNewClass init = (JCNewClass) tree.init;
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   620
                        if (init.args != null && init.args.nonEmpty()) {
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   621
                            print("(");
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   622
                            print(init.args);
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   623
                            print(")");
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   624
                        }
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   625
                        if (init.def != null && init.def.defs != null) {
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   626
                            print(" ");
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   627
                            printBlock(init.def.defs);
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   628
                        }
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   629
                        return;
2ae470f0b492 6902720: javac pretty printer does not handle enums correctly
jjg
parents: 3149
diff changeset
   630
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                    print(" /* = ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
                    printExpr(tree.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
                    print(" */");
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                printExpr(tree.mods);
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                if ((tree.mods.flags & VARARGS) != 0) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   638
                    JCTree vartype = tree.vartype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   639
                    List<JCAnnotation> tas = null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   640
                    if (vartype instanceof JCAnnotatedType) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   641
                        tas = ((JCAnnotatedType)vartype).annotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   642
                        vartype = ((JCAnnotatedType)vartype).underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   643
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   644
                    printExpr(((JCArrayTypeTree) vartype).elemtype);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   645
                    if (tas != null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   646
                        print(' ');
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
   647
                        printTypeAnnotations(tas);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   648
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                    print("... " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
                    printExpr(tree.vartype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                    print(" " + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
                if (tree.init != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                    print(" = ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                    printExpr(tree.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
                if (prec == TreeInfo.notExpression) print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
    public void visitSkip(JCSkip tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
    public void visitBlock(JCBlock tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
            printFlags(tree.flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
            printBlock(tree.stats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
    public void visitDoLoop(JCDoWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            print("do ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
            align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
            print(" while ");
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   688
            if (tree.cond.hasTag(PARENS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
                print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
    public void visitWhileLoop(JCWhileLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
            print("while ");
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   704
            if (tree.cond.hasTag(PARENS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
                print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
                print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
            print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
    public void visitForLoop(JCForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
            print("for (");
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
            if (tree.init.nonEmpty()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   722
                if (tree.init.head.hasTag(VARDEF)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                    printExpr(tree.init.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
                    for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
                        JCVariableDecl vdef = (JCVariableDecl)l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
                        print(", " + vdef.name + " = ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
                        printExpr(vdef.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
                    printExprs(tree.init);
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
            print("; ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            if (tree.cond != null) printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            print("; ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            printExprs(tree.step);
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            print(") ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
    public void visitForeachLoop(JCEnhancedForLoop tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
            print("for (");
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
            printExpr(tree.var);
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
            print(" : ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
            printExpr(tree.expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
            print(") ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
    public void visitLabelled(JCLabeledStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            print(tree.label + ": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
    public void visitSwitch(JCSwitch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
            print("switch ");
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   769
            if (tree.selector.hasTag(PARENS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
                printExpr(tree.selector);
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
                print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
                printExpr(tree.selector);
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
                print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            print(" {");
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            printStats(tree.cases);
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
            align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            print("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
    public void visitCase(JCCase tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
            if (tree.pat == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
                print("default");
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
                print("case ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
                printExpr(tree.pat);
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            print(": ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
            indent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            printStats(tree.stats);
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            undent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
            align();
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
    public void visitSynchronized(JCSynchronized tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            print("synchronized ");
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   808
            if (tree.lock.hasTag(PARENS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                printExpr(tree.lock);
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
                print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
                printExpr(tree.lock);
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
                print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
    public void visitTry(JCTry tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            print("try ");
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   825
            if (tree.resources.nonEmpty()) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   826
                print("(");
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   827
                boolean first = true;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   828
                for (JCTree var : tree.resources) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   829
                    if (!first) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   830
                        println();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   831
                        indent();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   832
                    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   833
                    printStat(var);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   834
                    first = false;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   835
                }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   836
                print(") ");
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   837
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
            for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
                printStat(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            if (tree.finalizer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                print(" finally ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                printStat(tree.finalizer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
    public void visitCatch(JCCatch tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
            print(" catch (");
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
            printExpr(tree.param);
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            print(") ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
            printStat(tree.body);
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
    public void visitConditional(JCConditional tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            open(prec, TreeInfo.condPrec);
21004
dc81ffd21bd3 8024415: Bug in javac Pretty: Wrong precedence in JCConditional trees
alundblad
parents: 19651
diff changeset
   865
            printExpr(tree.cond, TreeInfo.condPrec + 1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
            print(" ? ");
21004
dc81ffd21bd3 8024415: Bug in javac Pretty: Wrong precedence in JCConditional trees
alundblad
parents: 19651
diff changeset
   867
            printExpr(tree.truepart);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
            print(" : ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
            printExpr(tree.falsepart, TreeInfo.condPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
            close(prec, TreeInfo.condPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
    public void visitIf(JCIf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
            print("if ");
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   879
            if (tree.cond.hasTag(PARENS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
                print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
                printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
            print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
            printStat(tree.thenpart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
            if (tree.elsepart != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
                print(" else ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
                printStat(tree.elsepart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
    public void visitExec(JCExpressionStatement tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
            printExpr(tree.expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
            if (prec == TreeInfo.notExpression) print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
    public void visitBreak(JCBreak tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            print("break");
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
            if (tree.label != null) print(" " + tree.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
    public void visitContinue(JCContinue tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
            print("continue");
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
            if (tree.label != null) print(" " + tree.label);
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
    public void visitReturn(JCReturn tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
            print("return");
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
            if (tree.expr != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
                print(" ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                printExpr(tree.expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
    public void visitThrow(JCThrow tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
            print("throw ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            printExpr(tree.expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
    public void visitAssert(JCAssert tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
            print("assert ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
            printExpr(tree.cond);
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
            if (tree.detail != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
                print(" : ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
                printExpr(tree.detail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
            print(";");
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
    public void visitApply(JCMethodInvocation tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
            if (!tree.typeargs.isEmpty()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
   966
                if (tree.meth.hasTag(SELECT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
                    JCFieldAccess left = (JCFieldAccess)tree.meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
                    printExpr(left.selected);
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
                    print(".<");
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
                    printExprs(tree.typeargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
                    print(">" + left.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
                    print("<");
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
                    printExprs(tree.typeargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
                    print(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
                    printExpr(tree.meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
                printExpr(tree.meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
            print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            printExprs(tree.args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
    public void visitNewClass(JCNewClass tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
            if (tree.encl != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
                printExpr(tree.encl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
                print(".");
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
            print("new ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
            if (!tree.typeargs.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
                print("<");
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
                printExprs(tree.typeargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
                print(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1001
            if (tree.def != null && tree.def.mods.annotations.nonEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1002
                printTypeAnnotations(tree.def.mods.annotations);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1003
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
            printExpr(tree.clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
            print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
            printExprs(tree.args);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
            if (tree.def != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
                Name enclClassNamePrev = enclClassName;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
                enclClassName =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
                        tree.def.name != null ? tree.def.name :
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1012
                            tree.type != null && tree.type.tsym.name != tree.type.tsym.name.table.names.empty
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1013
                                ? tree.type.tsym.name : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
                if ((tree.def.mods.flags & Flags.ENUM) != 0) print("/*enum*/");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
                printBlock(tree.def.defs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
                enclClassName = enclClassNamePrev;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
    public void visitNewArray(JCNewArray tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
            if (tree.elemtype != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
                print("new ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                JCTree elem = tree.elemtype;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1028
                printBaseElementType(elem);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1029
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1030
                if (!tree.annotations.isEmpty()) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1031
                    print(' ');
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1032
                    printTypeAnnotations(tree.annotations);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1033
                }
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1034
                if (tree.elems != null) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1035
                    print("[]");
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1036
                }
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1037
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1038
                int i = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1039
                List<List<JCAnnotation>> da = tree.dimAnnotations;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
                for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1041
                    if (da.size() > i && !da.get(i).isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1042
                        print(' ');
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1043
                        printTypeAnnotations(da.get(i));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1044
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
                    print("[");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1046
                    i++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
                    printExpr(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
                    print("]");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
                }
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1050
                printBrackets(elem);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
            if (tree.elems != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
                print("{");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
                printExprs(tree.elems);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                print("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
11141
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1062
    public void visitLambda(JCLambda tree) {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1063
        try {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1064
            print("(");
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15044
diff changeset
  1065
            if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1066
                printExprs(tree.params);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1067
            } else {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1068
                String sep = "";
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1069
                for (JCVariableDecl param : tree.params) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1070
                    print(sep);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1071
                    print(param.name);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1072
                    sep = ",";
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1073
                }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1074
            }
11141
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1075
            print(")->");
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1076
            printExpr(tree.body);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1077
        } catch (IOException e) {
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1078
            throw new UncheckedIOException(e);
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1079
        }
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1080
    }
7d112a1ecd0f 7115046: Add AST node for lambda expressions
mcimadamore
parents: 10950
diff changeset
  1081
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
    public void visitParens(JCParens tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
            print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
            printExpr(tree.expr);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
    public void visitAssign(JCAssign tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
            open(prec, TreeInfo.assignPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
            printExpr(tree.lhs, TreeInfo.assignPrec + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
            print(" = ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
            printExpr(tree.rhs, TreeInfo.assignPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
            close(prec, TreeInfo.assignPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1104
    public String operatorName(JCTree.Tag tag) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
        switch(tag) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1106
            case POS:     return "+";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1107
            case NEG:     return "-";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1108
            case NOT:     return "!";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1109
            case COMPL:   return "~";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1110
            case PREINC:  return "++";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1111
            case PREDEC:  return "--";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1112
            case POSTINC: return "++";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1113
            case POSTDEC: return "--";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1114
            case NULLCHK: return "<*nullchk*>";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1115
            case OR:      return "||";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1116
            case AND:     return "&&";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1117
            case EQ:      return "==";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1118
            case NE:      return "!=";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1119
            case LT:      return "<";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1120
            case GT:      return ">";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1121
            case LE:      return "<=";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1122
            case GE:      return ">=";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1123
            case BITOR:   return "|";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1124
            case BITXOR:  return "^";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1125
            case BITAND:  return "&";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1126
            case SL:      return "<<";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1127
            case SR:      return ">>";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1128
            case USR:     return ">>>";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1129
            case PLUS:    return "+";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1130
            case MINUS:   return "-";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1131
            case MUL:     return "*";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1132
            case DIV:     return "/";
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1133
            case MOD:     return "%";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
            default: throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
    public void visitAssignop(JCAssignOp tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
            open(prec, TreeInfo.assignopPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
            printExpr(tree.lhs, TreeInfo.assignopPrec + 1);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1142
            print(" " + operatorName(tree.getTag().noAssignOp()) + "= ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
            printExpr(tree.rhs, TreeInfo.assignopPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            close(prec, TreeInfo.assignopPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
    public void visitUnary(JCUnary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
            int ownprec = TreeInfo.opPrec(tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
            String opname = operatorName(tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
            open(prec, ownprec);
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9300
diff changeset
  1155
            if (!tree.getTag().isPostUnaryOp()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
                print(opname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
                printExpr(tree.arg, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
                printExpr(tree.arg, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
                print(opname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
            close(prec, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
    public void visitBinary(JCBinary tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
            int ownprec = TreeInfo.opPrec(tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
            String opname = operatorName(tree.getTag());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
            open(prec, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
            printExpr(tree.lhs, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
            print(" " + opname + " ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
            printExpr(tree.rhs, ownprec + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
            close(prec, ownprec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
    public void visitTypeCast(JCTypeCast tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
            open(prec, TreeInfo.prefixPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
            print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
            printExpr(tree.clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
            printExpr(tree.expr, TreeInfo.prefixPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
            close(prec, TreeInfo.prefixPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
    public void visitTypeTest(JCInstanceOf tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
            open(prec, TreeInfo.ordPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
            printExpr(tree.expr, TreeInfo.ordPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
            print(" instanceof ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
            printExpr(tree.clazz, TreeInfo.ordPrec + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
            close(prec, TreeInfo.ordPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
    public void visitIndexed(JCArrayAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
            printExpr(tree.indexed, TreeInfo.postfixPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
            print("[");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
            printExpr(tree.index);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
            print("]");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
    public void visitSelect(JCFieldAccess tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
            printExpr(tree.selected, TreeInfo.postfixPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
            print("." + tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1227
    public void visitReference(JCMemberReference tree) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1228
        try {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1229
            printExpr(tree.expr);
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14359
diff changeset
  1230
            print("::");
11142
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1231
            if (tree.typeargs != null) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1232
                print("<");
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1233
                printExprs(tree.typeargs);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1234
                print(">");
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1235
            }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1236
            print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1237
        } catch (IOException e) {
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1238
            throw new UncheckedIOException(e);
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1239
        }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1240
    }
45d0ec1e7463 7115049: Add AST node for method references
mcimadamore
parents: 11141
diff changeset
  1241
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
    public void visitIdent(JCIdent tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
            print(tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
    public void visitLiteral(JCLiteral tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
            switch (tree.typetag) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1253
                case INT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
                    print(tree.value.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1256
                case LONG:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
                    print(tree.value + "L");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1259
                case FLOAT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
                    print(tree.value + "F");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1262
                case DOUBLE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
                    print(tree.value.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1265
                case CHAR:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
                    print("\'" +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
                            Convert.quote(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
                            String.valueOf((char)((Number)tree.value).intValue())) +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
                            "\'");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1271
                case BOOLEAN:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
                    print(((Number)tree.value).intValue() == 1 ? "true" : "false");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1274
                case BOT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
                    print("null");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
                    print("\"" + Convert.quote(tree.value.toString()) + "\"");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
    public void visitTypeIdent(JCPrimitiveTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
            switch(tree.typetag) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1289
                case BYTE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
                    print("byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1292
                case CHAR:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
                    print("char");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1295
                case SHORT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
                    print("short");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1298
                case INT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
                    print("int");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1301
                case LONG:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
                    print("long");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1304
                case FLOAT:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
                    print("float");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1307
                case DOUBLE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
                    print("double");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1310
                case BOOLEAN:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
                    print("boolean");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
                    break;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1313
                case VOID:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
                    print("void");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
                    print("error");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
    public void visitTypeArray(JCArrayTypeTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
            printBaseElementType(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
            printBrackets(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
    // Prints the inner element type of a nested array
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1335
    private void printBaseElementType(JCTree tree) throws IOException {
4705
7fac532dc6fa 6917122: provide utility method to find the inner most type of a type tree
jjg
parents: 4696
diff changeset
  1336
        printExpr(TreeInfo.innermostType(tree));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
    // prints the brackets of a nested array in reverse order
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1340
    // tree is either JCArrayTypeTree or JCAnnotatedTypeTree
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1341
    private void printBrackets(JCTree tree) throws IOException {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1342
        JCTree elem = tree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
        while (true) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1344
            if (elem.hasTag(ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1345
                JCAnnotatedType atype = (JCAnnotatedType) elem;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1346
                elem = atype.underlyingType;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1347
                if (elem.hasTag(TYPEARRAY)) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1348
                    print(' ');
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1349
                    printTypeAnnotations(atype.annotations);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1350
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1351
            }
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1352
            if (elem.hasTag(TYPEARRAY)) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1353
                print("[]");
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1354
                elem = ((JCArrayTypeTree)elem).elemtype;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1355
            } else {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1356
                break;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1357
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
    public void visitTypeApply(JCTypeApply tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
            printExpr(tree.clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
            print("<");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
            printExprs(tree.arguments);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
            print(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 8031
diff changeset
  1372
    public void visitTypeUnion(JCTypeUnion tree) {
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1373
        try {
7074
0183c3f9614e 6949587: rename "DisjointType" to "DisjunctType"
jjg
parents: 6148
diff changeset
  1374
            printExprs(tree.alternatives, " | ");
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1375
        } catch (IOException e) {
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1376
            throw new UncheckedIOException(e);
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1377
        }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1378
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 4705
diff changeset
  1379
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1380
    public void visitTypeIntersection(JCTypeIntersection tree) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1381
        try {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1382
            printExprs(tree.bounds, " & ");
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1383
        } catch (IOException e) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1384
            throw new UncheckedIOException(e);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1385
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1386
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
  1387
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
    public void visitTypeParameter(JCTypeParameter tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
        try {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1390
            if (tree.annotations.nonEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1391
                this.printTypeAnnotations(tree.annotations);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1392
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
            print(tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
            if (tree.bounds.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
                print(" extends ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
                printExprs(tree.bounds, " & ");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
    public void visitWildcard(JCWildcard tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
            print(tree.kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
            if (tree.kind.kind != BoundKind.UNBOUND)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
                printExpr(tree.inner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
    public void visitTypeBoundKind(TypeBoundKind tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
            print(String.valueOf(tree.kind));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
    public void visitErroneous(JCErroneous tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
            print("(ERROR)");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
06bc494ca11e Initial load
duke
parents:
diff changeset
  1431
    public void visitLetExpr(LetExpr tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1432
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
            print("(let " + tree.defs + " in " + tree.expr + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
    public void visitModifiers(JCModifiers mods) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
            printAnnotations(mods.annotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
            printFlags(mods.flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
    public void visitAnnotation(JCAnnotation tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
            print("@");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
            printExpr(tree.annotationType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
            print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
            printExprs(tree.args);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
            print(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1460
    public void visitAnnotatedType(JCAnnotatedType tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1461
        try {
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1462
            if (tree.underlyingType.hasTag(SELECT)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1463
                JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1464
                printExpr(access.selected, TreeInfo.postfixPrec);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1465
                print(".");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1466
                printTypeAnnotations(tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1467
                print(access.name);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1468
            } else if (tree.underlyingType.hasTag(TYPEARRAY)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1469
                printBaseElementType(tree);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 19246
diff changeset
  1470
                printBrackets(tree);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1471
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1472
                printTypeAnnotations(tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1473
                printExpr(tree.underlyingType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1474
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1475
        } catch (IOException e) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1476
            throw new UncheckedIOException(e);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1477
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1478
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15374
diff changeset
  1479
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
    public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
            print("(UNKNOWN: " + tree + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
            println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
            throw new UncheckedIOException(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
    }
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1488
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
}