author | ohair |
Tue, 25 May 2010 15:54:51 -0700 | |
changeset 5520 | 86e4b9a9da40 |
parent 3995 | 73af8b6fb8bc |
child 5847 | 1908176fd6e3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
28 |
import java.util.Locale; |
|
29 |
import java.util.Map; |
|
30 |
||
31 |
import javax.tools.Diagnostic; |
|
32 |
import javax.tools.JavaFileObject; |
|
33 |
||
942 | 34 |
import com.sun.tools.javac.api.DiagnosticFormatter; |
10 | 35 |
import com.sun.tools.javac.tree.JCTree; |
36 |
||
37 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; |
|
38 |
||
39 |
/** An abstraction of a diagnostic message generated by the compiler. |
|
40 |
* |
|
41 |
* <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
42 |
* you write code that depends on this, you do so at your own risk. |
|
43 |
* This code and its internal interfaces are subject to change or |
|
44 |
* deletion without notice.</b> |
|
45 |
*/ |
|
46 |
public class JCDiagnostic implements Diagnostic<JavaFileObject> { |
|
47 |
/** A factory for creating diagnostic objects. */ |
|
48 |
public static class Factory { |
|
49 |
/** The context key for the diagnostic factory. */ |
|
50 |
protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey = |
|
51 |
new Context.Key<JCDiagnostic.Factory>(); |
|
52 |
||
53 |
/** Get the Factory instance for this context. */ |
|
54 |
public static Factory instance(Context context) { |
|
55 |
Factory instance = context.get(diagnosticFactoryKey); |
|
56 |
if (instance == null) |
|
57 |
instance = new Factory(context); |
|
58 |
return instance; |
|
59 |
} |
|
60 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
61 |
DiagnosticFormatter<JCDiagnostic> formatter; |
10 | 62 |
final String prefix; |
63 |
||
64 |
/** Create a new diagnostic factory. */ |
|
65 |
protected Factory(Context context) { |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
66 |
this(JavacMessages.instance(context), "compiler"); |
10 | 67 |
context.put(diagnosticFactoryKey, this); |
68 |
} |
|
69 |
||
70 |
/** Create a new diagnostic factory. */ |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
71 |
public Factory(JavacMessages messages, String prefix) { |
10 | 72 |
this.prefix = prefix; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
73 |
this.formatter = new BasicDiagnosticFormatter(messages); |
10 | 74 |
} |
75 |
||
76 |
/** |
|
77 |
* Create an error diagnostic. |
|
78 |
* @param source The source of the compilation unit, if any, in which to report the error. |
|
79 |
* @param pos The source position at which to report the error. |
|
80 |
* @param key The key for the localized error message. |
|
81 |
* @param args Fields of the error message. |
|
82 |
*/ |
|
83 |
public JCDiagnostic error( |
|
84 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
85 |
return create(ERROR, true, source, pos, key, args); |
10 | 86 |
} |
87 |
||
88 |
/** |
|
89 |
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
|
90 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
|
91 |
* @param pos The source position at which to report the warning. |
|
92 |
* @param key The key for the localized error message. |
|
93 |
* @param args Fields of the error message. |
|
94 |
* @see MandatoryWarningHandler |
|
95 |
*/ |
|
96 |
public JCDiagnostic mandatoryWarning( |
|
97 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
98 |
return create(WARNING, true, source, pos, key, args); |
10 | 99 |
} |
100 |
||
101 |
/** |
|
102 |
* Create a warning diagnostic. |
|
103 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
|
104 |
* @param pos The source position at which to report the warning. |
|
105 |
* @param key The key for the localized error message. |
|
106 |
* @param args Fields of the error message. |
|
107 |
*/ |
|
108 |
public JCDiagnostic warning( |
|
109 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
110 |
return create(WARNING, false, source, pos, key, args); |
10 | 111 |
} |
112 |
||
113 |
/** |
|
114 |
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
|
115 |
* @param key The key for the localized error message. |
|
116 |
* @param args Fields of the error message. |
|
117 |
* @see MandatoryWarningHandler |
|
118 |
*/ |
|
119 |
public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
120 |
return create(NOTE, true, source, null, key, args); |
10 | 121 |
} |
122 |
||
123 |
/** |
|
124 |
* Create a note diagnostic. |
|
125 |
* @param key The key for the localized error message. |
|
126 |
* @param args Fields of the error message. |
|
127 |
*/ |
|
128 |
public JCDiagnostic note(String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
129 |
return create(NOTE, false, null, null, key, args); |
10 | 130 |
} |
131 |
||
132 |
/** |
|
133 |
* Create a note diagnostic. |
|
134 |
* @param source The source of the compilation unit, if any, in which to report the note. |
|
135 |
* @param pos The source position at which to report the note. |
|
136 |
* @param key The key for the localized error message. |
|
137 |
* @param args Fields of the error message. |
|
138 |
*/ |
|
139 |
public JCDiagnostic note( |
|
140 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
141 |
return create(NOTE, false, source, pos, key, args); |
10 | 142 |
} |
143 |
||
144 |
/** |
|
145 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
|
146 |
* @param key The key for the localized error message. |
|
147 |
* @param args Fields of the error message. |
|
148 |
*/ |
|
149 |
public JCDiagnostic fragment(String key, Object... args) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
150 |
return create(FRAGMENT, false, null, null, key, args); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
151 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
152 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
153 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
154 |
* Create a new diagnostic of the given kind. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
155 |
* @param kind The diagnostic kind |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
156 |
* @param isMandatory is diagnostic mandatory? |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
157 |
* @param source The source of the compilation unit, if any, in which to report the note. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
158 |
* @param pos The source position at which to report the note. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
159 |
* @param key The key for the localized error message. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
160 |
* @param args Fields of the error message. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
161 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
162 |
public JCDiagnostic create( |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
163 |
DiagnosticType kind, boolean isMandatory, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
164 |
return new JCDiagnostic(formatter, kind, isMandatory, source, pos, qualify(kind, key), args); |
10 | 165 |
} |
166 |
||
167 |
protected String qualify(DiagnosticType t, String key) { |
|
168 |
return prefix + "." + t.key + "." + key; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
||
173 |
||
174 |
/** |
|
175 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
|
176 |
* @param key The key for the localized error message. |
|
177 |
* @param args Fields of the error message. |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
178 |
* |
10 | 179 |
*/ |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
180 |
@Deprecated |
10 | 181 |
public static JCDiagnostic fragment(String key, Object... args) { |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
182 |
return new JCDiagnostic(getFragmentFormatter(), |
10 | 183 |
FRAGMENT, |
184 |
false, |
|
185 |
null, |
|
186 |
null, |
|
187 |
"compiler." + FRAGMENT.key + "." + key, |
|
188 |
args); |
|
189 |
} |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
190 |
//where |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
191 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
192 |
public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() { |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
193 |
if (fragmentFormatter == null) { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
194 |
fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages()); |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
195 |
} |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
196 |
return fragmentFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
197 |
} |
10 | 198 |
|
199 |
/** |
|
200 |
* A DiagnosticType defines the type of the diagnostic. |
|
201 |
**/ |
|
202 |
public enum DiagnosticType { |
|
203 |
/** A fragment of an enclosing diagnostic. */ |
|
204 |
FRAGMENT("misc"), |
|
205 |
/** A note: similar to, but less serious than, a warning. */ |
|
206 |
NOTE("note"), |
|
207 |
/** A warning. */ |
|
208 |
WARNING("warn"), |
|
209 |
/** An error. */ |
|
210 |
ERROR("err"); |
|
211 |
||
212 |
final String key; |
|
213 |
||
214 |
/** Create a DiagnosticType. |
|
215 |
* @param key A string used to create the resource key for the diagnostic. |
|
216 |
*/ |
|
217 |
DiagnosticType(String key) { |
|
218 |
this.key = key; |
|
219 |
} |
|
220 |
}; |
|
221 |
||
222 |
/** |
|
223 |
* A DiagnosticPosition provides information about the positions in a file |
|
224 |
* that gave rise to a diagnostic. It always defines a "preferred" position |
|
225 |
* that most accurately defines the location of the diagnostic, it may also |
|
226 |
* provide a related tree node that spans that location. |
|
227 |
*/ |
|
228 |
public static interface DiagnosticPosition { |
|
229 |
/** Gets the tree node, if any, to which the diagnostic applies. */ |
|
230 |
JCTree getTree(); |
|
231 |
/** If there is a tree node, get the start position of the tree node. |
|
232 |
* Otherwise, just returns the same as getPreferredPosition(). */ |
|
233 |
int getStartPosition(); |
|
234 |
/** Get the position within the file that most accurately defines the |
|
235 |
* location for the diagnostic. */ |
|
236 |
int getPreferredPosition(); |
|
237 |
/** If there is a tree node, and if endPositions are available, get |
|
238 |
* the end position of the tree node. Otherwise, just returns the |
|
239 |
* same as getPreferredPosition(). */ |
|
240 |
int getEndPosition(Map<JCTree, Integer> endPosTable); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* A DiagnosticPosition that simply identifies a position, but no related |
|
245 |
* tree node, as the location for a diagnostic. Used for scanner and parser |
|
246 |
* diagnostics. */ |
|
247 |
public static class SimpleDiagnosticPosition implements DiagnosticPosition { |
|
248 |
public SimpleDiagnosticPosition(int pos) { |
|
249 |
this.pos = pos; |
|
250 |
} |
|
251 |
||
252 |
public JCTree getTree() { |
|
253 |
return null; |
|
254 |
} |
|
255 |
||
256 |
public int getStartPosition() { |
|
257 |
return pos; |
|
258 |
} |
|
259 |
||
260 |
public int getPreferredPosition() { |
|
261 |
return pos; |
|
262 |
} |
|
263 |
||
264 |
public int getEndPosition(Map<JCTree, Integer> endPosTable) { |
|
265 |
return pos; |
|
266 |
} |
|
267 |
||
268 |
private final int pos; |
|
269 |
} |
|
270 |
||
271 |
private final DiagnosticType type; |
|
272 |
private final DiagnosticSource source; |
|
273 |
private final DiagnosticPosition position; |
|
274 |
private final int line; |
|
275 |
private final int column; |
|
276 |
private final String key; |
|
942 | 277 |
protected Object[] args; |
10 | 278 |
private boolean mandatory; |
279 |
||
280 |
/** |
|
281 |
* Create a diagnostic object. |
|
282 |
* @param messages the resource for localized messages |
|
283 |
* @param dt the type of diagnostic |
|
284 |
* @param name the name of the source file, or null if none. |
|
285 |
* @param pos the character offset within the source file, if given. |
|
286 |
* @param key a resource key to identify the text of the diagnostic |
|
287 |
* @param args arguments to be included in the text of the diagnostic |
|
288 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
289 |
protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter, |
10 | 290 |
DiagnosticType dt, |
291 |
boolean mandatory, |
|
292 |
DiagnosticSource source, |
|
293 |
DiagnosticPosition pos, |
|
294 |
String key, |
|
295 |
Object ... args) { |
|
296 |
if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) |
|
297 |
throw new IllegalArgumentException(); |
|
298 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
299 |
this.defaultFormatter = formatter; |
10 | 300 |
this.type = dt; |
301 |
this.mandatory = mandatory; |
|
302 |
this.source = source; |
|
303 |
this.position = pos; |
|
304 |
this.key = key; |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
305 |
this.args = args; |
10 | 306 |
|
307 |
int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); |
|
308 |
if (n == Position.NOPOS || source == null) |
|
309 |
line = column = -1; |
|
310 |
else { |
|
311 |
line = source.getLineNumber(n); |
|
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
1040
diff
changeset
|
312 |
column = source.getColumnNumber(n, true); |
10 | 313 |
} |
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Get the type of this diagnostic. |
|
318 |
* @return the type of this diagnostic |
|
319 |
*/ |
|
320 |
public DiagnosticType getType() { |
|
321 |
return type; |
|
322 |
} |
|
323 |
||
324 |
/** |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
325 |
* Get the subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
326 |
* @return subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
327 |
*/ |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
328 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
329 |
return List.nil(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
330 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
331 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
332 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
333 |
return false; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
334 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
335 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
336 |
/** |
10 | 337 |
* Check whether or not this diagnostic is required to be shown. |
338 |
* @return true if this diagnostic is required to be shown. |
|
339 |
*/ |
|
340 |
public boolean isMandatory() { |
|
341 |
return mandatory; |
|
342 |
} |
|
343 |
||
344 |
/** |
|
345 |
* Get the name of the source file referred to by this diagnostic. |
|
346 |
* @return the name of the source referred to with this diagnostic, or null if none |
|
347 |
*/ |
|
348 |
public JavaFileObject getSource() { |
|
349 |
if (source == null) |
|
350 |
return null; |
|
351 |
else |
|
352 |
return source.getFile(); |
|
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* Get the source referred to by this diagnostic. |
|
357 |
* @return the source referred to with this diagnostic, or null if none |
|
358 |
*/ |
|
359 |
public DiagnosticSource getDiagnosticSource() { |
|
360 |
return source; |
|
361 |
} |
|
362 |
||
363 |
protected int getIntStartPosition() { |
|
364 |
return (position == null ? Position.NOPOS : position.getStartPosition()); |
|
365 |
} |
|
366 |
||
367 |
protected int getIntPosition() { |
|
368 |
return (position == null ? Position.NOPOS : position.getPreferredPosition()); |
|
369 |
} |
|
370 |
||
371 |
protected int getIntEndPosition() { |
|
372 |
return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable())); |
|
373 |
} |
|
374 |
||
375 |
public long getStartPosition() { |
|
376 |
return getIntStartPosition(); |
|
377 |
} |
|
378 |
||
379 |
public long getPosition() { |
|
380 |
return getIntPosition(); |
|
381 |
} |
|
382 |
||
383 |
public long getEndPosition() { |
|
384 |
return getIntEndPosition(); |
|
385 |
} |
|
386 |
||
387 |
/** |
|
388 |
* Get the line number within the source referred to by this diagnostic. |
|
389 |
* @return the line number within the source referred to by this diagnostic |
|
390 |
*/ |
|
391 |
public long getLineNumber() { |
|
392 |
return line; |
|
393 |
} |
|
394 |
||
395 |
/** |
|
396 |
* Get the column number within the line of source referred to by this diagnostic. |
|
397 |
* @return the column number within the line of source referred to by this diagnostic |
|
398 |
*/ |
|
399 |
public long getColumnNumber() { |
|
400 |
return column; |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Get the arguments to be included in the text of the diagnostic. |
|
405 |
* @return the arguments to be included in the text of the diagnostic |
|
406 |
*/ |
|
407 |
public Object[] getArgs() { |
|
408 |
return args; |
|
409 |
} |
|
410 |
||
411 |
/** |
|
412 |
* Get the prefix string associated with this type of diagnostic. |
|
413 |
* @return the prefix string associated with this type of diagnostic |
|
414 |
*/ |
|
415 |
public String getPrefix() { |
|
416 |
return getPrefix(type); |
|
417 |
} |
|
418 |
||
419 |
/** |
|
420 |
* Get the prefix string associated with a particular type of diagnostic. |
|
421 |
* @return the prefix string associated with a particular type of diagnostic |
|
422 |
*/ |
|
423 |
public String getPrefix(DiagnosticType dt) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
424 |
return defaultFormatter.formatKind(this, Locale.getDefault()); |
942 | 425 |
} |
426 |
||
10 | 427 |
/** |
428 |
* Return the standard presentation of this diagnostic. |
|
429 |
*/ |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3143
diff
changeset
|
430 |
@Override |
10 | 431 |
public String toString() { |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
432 |
return defaultFormatter.format(this,Locale.getDefault()); |
10 | 433 |
} |
434 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
435 |
private DiagnosticFormatter<JCDiagnostic> defaultFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
436 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
437 |
private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter; |
10 | 438 |
|
439 |
// Methods for javax.tools.Diagnostic |
|
440 |
||
441 |
public Diagnostic.Kind getKind() { |
|
442 |
switch (type) { |
|
443 |
case NOTE: |
|
444 |
return Diagnostic.Kind.NOTE; |
|
445 |
case WARNING: |
|
446 |
return mandatory ? Diagnostic.Kind.MANDATORY_WARNING |
|
447 |
: Diagnostic.Kind.WARNING; |
|
448 |
case ERROR: |
|
449 |
return Diagnostic.Kind.ERROR; |
|
450 |
default: |
|
451 |
return Diagnostic.Kind.OTHER; |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
public String getCode() { |
|
456 |
return key; |
|
457 |
} |
|
458 |
||
459 |
public String getMessage(Locale locale) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
460 |
return defaultFormatter.formatMessage(this, locale); |
10 | 461 |
} |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
462 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
463 |
public static class MultilineDiagnostic extends JCDiagnostic { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
464 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
465 |
private final List<JCDiagnostic> subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
466 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
467 |
public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
468 |
super(other.defaultFormatter, |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
469 |
other.getType(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
470 |
other.isMandatory(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
471 |
other.getDiagnosticSource(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
472 |
other.position, |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
473 |
other.getCode(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
474 |
other.getArgs()); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
475 |
this.subdiagnostics = subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
476 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
477 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
478 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
479 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
480 |
return subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
481 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
482 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
483 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
484 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
485 |
return true; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
486 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
487 |
} |
10 | 488 |
} |