langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
author mcimadamore
Wed, 06 Feb 2013 14:03:39 +0000
changeset 15705 c4124695db0c
parent 15385 ee1eebe7e210
child 16557 67a3ae363f03
permissions -rw-r--r--
8007463: Cleanup inference related classes Summary: Make Infer.InferenceContext an inner class; adjust bound replacement logic in Type.UndetVar Reviewed-by: jjg
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
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
     2
 * Copyright (c) 2009, 2013, 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
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
    30
import javax.lang.model.type.TypeKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
    31
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    32
import com.sun.tools.javac.api.Messages;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
    33
import com.sun.tools.javac.code.Type.AnnotatedType;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    34
import com.sun.tools.javac.code.Symbol.*;
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    35
import com.sun.tools.javac.code.Type.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.javac.util.List;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.util.ListBuffer;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14263
diff changeset
    38
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    39
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
    40
import static com.sun.tools.javac.code.Flags.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14263
diff changeset
    41
import static com.sun.tools.javac.code.TypeTag.CLASS;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14263
diff changeset
    42
import static com.sun.tools.javac.code.TypeTag.FORALL;
2221
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
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    58
    protected Printer() { }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    59
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    60
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    61
     * 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
    62
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    63
     * @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
    64
     * @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
    65
     * @param args a list of optional arguments
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    66
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    67
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    68
    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
    69
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    70
    /**
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    71
     * Maps a captured type into an unique identifier.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    72
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    73
     * @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
    74
     * @param locale locale settings
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    75
     * @return unique id representing this captured type
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    76
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    77
    protected abstract String capturedVarId(CapturedType t, Locale locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    78
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
     * 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
    81
     * captured types ids are generated using hashcode.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    82
     *
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    83
     * @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
    84
     * @return printer visitor instance
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    85
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    86
    public static Printer createStandardPrinter(final Messages messages) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    87
        return new Printer() {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    88
            @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    89
            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
    90
                return messages.getLocalizedString(locale, key, args);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    91
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    92
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    93
            @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    94
            protected String capturedVarId(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    95
                return (t.hashCode() & 0xFFFFFFFFL) % PRIME + "";
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    96
        }};
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    97
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    98
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
     * 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
   101
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   102
     * @param ts types to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   103
     * @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
   104
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   105
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   106
    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
   107
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   108
        for (Type t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   109
            sbuf.append(visit(t, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   110
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   111
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   112
    }
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
    /**
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents: 5847
diff changeset
   115
     * * 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
   116
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   117
     * @param ts symbols to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   118
     * @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
   119
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   120
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   121
    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
   122
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   123
        for (Symbol t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   124
            sbuf.append(visit(t, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   125
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   126
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   127
    }
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
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   130
     * 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
   131
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   132
     * @param t type to be displayed
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   133
     * @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
   134
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   135
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   136
    public String visit(Type t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   137
        return t.accept(this, locale);
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
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   140
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   141
     * 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
   142
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   143
     * @param s symbol to be displayed
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   144
     * @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
   145
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   146
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   147
    public String visit(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   148
        return s.accept(this, locale);
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
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   151
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   152
    public String visitCapturedType(CapturedType t, Locale locale) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   153
        if (seenCaptured.contains(t))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   154
            return localize(locale, "compiler.misc.type.captureof.1",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   155
                capturedVarId(t, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   156
        else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   157
            try {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   158
                seenCaptured = seenCaptured.prepend(t);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   159
                return localize(locale, "compiler.misc.type.captureof",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   160
                    capturedVarId(t, locale),
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   161
                    visit(t.wildcard, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   162
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   163
            finally {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   164
                seenCaptured = seenCaptured.tail;
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
        }
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   167
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   168
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   169
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   170
    public String visitForAll(ForAll t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   171
        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
   172
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   173
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   174
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   175
    public String visitUndetVar(UndetVar t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   176
        if (t.inst != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   177
            return visit(t.inst, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   178
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   179
            return visit(t.qtype, locale) + "?";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   180
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   181
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   182
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   183
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   184
    public String visitArrayType(ArrayType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   185
        return visit(t.elemtype, locale) + "[]";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   186
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   187
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   188
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   189
    public String visitClassType(ClassType t, Locale locale) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   190
        StringBuilder buf = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   191
        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
   192
            buf.append(visit(t.getEnclosingType(), locale));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   193
            buf.append('.');
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   194
            buf.append(className(t, false, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   195
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   196
            buf.append(className(t, true, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   197
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   198
        if (t.getTypeArguments().nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   199
            buf.append('<');
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   200
            buf.append(visitTypes(t.getTypeArguments(), locale));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   201
            buf.append('>');
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   202
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   203
        return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   204
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   205
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   206
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   207
    public String visitMethodType(MethodType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   208
        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
   209
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   210
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   211
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   212
    public String visitPackageType(PackageType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   213
        return t.tsym.getQualifiedName().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   214
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   215
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   216
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   217
    public String visitWildcardType(WildcardType t, Locale locale) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   218
        StringBuilder s = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   219
        s.append(t.kind);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   220
        if (t.kind != UNBOUND) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   221
            s.append(visit(t.type, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   222
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   223
        return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   224
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   225
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   226
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   227
    public String visitErrorType(ErrorType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   228
        return visitType(t, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   229
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   230
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   231
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   232
    public String visitTypeVar(TypeVar t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   233
        return visitType(t, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   234
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   235
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   236
    @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   237
    public String visitAnnotatedType(AnnotatedType t, Locale locale) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   238
        if (t.typeAnnotations != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   239
                t.typeAnnotations.nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   240
            // TODO: better logic for arrays, ...
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   241
            return "(" + t.typeAnnotations + " :: " + visit(t.underlyingType, locale) + ")";
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   242
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   243
            return "({} :: " + visit(t.underlyingType, locale) + ")";
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   244
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   245
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   246
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   247
    public String visitType(Type t, Locale locale) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   248
        String s = (t.tsym == null || t.tsym.name == null)
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   249
                ? localize(locale, "compiler.misc.type.none")
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   250
                : t.tsym.name.toString();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   251
        return s;
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   252
    }
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
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   255
     * 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
   256
     * 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
   257
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   258
     * @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
   259
     * @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
   260
     * short name is chosen (w/o package)
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   261
     * @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
   262
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   263
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   264
    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
   265
        Symbol sym = t.tsym;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   266
        if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   267
            StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   268
            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
   269
                s.append("&");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   270
                s.append(visit(is.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   271
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   272
            return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   273
        } else if (sym.name.length() == 0) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   274
            String s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   275
            ClassType norm = (ClassType) t.tsym.type;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   276
            if (norm == null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   277
                s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10626
diff changeset
   278
            } 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
   279
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   280
                        visit(norm.interfaces_field.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   281
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   282
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   283
                        visit(norm.supertype_field, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   284
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   285
            return s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   286
        } else if (longform) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   287
            return sym.getQualifiedName().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   288
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   289
            return sym.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   290
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   291
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   292
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   293
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   294
     * 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
   295
     * localized string representation.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   296
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   297
     * @param args arguments to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   298
     * @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
   299
     * @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
   300
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   301
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   302
    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
   303
        if (!varArgs) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   304
            return visitTypes(args, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   305
        } else {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   306
            StringBuilder buf = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   307
            while (args.tail.nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   308
                buf.append(visit(args.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   309
                args = args.tail;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   310
                buf.append(',');
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   311
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   312
            if (args.head.unannotatedType().getKind() == TypeKind.ARRAY) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   313
                buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   314
                if (args.head.getAnnotations().nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   315
                    buf.append(' ');
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   316
                    buf.append(args.head.getAnnotations());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   317
                    buf.append(' ');
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14359
diff changeset
   318
                }
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   319
                buf.append("...");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   320
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   321
                buf.append(visit(args.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   322
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   323
            return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   324
        }
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
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   327
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   328
    public String visitClassSymbol(ClassSymbol sym, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   329
        return sym.name.isEmpty()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   330
                ? 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
   331
                : sym.fullname.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   332
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   333
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   334
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   335
    public String visitMethodSymbol(MethodSymbol s, Locale locale) {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 8226
diff changeset
   336
        if (s.isStaticOrInstanceInit()) {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   337
            return s.owner.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   338
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   339
            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
   340
                    ? s.owner.name.toString()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   341
                    : s.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   342
            if (s.type != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   343
                if (s.type.tag == FORALL) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   344
                    ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
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
                ms += "(" + printMethodArgs(
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   347
                        s.type.getParameterTypes(),
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   348
                        (s.flags() & VARARGS) != 0,
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   349
                        locale) + ")";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   350
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   351
            return ms;
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
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   354
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   355
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   356
    public String visitOperatorSymbol(OperatorSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   357
        return visitMethodSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   358
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   359
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   360
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   361
    public String visitPackageSymbol(PackageSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   362
        return s.isUnnamed()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   363
                ? localize(locale, "compiler.misc.unnamed.package")
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   364
                : s.fullname.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   365
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   366
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   367
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   368
    public String visitTypeSymbol(TypeSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   369
        return visitSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   370
    }
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
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   373
    public String visitVarSymbol(VarSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   374
        return visitSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   375
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   376
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   377
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   378
    public String visitSymbol(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   379
        return s.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   380
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   381
}