langtools/src/share/classes/com/sun/tools/javac/code/Printer.java
author jjg
Wed, 10 Oct 2012 18:44:21 -0700
changeset 14263 473b1eaede64
parent 14259 fb94a1df0d53
child 14359 d4099818ab70
permissions -rw-r--r--
8000310: Clean up use of StringBuffer in langtools Reviewed-by: bpatel
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
/*
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
     2
 * Copyright (c) 2009, 2012, 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;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    31
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
    32
import com.sun.tools.javac.code.Type.*;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.javac.util.List;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.util.ListBuffer;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    35
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
    36
import static com.sun.tools.javac.code.Flags.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    37
import static com.sun.tools.javac.code.TypeTags.*;
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    38
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
 * 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
    41
 * representation of types and symbols.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 2984
diff changeset
    42
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    43
 * <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
    44
 * 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
    45
 * 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
    46
 * deletion without notice.</b>
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    47
 */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    48
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
    49
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    50
    List<Type> seenCaptured = List.nil();
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    51
    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
    52
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    53
    protected Printer() { }
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    54
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    55
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    56
     * 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
    57
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    58
     * @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
    59
     * @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
    60
     * @param args a list of optional arguments
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    61
     * @return localized string representation
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
    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
    64
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    65
    /**
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    66
     * Maps a captured type into an unique identifier.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    67
     *
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    68
     * @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
    69
     * @param locale locale settings
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    70
     * @return unique id representing this captured type
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    71
     */
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    72
    protected abstract String capturedVarId(CapturedType t, Locale locale);
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    73
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    74
    /**
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    75
     * 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
    76
     * captured types ids are generated using hashcode.
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    77
     *
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    78
     * @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
    79
     * @return printer visitor instance
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    80
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    81
    public static Printer createStandardPrinter(final Messages messages) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
    82
        return new Printer() {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    83
            @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    84
            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
    85
                return messages.getLocalizedString(locale, key, args);
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    86
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    87
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    88
            @Override
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    89
            protected String capturedVarId(CapturedType t, Locale locale) {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
    90
                return (t.hashCode() & 0xFFFFFFFFL) % PRIME + "";
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    91
        }};
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    92
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    93
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    94
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    95
     * 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
    96
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    97
     * @param ts types to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
    98
     * @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
    99
     * @return localized string representation
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
    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
   102
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   103
        for (Type t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   104
            sbuf.append(visit(t, locale));
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
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   107
    }
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
    /**
8226
8c2fd7e7bcf3 7013272: Automatically generate info about how compiler resource keys are used
jjg
parents: 5847
diff changeset
   110
     * * 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
   111
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   112
     * @param ts symbols to be displayed
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   113
     * @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
   114
     * @return localized string representation
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
    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
   117
        ListBuffer<String> sbuf = ListBuffer.lb();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   118
        for (Symbol t : ts) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   119
            sbuf.append(visit(t, locale));
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
        return sbuf.toList().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   122
    }
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
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   125
     * 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
   126
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   127
     * @param t type to be displayed
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   128
     * @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
   129
     * @return localized string representation
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
    public String visit(Type t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   132
        return t.accept(this, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   133
    }
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
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   136
     * 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
   137
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   138
     * @param s symbol to be displayed
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   139
     * @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
   140
     * @return localized string representation
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
    public String visit(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   143
        return s.accept(this, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   144
    }
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
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   147
    public String visitCapturedType(CapturedType t, Locale locale) {
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   148
        if (seenCaptured.contains(t))
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   149
            return localize(locale, "compiler.misc.type.captureof.1",
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   150
                capturedVarId(t, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   151
        else {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   152
            try {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   153
                seenCaptured = seenCaptured.prepend(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",
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
                    visit(t.wildcard, locale));
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   157
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   158
            finally {
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   159
                seenCaptured = seenCaptured.tail;
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   160
            }
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 2221
diff changeset
   161
        }
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   162
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   163
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   164
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   165
    public String visitForAll(ForAll t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   166
        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
   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 visitUndetVar(UndetVar t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   171
        if (t.inst != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   172
            return visit(t.inst, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   173
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   174
            return 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
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   177
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   178
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   179
    public String visitArrayType(ArrayType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   180
        return visit(t.elemtype, locale) + "[]";
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 visitClassType(ClassType t, Locale locale) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   185
        StringBuilder buf = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   186
        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
   187
            buf.append(visit(t.getEnclosingType(), locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   188
            buf.append(".");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   189
            buf.append(className(t, false, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   190
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   191
            buf.append(className(t, true, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   192
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   193
        if (t.getTypeArguments().nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   194
            buf.append('<');
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   195
            buf.append(visitTypes(t.getTypeArguments(), locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   196
            buf.append(">");
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
        return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   199
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   200
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   201
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   202
    public String visitMethodType(MethodType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   203
        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
   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 visitPackageType(PackageType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   208
        return t.tsym.getQualifiedName().toString();
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 visitWildcardType(WildcardType t, Locale locale) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   213
        StringBuilder s = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   214
        s.append(t.kind);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   215
        if (t.kind != UNBOUND) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   216
            s.append(visit(t.type, 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
        return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   219
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   220
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   221
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   222
    public String visitErrorType(ErrorType t, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   223
        return visitType(t, locale);
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 visitTypeVar(TypeVar 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
    public String visitType(Type t, Locale locale) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   232
        String s = (t.tsym == null || t.tsym.name == null)
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   233
                ? localize(locale, "compiler.misc.type.none")
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   234
                : t.tsym.name.toString();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   235
        return s;
2221
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
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   238
    /**
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   239
     * 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
   240
     * 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
   241
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   242
     * @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
   243
     * @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
   244
     * short name is chosen (w/o package)
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   245
     * @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
   246
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   247
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   248
    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
   249
        Symbol sym = t.tsym;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   250
        if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   251
            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
   252
            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
   253
                s.append("&");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   254
                s.append(visit(is.head, locale));
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
            return s.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   257
        } else if (sym.name.length() == 0) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   258
            String s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   259
            ClassType norm = (ClassType) t.tsym.type;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   260
            if (norm == null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   261
                s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10626
diff changeset
   262
            } 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
   263
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   264
                        visit(norm.interfaces_field.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   265
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   266
                s = localize(locale, "compiler.misc.anonymous.class",
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   267
                        visit(norm.supertype_field, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   268
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   269
            return s;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   270
        } else if (longform) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   271
            return sym.getQualifiedName().toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   272
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   273
            return sym.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   274
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   275
    }
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
     * 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
   279
     * localized string representation.
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   280
     *
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   281
     * @param args arguments to be rendered
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   282
     * @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
   283
     * @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
   284
     * @return localized string representation
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   285
     */
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   286
    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
   287
        if (!varArgs) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   288
            return visitTypes(args, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   289
        } else {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14259
diff changeset
   290
            StringBuilder buf = new StringBuilder();
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   291
            while (args.tail.nonEmpty()) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   292
                buf.append(visit(args.head, locale));
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   293
                args = args.tail;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   294
                buf.append(',');
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
            if (args.head.tag == ARRAY) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   297
                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
   298
                buf.append("...");
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   299
            } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   300
                buf.append(visit(args.head, locale));
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
            return buf.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   303
        }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   304
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   305
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   306
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   307
    public String visitClassSymbol(ClassSymbol sym, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   308
        return sym.name.isEmpty()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   309
                ? 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
   310
                : sym.fullname.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   311
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   312
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   313
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   314
    public String visitMethodSymbol(MethodSymbol s, Locale locale) {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 8226
diff changeset
   315
        if (s.isStaticOrInstanceInit()) {
2221
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   316
            return s.owner.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   317
        } else {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   318
            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
   319
                    ? s.owner.name.toString()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   320
                    : s.name.toString();
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   321
            if (s.type != null) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   322
                if (s.type.tag == FORALL) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   323
                    ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
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
                ms += "(" + printMethodArgs(
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   326
                        s.type.getParameterTypes(),
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   327
                        (s.flags() & VARARGS) != 0,
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   328
                        locale) + ")";
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   329
            }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   330
            return ms;
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   331
        }
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 visitOperatorSymbol(OperatorSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   336
        return visitMethodSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   337
    }
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   338
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   339
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   340
    public String visitPackageSymbol(PackageSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   341
        return s.isUnnamed()
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   342
                ? localize(locale, "compiler.misc.unnamed.package")
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   343
                : s.fullname.toString();
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 visitTypeSymbol(TypeSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   348
        return visitSymbol(s, locale);
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   349
    }
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
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   352
    public String visitVarSymbol(VarSymbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   353
        return visitSymbol(s, locale);
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
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   356
    @Override
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   357
    public String visitSymbol(Symbol s, Locale locale) {
cd6557bcaa0a 6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff changeset
   358
        return s.name.toString();
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
}