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