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