author | jjg |
Tue, 16 Sep 2008 18:35:18 -0700 | |
changeset 1260 | a772ba9ba43d |
parent 1109 | 853d8c191eac |
child 1471 | 57506cdfb7b4 |
permissions | -rw-r--r-- |
942 | 1 |
/* |
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package com.sun.tools.javac.util; |
|
26 |
||
27 |
import java.util.Locale; |
|
28 |
||
29 |
import com.sun.tools.javac.api.Formattable; |
|
30 |
import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*; |
|
31 |
||
32 |
/** |
|
33 |
* A raw formatter for diagnostic messages. |
|
34 |
* The raw formatter will format a diagnostic according to one of two format patterns, depending on whether |
|
35 |
* or not the source name and position are set. This formatter provides a standardized, localize-independent |
|
36 |
* implementation of a diagnostic formatter; as such, this formatter is best suited for testing purposes. |
|
37 |
*/ |
|
38 |
public class RawDiagnosticFormatter extends AbstractDiagnosticFormatter { |
|
39 |
||
40 |
/** |
|
41 |
* Create a formatter based on the supplied options. |
|
42 |
* @param msgs |
|
43 |
*/ |
|
44 |
public RawDiagnosticFormatter(Messages msgs) { |
|
45 |
super(null); |
|
46 |
} |
|
47 |
||
48 |
//provide common default formats |
|
49 |
public String format(JCDiagnostic d, Locale l) { |
|
50 |
try { |
|
51 |
StringBuffer buf = new StringBuffer(); |
|
52 |
if (d.getPosition() != Position.NOPOS) { |
|
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
942
diff
changeset
|
53 |
buf.append(formatSource(d, false, null)); |
942 | 54 |
buf.append(':'); |
55 |
buf.append(formatPosition(d, LINE, null)); |
|
56 |
buf.append(':'); |
|
57 |
buf.append(formatPosition(d, COLUMN, null)); |
|
58 |
buf.append(':'); |
|
59 |
} |
|
60 |
else |
|
61 |
buf.append('-'); |
|
62 |
buf.append(' '); |
|
63 |
buf.append(formatMessage(d, null)); |
|
64 |
return buf.toString(); |
|
65 |
} |
|
66 |
catch (Exception e) { |
|
67 |
e.printStackTrace(); |
|
68 |
return null; |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
@Override |
|
73 |
protected String formatArgument(JCDiagnostic diag, Object arg, Locale l) { |
|
74 |
String s; |
|
75 |
if (arg instanceof Formattable) |
|
76 |
s = arg.toString(); |
|
77 |
else |
|
78 |
s = super.formatArgument(diag, arg, null); |
|
79 |
if (arg instanceof JCDiagnostic) |
|
80 |
return "(" + s + ")"; |
|
81 |
else |
|
82 |
return s; |
|
83 |
} |
|
84 |
||
85 |
@Override |
|
86 |
protected String localize(Locale l, String s, Object... args) { |
|
87 |
StringBuffer buf = new StringBuffer(); |
|
88 |
buf.append(s); |
|
89 |
String sep = ": "; |
|
90 |
for (Object o : args) { |
|
91 |
buf.append(sep); |
|
92 |
buf.append(o); |
|
93 |
sep = ", "; |
|
94 |
} |
|
95 |
return buf.toString(); |
|
96 |
} |
|
97 |
||
98 |
public boolean displaySource(JCDiagnostic d) { |
|
99 |
return false; |
|
100 |
} |
|
101 |
} |