langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
author mcimadamore
Thu, 04 Oct 2012 13:04:53 +0100
changeset 14057 b4b0377b8dba
parent 10816 ce8a7e9d8882
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:
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
     1
/*
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents: 5847
diff changeset
     2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
     4
 *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
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: 3380
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3380
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    10
 *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    16
 *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3380
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3380
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3380
diff changeset
    23
 * questions.
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    24
 */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    25
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    26
package com.sun.tools.javac.code;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    27
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    28
import java.util.Locale;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    29
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    30
import com.sun.tools.javac.api.Messages;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    31
import com.sun.tools.javac.code.Type.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    32
import com.sun.tools.javac.code.Symbol.*;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    33
import com.sun.tools.javac.comp.DeferredAttr.DeferredType;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    34
import com.sun.tools.javac.tree.JCTree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    35
import com.sun.tools.javac.tree.Pretty;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    36
import com.sun.tools.javac.util.Assert;
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.util.List;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    38
import com.sun.tools.javac.util.ListBuffer;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    39
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    40
import static com.sun.tools.javac.code.TypeTags.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    41
import static com.sun.tools.javac.code.BoundKind.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    42
import static com.sun.tools.javac.code.Flags.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    43
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    44
/**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    45
 * A combined type/symbol visitor for generating non-trivial localized string
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    46
 * representation of types and symbols.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 2984
diff changeset
    47
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    48
 * <p><b>This is NOT part of any supported API.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 2984
diff changeset
    49
 * If you write code that depends on this, you do so at your own risk.
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 2984
diff changeset
    50
 * This code and its internal interfaces are subject to change or
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 2984
diff changeset
    51
 * deletion without notice.</b>
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    52
 */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    53
public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Visitor<String, Locale> {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    54
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    55
    List<Type> seenCaptured = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    56
    static final int PRIME = 997;  // largest prime less than 1000
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    57
    boolean raw;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    58
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    59
    protected Printer(boolean raw) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    60
        this.raw = raw;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    61
    }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    62
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    63
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    64
     * This method should be overriden in order to provide proper i18n support.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    65
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    66
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    67
     * @param key the key corresponding to the message to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    68
     * @param args a list of optional arguments
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    69
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    70
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    71
    protected abstract String localize(Locale locale, String key, Object... args);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    72
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    73
    /**
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    74
     * Maps a captured type into an unique identifier.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    75
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    76
     * @param t the captured type for which an id is to be retrieved
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    77
     * @param locale locale settings
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    78
     * @return unique id representing this captured type
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    79
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    80
    protected abstract String capturedVarId(CapturedType t, Locale locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    81
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    82
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    83
     * Create a printer with default i18n support provided by Messages. By default,
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    84
     * captured types ids are generated using hashcode.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    85
     *
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    86
     * @param messages Messages class to be used for i18n
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    87
     * @return printer visitor instance
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    88
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    89
    public static Printer createStandardPrinter(final Messages messages) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
    90
        return new Printer(false) {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    91
            @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    92
            protected String localize(Locale locale, String key, Object... args) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    93
                return messages.getLocalizedString(locale, key, args);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    94
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    95
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    96
            @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    97
            protected String capturedVarId(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    98
                return (t.hashCode() & 0xFFFFFFFFL) % PRIME + "";
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    99
        }};
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   100
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   101
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   102
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   103
     * Get a localized string representation for all the types in the input list.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   104
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   105
     * @param ts types to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   106
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   107
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   108
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   109
    public String visitTypes(List<Type> ts, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   110
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   111
        for (Type t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   112
            sbuf.append(visit(t, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   113
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   114
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   115
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   116
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   117
    /**
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents: 5847
diff changeset
   118
     * * Get a localized string representation for all the symbols in the input list.
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   119
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   120
     * @param ts symbols to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   121
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   122
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   123
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   124
    public String visitSymbols(List<Symbol> ts, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   125
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   126
        for (Symbol t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   127
            sbuf.append(visit(t, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   128
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   129
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   130
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   131
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   132
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   133
     * Get a localized string represenation for a given type.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   134
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   135
     * @param ts type to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   136
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   137
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   138
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   139
    public String visit(Type t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   140
        return t.accept(this, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   141
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   142
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   143
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   144
     * Get a localized string represenation for a given symbol.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   145
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   146
     * @param ts symbol to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   147
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   148
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   149
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   150
    public String visit(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   151
        return s.accept(this, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   152
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   153
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   154
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   155
    public String visitCapturedType(CapturedType t, Locale locale) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   156
        if (seenCaptured.contains(t))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   157
            return localize(locale, "compiler.misc.type.captureof.1",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   158
                capturedVarId(t, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   159
        else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   160
            try {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   161
                seenCaptured = seenCaptured.prepend(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   162
                return localize(locale, "compiler.misc.type.captureof",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   163
                    capturedVarId(t, locale),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   164
                    visit(t.wildcard, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   165
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   166
            finally {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   167
                seenCaptured = seenCaptured.tail;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   168
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   169
        }
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   170
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   171
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   172
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   173
    public String visitForAll(ForAll t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   174
        return "<" + visitTypes(t.tvars, locale) + ">" + visit(t.qtype, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   175
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   176
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   177
    public String visitDeferredType(DeferredType t, Locale locale) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   178
        return raw ? localize(locale, getDeferredKey(t.tree)) :
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   179
            deferredTypeTree2String(t.tree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   180
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   181
    //where
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   182
        private String deferredTypeTree2String(JCTree tree) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   183
            switch(tree.getTag()) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   184
                case PARENS:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   185
                    return deferredTypeTree2String(((JCTree.JCParens)tree).expr);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   186
                case CONDEXPR:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   187
                    return Pretty.toSimpleString(tree, 15);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   188
                default:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   189
                    Assert.error("unexpected tree kind " + tree.getKind());
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   190
                    return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   191
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   192
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   193
        private String getDeferredKey (JCTree tree) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   194
            switch (tree.getTag()) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   195
                case PARENS:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   196
                    return getDeferredKey(((JCTree.JCParens)tree).expr);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   197
                case CONDEXPR:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   198
                     return "compiler.misc.type.conditional";
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   199
                default:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   200
                    Assert.error("unexpected tree kind " + tree.getKind());
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   201
                    return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   202
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   203
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   204
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   205
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   206
    public String visitUndetVar(UndetVar t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   207
        if (t.inst != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   208
            return visit(t.inst, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   209
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   210
            return visit(t.qtype, locale) + "?";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   211
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   212
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   213
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   214
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   215
    public String visitArrayType(ArrayType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   216
        return visit(t.elemtype, locale) + "[]";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   217
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   218
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   219
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   220
    public String visitClassType(ClassType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   221
        StringBuffer buf = new StringBuffer();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   222
        if (t.getEnclosingType().tag == CLASS && t.tsym.owner.kind == Kinds.TYP) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   223
            buf.append(visit(t.getEnclosingType(), locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   224
            buf.append(".");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   225
            buf.append(className(t, false, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   226
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   227
            buf.append(className(t, true, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   228
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   229
        if (t.getTypeArguments().nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   230
            buf.append('<');
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   231
            buf.append(visitTypes(t.getTypeArguments(), locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   232
            buf.append(">");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   233
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   234
        return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   235
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   236
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   237
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   238
    public String visitMethodType(MethodType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   239
        return "(" + printMethodArgs(t.argtypes, false, locale) + ")" + visit(t.restype, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   240
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   241
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   242
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   243
    public String visitPackageType(PackageType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   244
        return t.tsym.getQualifiedName().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   245
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   246
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   247
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   248
    public String visitWildcardType(WildcardType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   249
        StringBuffer s = new StringBuffer();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   250
        s.append(t.kind);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   251
        if (t.kind != UNBOUND) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   252
            s.append(visit(t.type, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   253
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   254
        return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   255
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   256
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   257
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   258
    public String visitErrorType(ErrorType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   259
        return visitType(t, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   260
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   261
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   262
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   263
    public String visitTypeVar(TypeVar t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   264
        return visitType(t, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   265
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   266
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   267
    public String visitType(Type t, Locale locale) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   268
        if (t.tag == DEFERRED) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   269
            return visitDeferredType((DeferredType)t, locale);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   270
        } else {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   271
            String s = (t.tsym == null || t.tsym.name == null)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   272
                    ? localize(locale, "compiler.misc.type.none")
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   273
                    : t.tsym.name.toString();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   274
            return s;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 10816
diff changeset
   275
        }
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   276
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   277
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   278
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   279
     * Converts a class name into a (possibly localized) string. Anonymous
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   280
     * inner classes gets converted into a localized string.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   281
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   282
     * @param t the type of the class whose name is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   283
     * @param longform if set, the class' fullname is displayed - if unset the
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   284
     * short name is chosen (w/o package)
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   285
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   286
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   287
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   288
    protected String className(ClassType t, boolean longform, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   289
        Symbol sym = t.tsym;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   290
        if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   291
            StringBuffer s = new StringBuffer(visit(t.supertype_field, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   292
            for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   293
                s.append("&");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   294
                s.append(visit(is.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   295
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   296
            return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   297
        } else if (sym.name.length() == 0) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   298
            String s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   299
            ClassType norm = (ClassType) t.tsym.type;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   300
            if (norm == null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   301
                s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10626
diff changeset
   302
            } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   303
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   304
                        visit(norm.interfaces_field.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   305
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   306
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   307
                        visit(norm.supertype_field, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   308
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   309
            return s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   310
        } else if (longform) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   311
            return sym.getQualifiedName().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   312
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   313
            return sym.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   314
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   315
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   316
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   317
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   318
     * Converts a set of method argument types into their corresponding
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   319
     * localized string representation.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   320
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   321
     * @param args arguments to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   322
     * @param varArgs if true, the last method argument is regarded as a vararg
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   323
     * @param locale the locale in which the string is to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   324
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   325
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   326
    protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   327
        if (!varArgs) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   328
            return visitTypes(args, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   329
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   330
            StringBuffer buf = new StringBuffer();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   331
            while (args.tail.nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   332
                buf.append(visit(args.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   333
                args = args.tail;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   334
                buf.append(',');
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   335
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   336
            if (args.head.tag == ARRAY) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   337
                buf.append(visit(((ArrayType) args.head).elemtype, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   338
                buf.append("...");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   339
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   340
                buf.append(visit(args.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   341
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   342
            return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   343
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   344
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   345
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   346
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   347
    public String visitClassSymbol(ClassSymbol sym, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   348
        return sym.name.isEmpty()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   349
                ? localize(locale, "compiler.misc.anonymous.class", sym.flatname)
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   350
                : sym.fullname.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   351
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   352
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   353
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   354
    public String visitMethodSymbol(MethodSymbol s, Locale locale) {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 8226
diff changeset
   355
        if (s.isStaticOrInstanceInit()) {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   356
            return s.owner.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   357
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   358
            String ms = (s.name == s.name.table.names.init)
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   359
                    ? s.owner.name.toString()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   360
                    : s.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   361
            if (s.type != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   362
                if (s.type.tag == FORALL) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   363
                    ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   364
                }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   365
                ms += "(" + printMethodArgs(
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   366
                        s.type.getParameterTypes(),
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   367
                        (s.flags() & VARARGS) != 0,
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   368
                        locale) + ")";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   369
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   370
            return ms;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   371
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   372
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   373
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   374
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   375
    public String visitOperatorSymbol(OperatorSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   376
        return visitMethodSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   377
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   378
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   379
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   380
    public String visitPackageSymbol(PackageSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   381
        return s.isUnnamed()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   382
                ? localize(locale, "compiler.misc.unnamed.package")
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   383
                : s.fullname.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   384
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   385
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   386
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   387
    public String visitTypeSymbol(TypeSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   388
        return visitSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   389
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   390
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   391
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   392
    public String visitVarSymbol(VarSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   393
        return visitSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   394
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   395
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   396
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   397
    public String visitSymbol(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   398
        return s.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   399
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   400
}