author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 22159 | 682da512ec17 |
permissions | -rw-r--r-- |
942 | 1 |
/* |
14259 | 2 |
* Copyright (c) 2005, 2012, 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 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
28 |
import java.util.Collection; |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
29 |
import java.util.EnumMap; |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
30 |
import java.util.EnumSet; |
942 | 31 |
import java.util.HashMap; |
32 |
import java.util.Locale; |
|
33 |
import java.util.Map; |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
34 |
import java.util.regex.Matcher; |
942 | 35 |
import javax.tools.JavaFileObject; |
36 |
||
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
37 |
import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
38 |
import com.sun.tools.javac.util.BasicDiagnosticFormatter.BasicConfiguration; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
39 |
|
942 | 40 |
import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*; |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
41 |
import static com.sun.tools.javac.util.BasicDiagnosticFormatter.BasicConfiguration.*; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
42 |
import static com.sun.tools.javac.util.LayoutCharacters.*; |
942 | 43 |
|
44 |
/** |
|
45 |
* A basic formatter for diagnostic messages. |
|
46 |
* The basic formatter will format a diagnostic according to one of three format patterns, depending on whether |
|
47 |
* or not the source name and position are set. The formatter supports a printf-like string for patterns |
|
48 |
* with the following special characters: |
|
49 |
* <ul> |
|
50 |
* <li>%b: the base of the source name |
|
51 |
* <li>%f: the source name (full absolute path) |
|
52 |
* <li>%l: the line number of the diagnostic, derived from the character offset |
|
53 |
* <li>%c: the column number of the diagnostic, derived from the character offset |
|
54 |
* <li>%o: the character offset of the diagnostic if set |
|
55 |
* <li>%p: the prefix for the diagnostic, derived from the diagnostic type |
|
56 |
* <li>%t: the prefix as it normally appears in standard diagnostics. In this case, no prefix is |
|
57 |
* shown if the type is ERROR and if a source name is set |
|
58 |
* <li>%m: the text or the diagnostic, including any appropriate arguments |
|
59 |
* <li>%_: space delimiter, useful for formatting purposes |
|
60 |
* </ul> |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
2984
diff
changeset
|
61 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
62 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
2984
diff
changeset
|
63 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
2984
diff
changeset
|
64 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
2984
diff
changeset
|
65 |
* deletion without notice.</b> |
942 | 66 |
*/ |
67 |
public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter { |
|
68 |
||
69 |
/** |
|
70 |
* Create a basic formatter based on the supplied options. |
|
71 |
* |
|
14259 | 72 |
* @param options list of command-line options |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
73 |
* @param msgs JavacMessages object used for i18n |
942 | 74 |
*/ |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
75 |
public BasicDiagnosticFormatter(Options options, JavacMessages msgs) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
76 |
super(msgs, new BasicConfiguration(options)); |
942 | 77 |
} |
78 |
||
79 |
/** |
|
80 |
* Create a standard basic formatter |
|
81 |
* |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
82 |
* @param msgs JavacMessages object used for i18n |
942 | 83 |
*/ |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
84 |
public BasicDiagnosticFormatter(JavacMessages msgs) { |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
85 |
super(msgs, new BasicConfiguration()); |
942 | 86 |
} |
87 |
||
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2085
diff
changeset
|
88 |
public String formatDiagnostic(JCDiagnostic d, Locale l) { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
89 |
if (l == null) |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
90 |
l = messages.getCurrentLocale(); |
942 | 91 |
String format = selectFormat(d); |
92 |
StringBuilder buf = new StringBuilder(); |
|
93 |
for (int i = 0; i < format.length(); i++) { |
|
94 |
char c = format.charAt(i); |
|
95 |
boolean meta = false; |
|
96 |
if (c == '%' && i < format.length() - 1) { |
|
97 |
meta = true; |
|
98 |
c = format.charAt(++i); |
|
99 |
} |
|
100 |
buf.append(meta ? formatMeta(c, d, l) : String.valueOf(c)); |
|
101 |
} |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
102 |
if (depth == 0) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
103 |
return addSourceLineIfNeeded(d, buf.toString()); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
104 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
105 |
return buf.toString(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
106 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
107 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
108 |
public String formatMessage(JCDiagnostic d, Locale l) { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
109 |
int currentIndentation = 0; |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
110 |
StringBuilder buf = new StringBuilder(); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
111 |
Collection<String> args = formatArguments(d, l); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
112 |
String msg = localize(l, d.getCode(), args.toArray()); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
113 |
String[] lines = msg.split("\n"); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
114 |
if (getConfiguration().getVisible().contains(DiagnosticPart.SUMMARY)) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
115 |
currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUMMARY); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
116 |
buf.append(indent(lines[0], currentIndentation)); //summary |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
117 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
118 |
if (lines.length > 1 && getConfiguration().getVisible().contains(DiagnosticPart.DETAILS)) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
119 |
currentIndentation += getConfiguration().getIndentation(DiagnosticPart.DETAILS); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
120 |
for (int i = 1;i < lines.length; i++) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
121 |
buf.append("\n" + indent(lines[i], currentIndentation)); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
122 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
123 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
124 |
if (d.isMultiline() && getConfiguration().getVisible().contains(DiagnosticPart.SUBDIAGNOSTICS)) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
125 |
currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUBDIAGNOSTICS); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
126 |
for (String sub : formatSubdiagnostics(d, l)) { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
127 |
buf.append("\n" + indent(sub, currentIndentation)); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
128 |
} |
1472
1e09e143438c
6731573: diagnostic output should optionally include source line
mcimadamore
parents:
1471
diff
changeset
|
129 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6151
diff
changeset
|
130 |
return buf.toString(); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
131 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
132 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
133 |
protected String addSourceLineIfNeeded(JCDiagnostic d, String msg) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
134 |
if (!displaySource(d)) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
135 |
return msg; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
136 |
else { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
137 |
BasicConfiguration conf = getConfiguration(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
138 |
int indentSource = conf.getIndentation(DiagnosticPart.SOURCE); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
139 |
String sourceLine = "\n" + formatSourceLine(d, indentSource); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14259
diff
changeset
|
140 |
boolean singleLine = !msg.contains("\n"); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
141 |
if (singleLine || getConfiguration().getSourcePosition() == SourcePosition.BOTTOM) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
142 |
return msg + sourceLine; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
143 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
144 |
return msg.replaceFirst("\n", Matcher.quoteReplacement(sourceLine) + "\n"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
145 |
} |
942 | 146 |
} |
147 |
||
148 |
protected String formatMeta(char c, JCDiagnostic d, Locale l) { |
|
149 |
switch (c) { |
|
150 |
case 'b': |
|
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
942
diff
changeset
|
151 |
return formatSource(d, false, l); |
942 | 152 |
case 'e': |
153 |
return formatPosition(d, END, l); |
|
154 |
case 'f': |
|
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
942
diff
changeset
|
155 |
return formatSource(d, true, l); |
942 | 156 |
case 'l': |
157 |
return formatPosition(d, LINE, l); |
|
158 |
case 'c': |
|
159 |
return formatPosition(d, COLUMN, l); |
|
160 |
case 'o': |
|
161 |
return formatPosition(d, OFFSET, l); |
|
162 |
case 'p': |
|
163 |
return formatKind(d, l); |
|
164 |
case 's': |
|
165 |
return formatPosition(d, START, l); |
|
166 |
case 't': { |
|
167 |
boolean usePrefix; |
|
168 |
switch (d.getType()) { |
|
169 |
case FRAGMENT: |
|
170 |
usePrefix = false; |
|
171 |
break; |
|
172 |
case ERROR: |
|
173 |
usePrefix = (d.getIntPosition() == Position.NOPOS); |
|
174 |
break; |
|
175 |
default: |
|
176 |
usePrefix = true; |
|
177 |
} |
|
178 |
if (usePrefix) |
|
179 |
return formatKind(d, l); |
|
180 |
else |
|
181 |
return ""; |
|
182 |
} |
|
183 |
case 'm': |
|
184 |
return formatMessage(d, l); |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
185 |
case 'L': |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
186 |
return formatLintCategory(d, l); |
942 | 187 |
case '_': |
188 |
return " "; |
|
189 |
case '%': |
|
190 |
return "%"; |
|
191 |
default: |
|
192 |
return String.valueOf(c); |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
private String selectFormat(JCDiagnostic d) { |
|
197 |
DiagnosticSource source = d.getDiagnosticSource(); |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
198 |
String format = getConfiguration().getFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT); |
5016
ff5e6791d0bb
6930108: IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.jav
jjg
parents:
3380
diff
changeset
|
199 |
if (source != null && source != DiagnosticSource.NO_SOURCE) { |
942 | 200 |
if (d.getIntPosition() != Position.NOPOS) { |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
201 |
format = getConfiguration().getFormat(BasicFormatKind.DEFAULT_POS_FORMAT); |
942 | 202 |
} else if (source.getFile() != null && |
203 |
source.getFile().getKind() == JavaFileObject.Kind.CLASS) { |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
204 |
format = getConfiguration().getFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT); |
942 | 205 |
} |
206 |
} |
|
207 |
return format; |
|
208 |
} |
|
209 |
||
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
210 |
@Override |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
211 |
public BasicConfiguration getConfiguration() { |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2223
diff
changeset
|
212 |
//the following cast is always safe - see init |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
213 |
return (BasicConfiguration)super.getConfiguration(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
214 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
215 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
216 |
static public class BasicConfiguration extends SimpleConfiguration { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
217 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
218 |
protected Map<DiagnosticPart, Integer> indentationLevels; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
219 |
protected Map<BasicFormatKind, String> availableFormats; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
220 |
protected SourcePosition sourcePosition; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
221 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
222 |
@SuppressWarnings("fallthrough") |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
223 |
public BasicConfiguration(Options options) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
224 |
super(options, EnumSet.of(DiagnosticPart.SUMMARY, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
225 |
DiagnosticPart.DETAILS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
226 |
DiagnosticPart.SUBDIAGNOSTICS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
227 |
DiagnosticPart.SOURCE)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
228 |
initFormat(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
229 |
initIndentation(); |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
230 |
if (options.isSet("oldDiags")) |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
231 |
initOldFormat(); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
232 |
String fmt = options.get("diagsFormat"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
233 |
if (fmt != null) { |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
234 |
if (fmt.equals("OLD")) |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
235 |
initOldFormat(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
236 |
else |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
237 |
initFormats(fmt); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
238 |
} |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
239 |
String srcPos = null; |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
240 |
if ((((srcPos = options.get("sourcePosition")) != null)) && |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
241 |
srcPos.equals("bottom")) |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
242 |
setSourcePosition(SourcePosition.BOTTOM); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
243 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
244 |
setSourcePosition(SourcePosition.AFTER_SUMMARY); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
245 |
String indent = options.get("diagsIndentation"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
246 |
if (indent != null) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
247 |
String[] levels = indent.split("\\|"); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
248 |
try { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
249 |
switch (levels.length) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
250 |
case 5: |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
251 |
setIndentation(DiagnosticPart.JLS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
252 |
Integer.parseInt(levels[4])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
253 |
case 4: |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
254 |
setIndentation(DiagnosticPart.SUBDIAGNOSTICS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
255 |
Integer.parseInt(levels[3])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
256 |
case 3: |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
257 |
setIndentation(DiagnosticPart.SOURCE, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
258 |
Integer.parseInt(levels[2])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
259 |
case 2: |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
260 |
setIndentation(DiagnosticPart.DETAILS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
261 |
Integer.parseInt(levels[1])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
262 |
default: |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
263 |
setIndentation(DiagnosticPart.SUMMARY, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
264 |
Integer.parseInt(levels[0])); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
265 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
266 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
267 |
catch (NumberFormatException ex) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
268 |
initIndentation(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
269 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
270 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
271 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
272 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
273 |
public BasicConfiguration() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
274 |
super(EnumSet.of(DiagnosticPart.SUMMARY, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
275 |
DiagnosticPart.DETAILS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
276 |
DiagnosticPart.SUBDIAGNOSTICS, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
277 |
DiagnosticPart.SOURCE)); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
278 |
initFormat(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
279 |
initIndentation(); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
280 |
} |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
281 |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
282 |
private void initFormat() { |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
283 |
initFormats("%f:%l:%_%p%L%m", "%p%L%m", "%f:%_%p%L%m"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
284 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
285 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
286 |
private void initOldFormat() { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
287 |
initFormats("%f:%l:%_%t%L%m", "%p%L%m", "%f:%_%t%L%m"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
288 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
289 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
290 |
private void initFormats(String pos, String nopos, String clazz) { |
22163 | 291 |
availableFormats = new EnumMap<>(BasicFormatKind.class); |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
292 |
setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, pos); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
293 |
setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, nopos); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
294 |
setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, clazz); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
295 |
} |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
296 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
297 |
@SuppressWarnings("fallthrough") |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
298 |
private void initFormats(String fmt) { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
299 |
String[] formats = fmt.split("\\|"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
300 |
switch (formats.length) { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
301 |
case 3: |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
302 |
setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
303 |
case 2: |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
304 |
setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
305 |
default: |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
306 |
setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
307 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
308 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
7681
diff
changeset
|
309 |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
310 |
private void initIndentation() { |
22163 | 311 |
indentationLevels = new HashMap<>(); |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
312 |
setIndentation(DiagnosticPart.SUMMARY, 0); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
313 |
setIndentation(DiagnosticPart.DETAILS, DetailsInc); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
314 |
setIndentation(DiagnosticPart.SUBDIAGNOSTICS, DiagInc); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
315 |
setIndentation(DiagnosticPart.SOURCE, 0); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
316 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
317 |
|
942 | 318 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
319 |
* Get the amount of spaces for a given indentation kind |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
320 |
* @param diagPart the diagnostic part for which the indentation is |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
321 |
* to be retrieved |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
322 |
* @return the amount of spaces used for the specified indentation kind |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
323 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
324 |
public int getIndentation(DiagnosticPart diagPart) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
325 |
return indentationLevels.get(diagPart); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
326 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
327 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
328 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
329 |
* Set the indentation level for various element of a given diagnostic - |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
330 |
* this might lead to more readable diagnostics |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
331 |
* |
14259 | 332 |
* @param diagPart |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
333 |
* @param nSpaces amount of spaces for the specified diagnostic part |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
334 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
335 |
public void setIndentation(DiagnosticPart diagPart, int nSpaces) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
336 |
indentationLevels.put(diagPart, nSpaces); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
337 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
338 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
339 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
340 |
* Set the source line positioning used by this formatter |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
341 |
* |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
342 |
* @param sourcePos a positioning value for source line |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
343 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
344 |
public void setSourcePosition(SourcePosition sourcePos) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
345 |
sourcePosition = sourcePos; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
346 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
347 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
348 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
349 |
* Get the source line positioning used by this formatter |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
350 |
* |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
351 |
* @return the positioning value used by this formatter |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
352 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
353 |
public SourcePosition getSourcePosition() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
354 |
return sourcePosition; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
355 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
356 |
//where |
942 | 357 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
358 |
* A source positioning value controls the position (within a given |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
359 |
* diagnostic message) in which the source line the diagnostic refers to |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
360 |
* should be displayed (if applicable) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
361 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
362 |
public enum SourcePosition { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
363 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
364 |
* Source line is displayed after the diagnostic message |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
365 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
366 |
BOTTOM, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
367 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
368 |
* Source line is displayed after the first line of the diagnostic |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
369 |
* message |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
370 |
*/ |
22163 | 371 |
AFTER_SUMMARY |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
372 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
373 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
374 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
375 |
* Set a metachar string for a specific format |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
376 |
* |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
377 |
* @param kind the format kind to be set |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
378 |
* @param s the metachar string specifying the format |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
379 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
380 |
public void setFormat(BasicFormatKind kind, String s) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
381 |
availableFormats.put(kind, s); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
382 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
383 |
|
942 | 384 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
385 |
* Get a metachar string for a specific format |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
386 |
* |
14259 | 387 |
* @param kind the format kind for which to get the metachar string |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
388 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
389 |
public String getFormat(BasicFormatKind kind) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
390 |
return availableFormats.get(kind); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
391 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
392 |
//where |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
393 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
394 |
* This enum contains all the kinds of formatting patterns supported |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
395 |
* by a basic diagnostic formatter. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
396 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
397 |
public enum BasicFormatKind { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
398 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
399 |
* A format string to be used for diagnostics with a given position. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
400 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
401 |
DEFAULT_POS_FORMAT, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
402 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
403 |
* A format string to be used for diagnostics without a given position. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
404 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
405 |
DEFAULT_NO_POS_FORMAT, |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
406 |
/** |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
407 |
* A format string to be used for diagnostics regarding classfiles |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
408 |
*/ |
22163 | 409 |
DEFAULT_CLASS_FORMAT |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1870
diff
changeset
|
410 |
} |
942 | 411 |
} |
412 |
} |