author | asaha |
Tue, 14 Jan 2014 08:08:32 -0800 | |
changeset 22449 | 1fd6d4bec7dd |
parent 22163 | 3651128c74eb |
parent 22448 | a85fbad9d687 |
permissions | -rw-r--r-- |
942 | 1 |
/* |
22448
a85fbad9d687
8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
ksrini
parents:
15724
diff
changeset
|
2 |
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. |
942 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
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 |
942 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
942 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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. |
|
942 | 24 |
*/ |
25 |
package com.sun.tools.javac.util; |
|
26 |
||
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
27 |
import java.util.Arrays; |
942 | 28 |
import java.util.Collection; |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
29 |
import java.util.EnumSet; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
30 |
import java.util.HashMap; |
942 | 31 |
import java.util.Locale; |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
32 |
import java.util.Map; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
33 |
import java.util.Set; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14259
diff
changeset
|
34 |
|
942 | 35 |
import javax.tools.JavaFileObject; |
36 |
||
37 |
import com.sun.tools.javac.api.DiagnosticFormatter; |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
38 |
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
39 |
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
40 |
import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind; |
942 | 41 |
import com.sun.tools.javac.api.Formattable; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
42 |
import com.sun.tools.javac.code.Lint.LintCategory; |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
43 |
import com.sun.tools.javac.code.Printer; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
44 |
import com.sun.tools.javac.code.Symbol; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
45 |
import com.sun.tools.javac.code.Type; |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
46 |
import com.sun.tools.javac.code.Type.CapturedType; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14259
diff
changeset
|
47 |
import com.sun.tools.javac.file.BaseFileObject; |
15724 | 48 |
import com.sun.tools.javac.jvm.Profile; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
49 |
import com.sun.tools.javac.tree.JCTree.*; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
50 |
import com.sun.tools.javac.tree.Pretty; |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
51 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; |
942 | 52 |
|
53 |
/** |
|
54 |
* This abstract class provides a basic implementation of the functionalities that should be provided |
|
55 |
* by any formatter used by javac. Among the main features provided by AbstractDiagnosticFormatter are: |
|
56 |
* |
|
57 |
* <ul> |
|
58 |
* <li> Provides a standard implementation of the visitor-like methods defined in the interface DiagnisticFormatter. |
|
59 |
* Those implementations are specifically targeting JCDiagnostic objects. |
|
60 |
* <li> Provides basic support for i18n and a method for executing all locale-dependent conversions |
|
61 |
* <li> Provides the formatting logic for rendering the arguments of a JCDiagnostic object. |
|
62 |
* <ul> |
|
63 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
64 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
3145
diff
changeset
|
65 |
* 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:
3145
diff
changeset
|
66 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
3145
diff
changeset
|
67 |
* deletion without notice.</b> |
942 | 68 |
*/ |
69 |
public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter<JCDiagnostic> { |
|
70 |
||
71 |
/** |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
72 |
* JavacMessages object used by this formatter for i18n. |
942 | 73 |
*/ |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
74 |
protected JavacMessages messages; |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
75 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
76 |
/** |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
77 |
* Configuration object used by this formatter |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
78 |
*/ |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
79 |
private SimpleConfiguration config; |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
80 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
81 |
/** |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
82 |
* Current depth level of the disgnostic being formatted |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
83 |
* (!= 0 for subdiagnostics) |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
84 |
*/ |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
85 |
protected int depth = 0; |
942 | 86 |
|
87 |
/** |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
88 |
* All captured types that have been encountered during diagnostic formatting. |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
89 |
* This info is used by the FormatterPrinter in order to print friendly unique |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
90 |
* ids for captured types |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
91 |
*/ |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
92 |
private List<Type> allCaptured = List.nil(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
93 |
|
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
94 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
95 |
* Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object. |
942 | 96 |
* @param messages |
97 |
*/ |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
98 |
protected AbstractDiagnosticFormatter(JavacMessages messages, SimpleConfiguration config) { |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
99 |
this.messages = messages; |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
100 |
this.config = config; |
942 | 101 |
} |
102 |
||
103 |
public String formatKind(JCDiagnostic d, Locale l) { |
|
104 |
switch (d.getType()) { |
|
105 |
case FRAGMENT: return ""; |
|
106 |
case NOTE: return localize(l, "compiler.note.note"); |
|
107 |
case WARNING: return localize(l, "compiler.warn.warning"); |
|
108 |
case ERROR: return localize(l, "compiler.err.error"); |
|
109 |
default: |
|
110 |
throw new AssertionError("Unknown diagnostic type: " + d.getType()); |
|
111 |
} |
|
112 |
} |
|
113 |
||
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
114 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
115 |
public String format(JCDiagnostic d, Locale locale) { |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
116 |
allCaptured = List.nil(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
117 |
return formatDiagnostic(d, locale); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
118 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
119 |
|
3145
5300990c95bd
6852649: The Rich formatter printer should be an explicit class to facilitate overriding
mcimadamore
parents:
3137
diff
changeset
|
120 |
protected abstract String formatDiagnostic(JCDiagnostic d, Locale locale); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
121 |
|
942 | 122 |
public String formatPosition(JCDiagnostic d, PositionKind pk,Locale l) { |
8032 | 123 |
Assert.check(d.getPosition() != Position.NOPOS); |
942 | 124 |
return String.valueOf(getPosition(d, pk)); |
125 |
} |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
126 |
//where |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
127 |
private long getPosition(JCDiagnostic d, PositionKind pk) { |
942 | 128 |
switch (pk) { |
129 |
case START: return d.getIntStartPosition(); |
|
130 |
case END: return d.getIntEndPosition(); |
|
131 |
case LINE: return d.getLineNumber(); |
|
132 |
case COLUMN: return d.getColumnNumber(); |
|
133 |
case OFFSET: return d.getIntPosition(); |
|
134 |
default: |
|
135 |
throw new AssertionError("Unknown diagnostic position: " + pk); |
|
136 |
} |
|
137 |
} |
|
138 |
||
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
942
diff
changeset
|
139 |
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) { |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
140 |
JavaFileObject fo = d.getSource(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
141 |
if (fo == null) |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
142 |
throw new IllegalArgumentException(); // d should have source set |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
143 |
if (fullname) |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
144 |
return fo.getName(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
145 |
else if (fo instanceof BaseFileObject) |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
146 |
return ((BaseFileObject) fo).getShortName(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
147 |
else |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
148 |
return BaseFileObject.getSimpleName(fo); |
942 | 149 |
} |
150 |
||
151 |
/** |
|
152 |
* Format the arguments of a given diagnostic. |
|
153 |
* |
|
154 |
* @param d diagnostic whose arguments are to be formatted |
|
155 |
* @param l locale object to be used for i18n |
|
156 |
* @return a Collection whose elements are the formatted arguments of the diagnostic |
|
157 |
*/ |
|
158 |
protected Collection<String> formatArguments(JCDiagnostic d, Locale l) { |
|
22163 | 159 |
ListBuffer<String> buf = new ListBuffer<>(); |
942 | 160 |
for (Object o : d.getArgs()) { |
161 |
buf.append(formatArgument(d, o, l)); |
|
162 |
} |
|
163 |
return buf.toList(); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Format a single argument of a given diagnostic. |
|
168 |
* |
|
169 |
* @param d diagnostic whose argument is to be formatted |
|
170 |
* @param arg argument to be formatted |
|
171 |
* @param l locale object to be used for i18n |
|
172 |
* @return string representation of the diagnostic argument |
|
173 |
*/ |
|
174 |
protected String formatArgument(JCDiagnostic d, Object arg, Locale l) { |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
175 |
if (arg instanceof JCDiagnostic) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
176 |
String s = null; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
177 |
depth++; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
178 |
try { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
179 |
s = formatMessage((JCDiagnostic)arg, l); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
180 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
181 |
finally { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
182 |
depth--; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
183 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
184 |
return s; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
185 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
186 |
else if (arg instanceof JCExpression) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
187 |
return expr2String((JCExpression)arg); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
188 |
} |
942 | 189 |
else if (arg instanceof Iterable<?>) { |
190 |
return formatIterable(d, (Iterable<?>)arg, l); |
|
191 |
} |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
192 |
else if (arg instanceof Type) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
193 |
return printer.visit((Type)arg, l); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
194 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
195 |
else if (arg instanceof Symbol) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
196 |
return printer.visit((Symbol)arg, l); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
197 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
198 |
else if (arg instanceof JavaFileObject) { |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3380
diff
changeset
|
199 |
return ((JavaFileObject)arg).getName(); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
200 |
} |
15724 | 201 |
else if (arg instanceof Profile) { |
202 |
return ((Profile)arg).name; |
|
203 |
} |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
204 |
else if (arg instanceof Formattable) { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
205 |
return ((Formattable)arg).toString(l, messages); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
206 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
207 |
else { |
942 | 208 |
return String.valueOf(arg); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
209 |
} |
942 | 210 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
211 |
//where |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
212 |
private String expr2String(JCExpression tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
213 |
switch(tree.getTag()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
214 |
case PARENS: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
215 |
return expr2String(((JCParens)tree).expr); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
216 |
case LAMBDA: |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
217 |
case REFERENCE: |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
218 |
case CONDEXPR: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
219 |
return Pretty.toSimpleString(tree); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
220 |
default: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
221 |
Assert.error("unexpected tree kind " + tree.getKind()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
222 |
return null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
223 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
224 |
} |
942 | 225 |
|
226 |
/** |
|
227 |
* Format an iterable argument of a given diagnostic. |
|
228 |
* |
|
229 |
* @param d diagnostic whose argument is to be formatted |
|
230 |
* @param it iterable argument to be formatted |
|
231 |
* @param l locale object to be used for i18n |
|
232 |
* @return string representation of the diagnostic iterable argument |
|
233 |
*/ |
|
234 |
protected String formatIterable(JCDiagnostic d, Iterable<?> it, Locale l) { |
|
235 |
StringBuilder sbuf = new StringBuilder(); |
|
236 |
String sep = ""; |
|
237 |
for (Object o : it) { |
|
238 |
sbuf.append(sep); |
|
239 |
sbuf.append(formatArgument(d, o, l)); |
|
240 |
sep = ","; |
|
241 |
} |
|
242 |
return sbuf.toString(); |
|
243 |
} |
|
244 |
||
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
245 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
246 |
* Format all the subdiagnostics attached to a given diagnostic. |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
247 |
* |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
248 |
* @param d diagnostic whose subdiagnostics are to be formatted |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
249 |
* @param l locale object to be used for i18n |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
250 |
* @return list of all string representations of the subdiagnostics |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
251 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
252 |
protected List<String> formatSubdiagnostics(JCDiagnostic d, Locale l) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
253 |
List<String> subdiagnostics = List.nil(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
254 |
int maxDepth = config.getMultilineLimit(MultilineLimit.DEPTH); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
255 |
if (maxDepth == -1 || depth < maxDepth) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
256 |
depth++; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
257 |
try { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
258 |
int maxCount = config.getMultilineLimit(MultilineLimit.LENGTH); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
259 |
int count = 0; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
260 |
for (JCDiagnostic d2 : d.getSubdiagnostics()) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
261 |
if (maxCount == -1 || count < maxCount) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
262 |
subdiagnostics = subdiagnostics.append(formatSubdiagnostic(d, d2, l)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
263 |
count++; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
264 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
265 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
266 |
break; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
267 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
268 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
269 |
finally { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
270 |
depth--; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
271 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
272 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
273 |
return subdiagnostics; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
274 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
275 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
276 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
277 |
* Format a subdiagnostics attached to a given diagnostic. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
278 |
* |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
279 |
* @param parent multiline diagnostic whose subdiagnostics is to be formatted |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
280 |
* @param sub subdiagnostic to be formatted |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
281 |
* @param l locale object to be used for i18n |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
282 |
* @return string representation of the subdiagnostics |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
283 |
*/ |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
284 |
protected String formatSubdiagnostic(JCDiagnostic parent, JCDiagnostic sub, Locale l) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
285 |
return formatMessage(sub, l); |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
286 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
287 |
|
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
288 |
/** Format the faulty source code line and point to the error. |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
289 |
* @param d The diagnostic for which the error line should be printed |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
290 |
*/ |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
291 |
protected String formatSourceLine(JCDiagnostic d, int nSpaces) { |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
292 |
StringBuilder buf = new StringBuilder(); |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
293 |
DiagnosticSource source = d.getDiagnosticSource(); |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
294 |
int pos = d.getIntPosition(); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
295 |
if (d.getIntPosition() == Position.NOPOS) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
296 |
throw new AssertionError(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
297 |
String line = (source == null ? null : source.getLine(pos)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
298 |
if (line == null) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
299 |
return ""; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
300 |
buf.append(indent(line, nSpaces)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
301 |
int col = source.getColumnNumber(pos, false); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
302 |
if (config.isCaretEnabled()) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
303 |
buf.append("\n"); |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
304 |
for (int i = 0; i < col - 1; i++) { |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
305 |
buf.append((line.charAt(i) == '\t') ? "\t" : " "); |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
306 |
} |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
307 |
buf.append(indent("^", nSpaces)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
308 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
309 |
return buf.toString(); |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
310 |
} |
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
311 |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
312 |
protected String formatLintCategory(JCDiagnostic d, Locale l) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
313 |
LintCategory lc = d.getLintCategory(); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
314 |
if (lc == null) |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
315 |
return ""; |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
316 |
return localize(l, "compiler.warn.lintOption", lc.option); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
317 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
318 |
|
942 | 319 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
320 |
* Converts a String into a locale-dependent representation accordingly to a given locale. |
942 | 321 |
* |
322 |
* @param l locale object to be used for i18n |
|
323 |
* @param key locale-independent key used for looking up in a resource file |
|
324 |
* @param args localization arguments |
|
325 |
* @return a locale-dependent string |
|
326 |
*/ |
|
327 |
protected String localize(Locale l, String key, Object... args) { |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
328 |
return messages.getLocalizedString(l, key, args); |
942 | 329 |
} |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
330 |
|
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
331 |
public boolean displaySource(JCDiagnostic d) { |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
332 |
return config.getVisible().contains(DiagnosticPart.SOURCE) && |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
333 |
d.getType() != FRAGMENT && |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
334 |
d.getIntPosition() != Position.NOPOS; |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
335 |
} |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
336 |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
337 |
public boolean isRaw() { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
338 |
return false; |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
339 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
340 |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
341 |
/** |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
342 |
* Creates a string with a given amount of empty spaces. Useful for |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
343 |
* indenting the text of a diagnostic message. |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
344 |
* |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
345 |
* @param nSpaces the amount of spaces to be added to the result string |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
346 |
* @return the indentation string |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
347 |
*/ |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
348 |
protected String indentString(int nSpaces) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
349 |
String spaces = " "; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
350 |
if (nSpaces <= spaces.length()) |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
351 |
return spaces.substring(0, nSpaces); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
352 |
else { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
353 |
StringBuilder buf = new StringBuilder(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
354 |
for (int i = 0 ; i < nSpaces ; i++) |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
355 |
buf.append(" "); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
356 |
return buf.toString(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
357 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
358 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
359 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
360 |
/** |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
361 |
* Indent a string by prepending a given amount of empty spaces to each line |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
362 |
* of the string. |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
363 |
* |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
364 |
* @param s the string to be indented |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
365 |
* @param nSpaces the amount of spaces that should be prepended to each line |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
366 |
* of the string |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
367 |
* @return an indented string |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
368 |
*/ |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
369 |
protected String indent(String s, int nSpaces) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
370 |
String indent = indentString(nSpaces); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
371 |
StringBuilder buf = new StringBuilder(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
372 |
String nl = ""; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
373 |
for (String line : s.split("\n")) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
374 |
buf.append(nl); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
375 |
buf.append(indent + line); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
376 |
nl = "\n"; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
377 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
378 |
return buf.toString(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
379 |
} |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
380 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
381 |
public SimpleConfiguration getConfiguration() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
382 |
return config; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
383 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
384 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
385 |
static public class SimpleConfiguration implements Configuration { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
386 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
387 |
protected Map<MultilineLimit, Integer> multilineLimits; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
388 |
protected EnumSet<DiagnosticPart> visibleParts; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
389 |
protected boolean caretEnabled; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
390 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
391 |
public SimpleConfiguration(Set<DiagnosticPart> parts) { |
22163 | 392 |
multilineLimits = new HashMap<>(); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
393 |
setVisible(parts); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
394 |
setMultilineLimit(MultilineLimit.DEPTH, -1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
395 |
setMultilineLimit(MultilineLimit.LENGTH, -1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
396 |
setCaretEnabled(true); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
397 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
398 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
399 |
@SuppressWarnings("fallthrough") |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
400 |
public SimpleConfiguration(Options options, Set<DiagnosticPart> parts) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
401 |
this(parts); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
402 |
String showSource = null; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
403 |
if ((showSource = options.get("showSource")) != null) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
404 |
if (showSource.equals("true")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
405 |
setVisiblePart(DiagnosticPart.SOURCE, true); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
406 |
else if (showSource.equals("false")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
407 |
setVisiblePart(DiagnosticPart.SOURCE, false); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
408 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
409 |
String diagOpts = options.get("diags"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
410 |
if (diagOpts != null) {//override -XDshowSource |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
411 |
Collection<String> args = Arrays.asList(diagOpts.split(",")); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
412 |
if (args.contains("short")) { |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
413 |
setVisiblePart(DiagnosticPart.DETAILS, false); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
414 |
setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
415 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
416 |
if (args.contains("source")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
417 |
setVisiblePart(DiagnosticPart.SOURCE, true); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
418 |
if (args.contains("-source")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
419 |
setVisiblePart(DiagnosticPart.SOURCE, false); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
420 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
421 |
String multiPolicy = null; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
422 |
if ((multiPolicy = options.get("multilinePolicy")) != null) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
423 |
if (multiPolicy.equals("disabled")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
424 |
setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
425 |
else if (multiPolicy.startsWith("limit:")) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
426 |
String limitString = multiPolicy.substring("limit:".length()); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
427 |
String[] limits = limitString.split(":"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
428 |
try { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
429 |
switch (limits.length) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
430 |
case 2: { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
431 |
if (!limits[1].equals("*")) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
432 |
setMultilineLimit(MultilineLimit.DEPTH, Integer.parseInt(limits[1])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
433 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
434 |
case 1: { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
435 |
if (!limits[0].equals("*")) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
436 |
setMultilineLimit(MultilineLimit.LENGTH, Integer.parseInt(limits[0])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
437 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
438 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
439 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
440 |
catch(NumberFormatException ex) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
441 |
setMultilineLimit(MultilineLimit.DEPTH, -1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
442 |
setMultilineLimit(MultilineLimit.LENGTH, -1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
443 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
444 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
445 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
446 |
String showCaret = null; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
447 |
if (((showCaret = options.get("showCaret")) != null) && |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
448 |
showCaret.equals("false")) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
449 |
setCaretEnabled(false); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
450 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
451 |
setCaretEnabled(true); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
452 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
453 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
454 |
public int getMultilineLimit(MultilineLimit limit) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
455 |
return multilineLimits.get(limit); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
456 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
457 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
458 |
public EnumSet<DiagnosticPart> getVisible() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
459 |
return EnumSet.copyOf(visibleParts); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
460 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
461 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
462 |
public void setMultilineLimit(MultilineLimit limit, int value) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
463 |
multilineLimits.put(limit, value < -1 ? -1 : value); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
464 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
465 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
466 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
467 |
public void setVisible(Set<DiagnosticPart> diagParts) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
468 |
visibleParts = EnumSet.copyOf(diagParts); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
469 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
470 |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
471 |
public void setVisiblePart(DiagnosticPart diagParts, boolean enabled) { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
472 |
if (enabled) |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
473 |
visibleParts.add(diagParts); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
474 |
else |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
475 |
visibleParts.remove(diagParts); |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
476 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
477 |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
478 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
479 |
* Shows a '^' sign under the source line displayed by the formatter |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
480 |
* (if applicable). |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
481 |
* |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
482 |
* @param caretEnabled if true enables caret |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
483 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
484 |
public void setCaretEnabled(boolean caretEnabled) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
485 |
this.caretEnabled = caretEnabled; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
486 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
487 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
488 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
489 |
* Tells whether the caret display is active or not. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
490 |
* |
14259 | 491 |
* @return true if the caret is enabled |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
492 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
493 |
public boolean isCaretEnabled() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
494 |
return caretEnabled; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
495 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1591
diff
changeset
|
496 |
} |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
497 |
|
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
498 |
public Printer getPrinter() { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
499 |
return printer; |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
500 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
501 |
|
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
502 |
public void setPrinter(Printer printer) { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
503 |
this.printer = printer; |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
504 |
} |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
505 |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
506 |
/** |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
507 |
* An enhanced printer for formatting types/symbols used by |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
508 |
* AbstractDiagnosticFormatter. Provides alternate numbering of captured |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
509 |
* types (they are numbered starting from 1 on each new diagnostic, instead |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
510 |
* of relying on the underlying hashcode() method which generates unstable |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
511 |
* output). Also detects cycles in wildcard messages (e.g. if the wildcard |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
512 |
* type referred by a given captured type C contains C itself) which might |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
513 |
* lead to infinite loops. |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
514 |
*/ |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
515 |
protected Printer printer = new Printer() { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
8032
diff
changeset
|
516 |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
517 |
@Override |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
518 |
protected String localize(Locale locale, String key, Object... args) { |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
519 |
return AbstractDiagnosticFormatter.this.localize(locale, key, args); |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
520 |
} |
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
521 |
@Override |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
522 |
protected String capturedVarId(CapturedType t, Locale locale) { |
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
523 |
return "" + (allCaptured.indexOf(t) + 1); |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
524 |
} |
3137
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
525 |
@Override |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
526 |
public String visitCapturedType(CapturedType t, Locale locale) { |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
527 |
if (!allCaptured.contains(t)) { |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
528 |
allCaptured = allCaptured.append(t); |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
529 |
} |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
530 |
return super.visitCapturedType(t, locale); |
a8590199a00e
6845686: basic and raw formatters do not display captured var id properly when javac runs in -XDoldDiags mode
mcimadamore
parents:
2984
diff
changeset
|
531 |
} |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
532 |
}; |
942 | 533 |
} |