author | jjg |
Tue, 15 Oct 2013 15:57:13 -0700 | |
changeset 21041 | 99f5e5e97425 |
parent 20249 | 93f8eae31092 |
child 24396 | 3c36c6afcbca |
permissions | -rw-r--r-- |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
1 |
/* |
15385 | 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 | 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 | 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 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
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; |
15385 | 31 |
import com.sun.tools.javac.code.Type.AnnotatedType; |
17578 | 32 |
import com.sun.tools.javac.code.Type.ArrayType; |
14258 | 33 |
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
|
34 |
import com.sun.tools.javac.code.Type.*; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.util.List; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
36 |
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
|
37 |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
|
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 |
* 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
|
45 |
* representation of types and symbols. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
2984
diff
changeset
|
46 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
47 |
* <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
|
48 |
* 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
|
49 |
* 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
|
50 |
* deletion without notice.</b> |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
51 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
52 |
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
|
53 |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
54 |
List<Type> seenCaptured = List.nil(); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
55 |
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
|
56 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
57 |
protected Printer() { } |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
58 |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
59 |
/** |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
60 |
* 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
|
61 |
* |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
62 |
* @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
|
63 |
* @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
|
64 |
* @param args a list of optional arguments |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
65 |
* @return localized string representation |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
66 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
67 |
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
|
68 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
69 |
/** |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
70 |
* Maps a captured type into an unique identifier. |
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 |
* @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
|
73 |
* @param locale locale settings |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
74 |
* @return unique id representing this captured type |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
75 |
*/ |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
76 |
protected abstract String capturedVarId(CapturedType t, Locale locale); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
77 |
|
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 |
* 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
|
80 |
* captured types ids are generated using hashcode. |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
81 |
* |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
82 |
* @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
|
83 |
* @return printer visitor instance |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
84 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
85 |
public static Printer createStandardPrinter(final Messages messages) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
86 |
return new Printer() { |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
87 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
88 |
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
|
89 |
return messages.getLocalizedString(locale, key, args); |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
90 |
} |
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 |
@Override |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
93 |
protected String capturedVarId(CapturedType t, Locale locale) { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
94 |
return (t.hashCode() & 0xFFFFFFFFL) % PRIME + ""; |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
95 |
}}; |
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 |
* 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
|
100 |
* |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
101 |
* @param ts types to be displayed |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
102 |
* @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
|
103 |
* @return localized string representation |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
104 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
105 |
public String visitTypes(List<Type> ts, Locale locale) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
106 |
ListBuffer<String> sbuf = new ListBuffer<>(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
107 |
for (Type t : ts) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
108 |
sbuf.append(visit(t, locale)); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
109 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
110 |
return sbuf.toList().toString(); |
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 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
113 |
/** |
8226
8c2fd7e7bcf3
7013272: Automatically generate info about how compiler resource keys are used
jjg
parents:
5847
diff
changeset
|
114 |
* * 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
|
115 |
* |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
116 |
* @param ts symbols to be displayed |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
117 |
* @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
|
118 |
* @return localized string representation |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
119 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
120 |
public String visitSymbols(List<Symbol> ts, Locale locale) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
121 |
ListBuffer<String> sbuf = new ListBuffer<>(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
122 |
for (Symbol t : ts) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
123 |
sbuf.append(visit(t, locale)); |
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 |
return sbuf.toList().toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
126 |
} |
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 |
/** |
17578 | 129 |
* Get a localized string representation for a given type. |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
130 |
* |
14259 | 131 |
* @param t type to be displayed |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
132 |
* @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
|
133 |
* @return localized string representation |
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 |
public String visit(Type t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
136 |
return t.accept(this, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
137 |
} |
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 |
/** |
17578 | 140 |
* Get a localized string representation for a given symbol. |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
141 |
* |
14259 | 142 |
* @param s symbol to be displayed |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
143 |
* @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
|
144 |
* @return localized string representation |
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 |
public String visit(Symbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
147 |
return s.accept(this, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
148 |
} |
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 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
151 |
public String visitCapturedType(CapturedType t, Locale locale) { |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
152 |
if (seenCaptured.contains(t)) |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
153 |
return localize(locale, "compiler.misc.type.captureof.1", |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
154 |
capturedVarId(t, locale)); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
155 |
else { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
156 |
try { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
157 |
seenCaptured = seenCaptured.prepend(t); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
158 |
return localize(locale, "compiler.misc.type.captureof", |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
159 |
capturedVarId(t, locale), |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
160 |
visit(t.wildcard, locale)); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
161 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
162 |
finally { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
163 |
seenCaptured = seenCaptured.tail; |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
164 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2221
diff
changeset
|
165 |
} |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
166 |
} |
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 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
169 |
public String visitForAll(ForAll t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
170 |
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
|
171 |
} |
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 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
174 |
public String visitUndetVar(UndetVar t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
175 |
if (t.inst != null) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
176 |
return visit(t.inst, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
177 |
} else { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
178 |
return visit(t.qtype, locale) + "?"; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
179 |
} |
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 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
183 |
public String visitArrayType(ArrayType t, Locale locale) { |
17578 | 184 |
StringBuilder res = new StringBuilder(); |
185 |
printBaseElementType(t, res, locale); |
|
186 |
printBrackets(t, res, locale); |
|
187 |
return res.toString(); |
|
188 |
} |
|
189 |
||
190 |
void printBaseElementType(Type t, StringBuilder sb, Locale locale) { |
|
191 |
Type arrel = t; |
|
19651 | 192 |
while (arrel.hasTag(TypeTag.ARRAY)) { |
17578 | 193 |
arrel = arrel.unannotatedType(); |
194 |
arrel = ((ArrayType) arrel).elemtype; |
|
195 |
} |
|
196 |
sb.append(visit(arrel, locale)); |
|
197 |
} |
|
198 |
||
199 |
void printBrackets(Type t, StringBuilder sb, Locale locale) { |
|
200 |
Type arrel = t; |
|
19651 | 201 |
while (arrel.hasTag(TypeTag.ARRAY)) { |
17578 | 202 |
if (arrel.isAnnotated()) { |
203 |
sb.append(' '); |
|
204 |
sb.append(arrel.getAnnotationMirrors()); |
|
205 |
sb.append(' '); |
|
206 |
} |
|
207 |
sb.append("[]"); |
|
208 |
arrel = arrel.unannotatedType(); |
|
209 |
arrel = ((ArrayType) arrel).elemtype; |
|
210 |
} |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
211 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
212 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
213 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
214 |
public String visitClassType(ClassType t, Locale locale) { |
14263 | 215 |
StringBuilder buf = new StringBuilder(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
17578
diff
changeset
|
216 |
if (t.getEnclosingType().hasTag(CLASS) && t.tsym.owner.kind == Kinds.TYP) { |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
217 |
buf.append(visit(t.getEnclosingType(), locale)); |
15385 | 218 |
buf.append('.'); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
219 |
buf.append(className(t, false, locale)); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
220 |
} else { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
221 |
buf.append(className(t, true, 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 |
if (t.getTypeArguments().nonEmpty()) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
224 |
buf.append('<'); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
225 |
buf.append(visitTypes(t.getTypeArguments(), locale)); |
15385 | 226 |
buf.append('>'); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
227 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
228 |
return buf.toString(); |
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 visitMethodType(MethodType t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
233 |
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
|
234 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
235 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
236 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
237 |
public String visitPackageType(PackageType t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
238 |
return t.tsym.getQualifiedName().toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
239 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
240 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
241 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
242 |
public String visitWildcardType(WildcardType t, Locale locale) { |
14263 | 243 |
StringBuilder s = new StringBuilder(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
244 |
s.append(t.kind); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
245 |
if (t.kind != UNBOUND) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
246 |
s.append(visit(t.type, locale)); |
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 |
return s.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
249 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
250 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
251 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
252 |
public String visitErrorType(ErrorType t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
253 |
return visitType(t, locale); |
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 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
256 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
257 |
public String visitTypeVar(TypeVar t, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
258 |
return visitType(t, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
259 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
260 |
|
15385 | 261 |
@Override |
262 |
public String visitAnnotatedType(AnnotatedType t, Locale locale) { |
|
21041 | 263 |
if (t.getAnnotationMirrors().nonEmpty()) { |
264 |
if (t.unannotatedType().hasTag(TypeTag.ARRAY)) { |
|
17578 | 265 |
StringBuilder res = new StringBuilder(); |
266 |
printBaseElementType(t, res, locale); |
|
267 |
printBrackets(t, res, locale); |
|
268 |
return res.toString(); |
|
21041 | 269 |
} else if (t.unannotatedType().hasTag(TypeTag.CLASS) && |
270 |
t.unannotatedType().getEnclosingType() != Type.noType) { |
|
271 |
return visit(t.unannotatedType().getEnclosingType(), locale) + |
|
17578 | 272 |
". " + |
21041 | 273 |
t.getAnnotationMirrors() + |
274 |
" " + className((ClassType)t.unannotatedType(), false, locale); |
|
17578 | 275 |
} else { |
21041 | 276 |
return t.getAnnotationMirrors() + " " + visit(t.unannotatedType(), locale); |
17578 | 277 |
} |
15385 | 278 |
} else { |
21041 | 279 |
return visit(t.unannotatedType(), locale); |
15385 | 280 |
} |
281 |
} |
|
282 |
||
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
283 |
public String visitType(Type t, Locale locale) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
284 |
String s = (t.tsym == null || t.tsym.name == null) |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
285 |
? localize(locale, "compiler.misc.type.none") |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
286 |
: t.tsym.name.toString(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
287 |
return s; |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
288 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
289 |
|
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 |
* Converts a class name into a (possibly localized) string. Anonymous |
17578 | 292 |
* inner classes get converted into a localized string. |
2221
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 |
* @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
|
295 |
* @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
|
296 |
* short name is chosen (w/o package) |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
297 |
* @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
|
298 |
* @return localized string representation |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
299 |
*/ |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
300 |
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
|
301 |
Symbol sym = t.tsym; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
302 |
if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) { |
14263 | 303 |
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
|
304 |
for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) { |
17578 | 305 |
s.append('&'); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
306 |
s.append(visit(is.head, locale)); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
307 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
308 |
return s.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
309 |
} else if (sym.name.length() == 0) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
310 |
String s; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
311 |
ClassType norm = (ClassType) t.tsym.type; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
312 |
if (norm == null) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
313 |
s = localize(locale, "compiler.misc.anonymous.class", (Object) null); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10626
diff
changeset
|
314 |
} 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
|
315 |
s = localize(locale, "compiler.misc.anonymous.class", |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
316 |
visit(norm.interfaces_field.head, locale)); |
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 |
s = localize(locale, "compiler.misc.anonymous.class", |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
319 |
visit(norm.supertype_field, locale)); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
320 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
321 |
return s; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
322 |
} else if (longform) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
323 |
return sym.getQualifiedName().toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
324 |
} else { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
325 |
return sym.name.toString(); |
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 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
328 |
|
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 |
* 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
|
331 |
* localized string representation. |
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 |
* @param args arguments to be rendered |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
334 |
* @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
|
335 |
* @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
|
336 |
* @return localized string representation |
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 |
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
|
339 |
if (!varArgs) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
340 |
return visitTypes(args, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
341 |
} else { |
14263 | 342 |
StringBuilder buf = new StringBuilder(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
343 |
while (args.tail.nonEmpty()) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
344 |
buf.append(visit(args.head, locale)); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
345 |
args = args.tail; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
346 |
buf.append(','); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
347 |
} |
19651 | 348 |
if (args.head.unannotatedType().hasTag(TypeTag.ARRAY)) { |
15385 | 349 |
buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale)); |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
15385
diff
changeset
|
350 |
if (args.head.getAnnotationMirrors().nonEmpty()) { |
15385 | 351 |
buf.append(' '); |
16557
67a3ae363f03
8007803: Implement javax.lang.model API for Type Annotations
jjg
parents:
15385
diff
changeset
|
352 |
buf.append(args.head.getAnnotationMirrors()); |
15385 | 353 |
buf.append(' '); |
354 |
} |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
355 |
buf.append("..."); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
356 |
} else { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
357 |
buf.append(visit(args.head, 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 |
return buf.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
360 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
361 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
362 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
363 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
364 |
public String visitClassSymbol(ClassSymbol sym, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
365 |
return sym.name.isEmpty() |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
366 |
? 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
|
367 |
: sym.fullname.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
368 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
369 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
370 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
371 |
public String visitMethodSymbol(MethodSymbol s, Locale locale) { |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8226
diff
changeset
|
372 |
if (s.isStaticOrInstanceInit()) { |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
373 |
return s.owner.name.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
374 |
} else { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
375 |
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
|
376 |
? s.owner.name.toString() |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
377 |
: s.name.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
378 |
if (s.type != null) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
17578
diff
changeset
|
379 |
if (s.type.hasTag(FORALL)) { |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
380 |
ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
381 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
382 |
ms += "(" + printMethodArgs( |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
383 |
s.type.getParameterTypes(), |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
384 |
(s.flags() & VARARGS) != 0, |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
385 |
locale) + ")"; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
386 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
387 |
return ms; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
388 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
389 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
390 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
391 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
392 |
public String visitOperatorSymbol(OperatorSymbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
393 |
return visitMethodSymbol(s, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
394 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
395 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
396 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
397 |
public String visitPackageSymbol(PackageSymbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
398 |
return s.isUnnamed() |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
399 |
? localize(locale, "compiler.misc.unnamed.package") |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
400 |
: s.fullname.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
401 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
402 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
403 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
404 |
public String visitTypeSymbol(TypeSymbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
405 |
return visitSymbol(s, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
406 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
407 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
408 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
409 |
public String visitVarSymbol(VarSymbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
410 |
return visitSymbol(s, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
411 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
412 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
413 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
414 |
public String visitSymbol(Symbol s, Locale locale) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
415 |
return s.name.toString(); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
416 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
diff
changeset
|
417 |
} |