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