author | vromero |
Fri, 26 Apr 2013 10:17:01 +0100 | |
changeset 17282 | c6964ad7df63 |
parent 16326 | 9b94bafef533 |
child 17582 | 4079713129dd |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
28 |
import java.util.EnumSet; |
10 | 29 |
import java.util.Locale; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
30 |
import java.util.Set; |
10 | 31 |
|
32 |
import javax.tools.Diagnostic; |
|
33 |
import javax.tools.JavaFileObject; |
|
34 |
||
942 | 35 |
import com.sun.tools.javac.api.DiagnosticFormatter; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
36 |
import com.sun.tools.javac.code.Lint.LintCategory; |
13077 | 37 |
import com.sun.tools.javac.tree.EndPosTable; |
10 | 38 |
import com.sun.tools.javac.tree.JCTree; |
39 |
||
40 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; |
|
41 |
||
42 |
/** An abstraction of a diagnostic message generated by the compiler. |
|
43 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
44 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
45 |
* If you write code that depends on this, you do so at your own risk. |
10 | 46 |
* This code and its internal interfaces are subject to change or |
47 |
* deletion without notice.</b> |
|
48 |
*/ |
|
49 |
public class JCDiagnostic implements Diagnostic<JavaFileObject> { |
|
50 |
/** A factory for creating diagnostic objects. */ |
|
51 |
public static class Factory { |
|
52 |
/** The context key for the diagnostic factory. */ |
|
53 |
protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey = |
|
54 |
new Context.Key<JCDiagnostic.Factory>(); |
|
55 |
||
56 |
/** Get the Factory instance for this context. */ |
|
57 |
public static Factory instance(Context context) { |
|
58 |
Factory instance = context.get(diagnosticFactoryKey); |
|
59 |
if (instance == null) |
|
60 |
instance = new Factory(context); |
|
61 |
return instance; |
|
62 |
} |
|
63 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
64 |
DiagnosticFormatter<JCDiagnostic> formatter; |
10 | 65 |
final String prefix; |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
66 |
final Set<DiagnosticFlag> defaultErrorFlags; |
10 | 67 |
|
68 |
/** Create a new diagnostic factory. */ |
|
69 |
protected Factory(Context context) { |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
70 |
this(JavacMessages.instance(context), "compiler"); |
10 | 71 |
context.put(diagnosticFactoryKey, this); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
72 |
|
11052 | 73 |
final Options options = Options.instance(context); |
74 |
initOptions(options); |
|
75 |
options.addListener(new Runnable() { |
|
76 |
public void run() { |
|
77 |
initOptions(options); |
|
78 |
} |
|
79 |
}); |
|
80 |
} |
|
81 |
||
82 |
private void initOptions(Options options) { |
|
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
83 |
if (options.isSet("onlySyntaxErrorsUnrecoverable")) |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
84 |
defaultErrorFlags.add(DiagnosticFlag.RECOVERABLE); |
10 | 85 |
} |
86 |
||
87 |
/** Create a new diagnostic factory. */ |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
88 |
public Factory(JavacMessages messages, String prefix) { |
10 | 89 |
this.prefix = prefix; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
90 |
this.formatter = new BasicDiagnosticFormatter(messages); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
91 |
defaultErrorFlags = EnumSet.of(DiagnosticFlag.MANDATORY); |
10 | 92 |
} |
93 |
||
94 |
/** |
|
95 |
* Create an error diagnostic. |
|
96 |
* @param source The source of the compilation unit, if any, in which to report the error. |
|
97 |
* @param pos The source position at which to report the error. |
|
98 |
* @param key The key for the localized error message. |
|
99 |
* @param args Fields of the error message. |
|
100 |
*/ |
|
101 |
public JCDiagnostic error( |
|
102 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
103 |
return create(ERROR, null, defaultErrorFlags, source, pos, key, args); |
10 | 104 |
} |
105 |
||
106 |
/** |
|
107 |
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
|
108 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
|
109 |
* @param pos The source position at which to report the warning. |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
110 |
* @param key The key for the localized warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
111 |
* @param args Fields of the warning message. |
10 | 112 |
* @see MandatoryWarningHandler |
113 |
*/ |
|
114 |
public JCDiagnostic mandatoryWarning( |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
115 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
116 |
return create(WARNING, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
117 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
118 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
119 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
120 |
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
121 |
* @param lc The lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
122 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
123 |
* @param pos The source position at which to report the warning. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
124 |
* @param key The key for the localized warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
125 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
126 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
127 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
128 |
public JCDiagnostic mandatoryWarning( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
129 |
LintCategory lc, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
130 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
131 |
return create(WARNING, lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, key, args); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
132 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
133 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
134 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
135 |
* Create a warning diagnostic. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
136 |
* @param lc The lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
137 |
* @param key The key for the localized error message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
138 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
139 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
140 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
141 |
public JCDiagnostic warning( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
142 |
LintCategory lc, String key, Object... args) { |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
143 |
return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args); |
10 | 144 |
} |
145 |
||
146 |
/** |
|
147 |
* Create a warning diagnostic. |
|
148 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
|
149 |
* @param pos The source position at which to report the warning. |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
150 |
* @param key The key for the localized warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
151 |
* @param args Fields of the warning message. |
10 | 152 |
*/ |
153 |
public JCDiagnostic warning( |
|
154 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
155 |
return create(WARNING, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
156 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
157 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
158 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
159 |
* Create a warning diagnostic. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
160 |
* @param lc The lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
161 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
162 |
* @param pos The source position at which to report the warning. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
163 |
* @param key The key for the localized warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
164 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
165 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
166 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
167 |
public JCDiagnostic warning( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
168 |
LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
169 |
return create(WARNING, lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args); |
10 | 170 |
} |
171 |
||
172 |
/** |
|
173 |
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
174 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
175 |
* @param args Fields of the message. |
10 | 176 |
* @see MandatoryWarningHandler |
177 |
*/ |
|
178 |
public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
179 |
return create(NOTE, null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, key, args); |
10 | 180 |
} |
181 |
||
182 |
/** |
|
183 |
* Create a note diagnostic. |
|
184 |
* @param key The key for the localized error message. |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
185 |
* @param args Fields of the message. |
10 | 186 |
*/ |
187 |
public JCDiagnostic note(String key, Object... args) { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
188 |
return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args); |
10 | 189 |
} |
190 |
||
191 |
/** |
|
192 |
* Create a note diagnostic. |
|
193 |
* @param source The source of the compilation unit, if any, in which to report the note. |
|
194 |
* @param pos The source position at which to report the note. |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
195 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
196 |
* @param args Fields of the message. |
10 | 197 |
*/ |
198 |
public JCDiagnostic note( |
|
199 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
200 |
return create(NOTE, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args); |
10 | 201 |
} |
202 |
||
203 |
/** |
|
204 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
205 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
206 |
* @param args Fields of the message. |
10 | 207 |
*/ |
208 |
public JCDiagnostic fragment(String key, Object... args) { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
209 |
return create(FRAGMENT, null, EnumSet.noneOf(DiagnosticFlag.class), null, null, key, args); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
210 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
211 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
212 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
213 |
* Create a new diagnostic of the given kind, which is not mandatory and which has |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
214 |
* no lint category. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
215 |
* @param kind The diagnostic kind |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
216 |
* @param source The source of the compilation unit, if any, in which to report the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
217 |
* @param pos The source position at which to report the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
218 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
219 |
* @param args Fields of the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
220 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
221 |
public JCDiagnostic create( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
222 |
DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
223 |
return create(kind, null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, key, args); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
224 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
225 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
226 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
227 |
* Create a new diagnostic of the given kind. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
228 |
* @param kind The diagnostic kind |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
229 |
* @param lc The lint category, if applicable, or null |
14259 | 230 |
* @param flags The set of flags for the diagnostic |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
231 |
* @param source The source of the compilation unit, if any, in which to report the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
232 |
* @param pos The source position at which to report the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
233 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
234 |
* @param args Fields of the message. |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
235 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
236 |
public JCDiagnostic create( |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
237 |
DiagnosticType kind, LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
238 |
return new JCDiagnostic(formatter, kind, lc, flags, source, pos, qualify(kind, key), args); |
10 | 239 |
} |
240 |
||
241 |
protected String qualify(DiagnosticType t, String key) { |
|
242 |
return prefix + "." + t.key + "." + key; |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
||
247 |
||
248 |
/** |
|
249 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
|
250 |
* @param key The key for the localized error message. |
|
251 |
* @param args Fields of the error message. |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
252 |
* |
10 | 253 |
*/ |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
254 |
@Deprecated |
10 | 255 |
public static JCDiagnostic fragment(String key, Object... args) { |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
256 |
return new JCDiagnostic(getFragmentFormatter(), |
10 | 257 |
FRAGMENT, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
258 |
null, |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
259 |
EnumSet.noneOf(DiagnosticFlag.class), |
10 | 260 |
null, |
261 |
null, |
|
262 |
"compiler." + FRAGMENT.key + "." + key, |
|
263 |
args); |
|
264 |
} |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
265 |
//where |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
266 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
267 |
public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() { |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
268 |
if (fragmentFormatter == null) { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
269 |
fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages()); |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
270 |
} |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
271 |
return fragmentFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
272 |
} |
10 | 273 |
|
274 |
/** |
|
275 |
* A DiagnosticType defines the type of the diagnostic. |
|
276 |
**/ |
|
277 |
public enum DiagnosticType { |
|
278 |
/** A fragment of an enclosing diagnostic. */ |
|
279 |
FRAGMENT("misc"), |
|
280 |
/** A note: similar to, but less serious than, a warning. */ |
|
281 |
NOTE("note"), |
|
282 |
/** A warning. */ |
|
283 |
WARNING("warn"), |
|
284 |
/** An error. */ |
|
285 |
ERROR("err"); |
|
286 |
||
287 |
final String key; |
|
288 |
||
289 |
/** Create a DiagnosticType. |
|
290 |
* @param key A string used to create the resource key for the diagnostic. |
|
291 |
*/ |
|
292 |
DiagnosticType(String key) { |
|
293 |
this.key = key; |
|
294 |
} |
|
295 |
}; |
|
296 |
||
297 |
/** |
|
298 |
* A DiagnosticPosition provides information about the positions in a file |
|
299 |
* that gave rise to a diagnostic. It always defines a "preferred" position |
|
300 |
* that most accurately defines the location of the diagnostic, it may also |
|
301 |
* provide a related tree node that spans that location. |
|
302 |
*/ |
|
303 |
public static interface DiagnosticPosition { |
|
304 |
/** Gets the tree node, if any, to which the diagnostic applies. */ |
|
305 |
JCTree getTree(); |
|
306 |
/** If there is a tree node, get the start position of the tree node. |
|
307 |
* Otherwise, just returns the same as getPreferredPosition(). */ |
|
308 |
int getStartPosition(); |
|
309 |
/** Get the position within the file that most accurately defines the |
|
310 |
* location for the diagnostic. */ |
|
311 |
int getPreferredPosition(); |
|
312 |
/** If there is a tree node, and if endPositions are available, get |
|
313 |
* the end position of the tree node. Otherwise, just returns the |
|
314 |
* same as getPreferredPosition(). */ |
|
11055 | 315 |
int getEndPosition(EndPosTable endPosTable); |
10 | 316 |
} |
317 |
||
318 |
/** |
|
319 |
* A DiagnosticPosition that simply identifies a position, but no related |
|
320 |
* tree node, as the location for a diagnostic. Used for scanner and parser |
|
321 |
* diagnostics. */ |
|
322 |
public static class SimpleDiagnosticPosition implements DiagnosticPosition { |
|
323 |
public SimpleDiagnosticPosition(int pos) { |
|
324 |
this.pos = pos; |
|
325 |
} |
|
326 |
||
327 |
public JCTree getTree() { |
|
328 |
return null; |
|
329 |
} |
|
330 |
||
331 |
public int getStartPosition() { |
|
332 |
return pos; |
|
333 |
} |
|
334 |
||
335 |
public int getPreferredPosition() { |
|
336 |
return pos; |
|
337 |
} |
|
338 |
||
11055 | 339 |
public int getEndPosition(EndPosTable endPosTable) { |
10 | 340 |
return pos; |
341 |
} |
|
342 |
||
343 |
private final int pos; |
|
344 |
} |
|
345 |
||
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
346 |
public enum DiagnosticFlag { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
347 |
MANDATORY, |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
348 |
RESOLVE_ERROR, |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
349 |
SYNTAX, |
16326
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
16309
diff
changeset
|
350 |
RECOVERABLE, |
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
16309
diff
changeset
|
351 |
NON_DEFERRABLE, |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
352 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
353 |
|
10 | 354 |
private final DiagnosticType type; |
355 |
private final DiagnosticSource source; |
|
356 |
private final DiagnosticPosition position; |
|
357 |
private final int line; |
|
358 |
private final int column; |
|
359 |
private final String key; |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
360 |
protected final Object[] args; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
361 |
private final Set<DiagnosticFlag> flags; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
362 |
private final LintCategory lintCategory; |
10 | 363 |
|
364 |
/** |
|
365 |
* Create a diagnostic object. |
|
14259 | 366 |
* @param formatter the formatter to use for the diagnostic |
10 | 367 |
* @param dt the type of diagnostic |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
368 |
* @param lc the lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
369 |
* @param source the name of the source file, or null if none. |
10 | 370 |
* @param pos the character offset within the source file, if given. |
371 |
* @param key a resource key to identify the text of the diagnostic |
|
372 |
* @param args arguments to be included in the text of the diagnostic |
|
373 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
374 |
protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter, |
10 | 375 |
DiagnosticType dt, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
376 |
LintCategory lc, |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
377 |
Set<DiagnosticFlag> flags, |
10 | 378 |
DiagnosticSource source, |
379 |
DiagnosticPosition pos, |
|
380 |
String key, |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
381 |
Object... args) { |
10 | 382 |
if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) |
383 |
throw new IllegalArgumentException(); |
|
384 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
385 |
this.defaultFormatter = formatter; |
10 | 386 |
this.type = dt; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
387 |
this.lintCategory = lc; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
388 |
this.flags = flags; |
10 | 389 |
this.source = source; |
390 |
this.position = pos; |
|
391 |
this.key = key; |
|
15385 | 392 |
this.args = args; |
10 | 393 |
|
394 |
int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); |
|
395 |
if (n == Position.NOPOS || source == null) |
|
396 |
line = column = -1; |
|
397 |
else { |
|
398 |
line = source.getLineNumber(n); |
|
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
1040
diff
changeset
|
399 |
column = source.getColumnNumber(n, true); |
10 | 400 |
} |
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Get the type of this diagnostic. |
|
405 |
* @return the type of this diagnostic |
|
406 |
*/ |
|
407 |
public DiagnosticType getType() { |
|
408 |
return type; |
|
409 |
} |
|
410 |
||
411 |
/** |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
412 |
* Get the subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
413 |
* @return subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
414 |
*/ |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
415 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
416 |
return List.nil(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
417 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
418 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
419 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
420 |
return false; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
421 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
422 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
423 |
/** |
10 | 424 |
* Check whether or not this diagnostic is required to be shown. |
425 |
* @return true if this diagnostic is required to be shown. |
|
426 |
*/ |
|
427 |
public boolean isMandatory() { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
428 |
return flags.contains(DiagnosticFlag.MANDATORY); |
10 | 429 |
} |
430 |
||
431 |
/** |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
432 |
* Check whether this diagnostic has an associated lint category. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
433 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
434 |
public boolean hasLintCategory() { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
435 |
return (lintCategory != null); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
436 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
437 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
438 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
439 |
* Get the associated lint category, or null if none. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
440 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
441 |
public LintCategory getLintCategory() { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
442 |
return lintCategory; |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
443 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
444 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
445 |
/** |
10 | 446 |
* Get the name of the source file referred to by this diagnostic. |
447 |
* @return the name of the source referred to with this diagnostic, or null if none |
|
448 |
*/ |
|
449 |
public JavaFileObject getSource() { |
|
450 |
if (source == null) |
|
451 |
return null; |
|
452 |
else |
|
453 |
return source.getFile(); |
|
454 |
} |
|
455 |
||
456 |
/** |
|
457 |
* Get the source referred to by this diagnostic. |
|
458 |
* @return the source referred to with this diagnostic, or null if none |
|
459 |
*/ |
|
460 |
public DiagnosticSource getDiagnosticSource() { |
|
461 |
return source; |
|
462 |
} |
|
463 |
||
464 |
protected int getIntStartPosition() { |
|
465 |
return (position == null ? Position.NOPOS : position.getStartPosition()); |
|
466 |
} |
|
467 |
||
468 |
protected int getIntPosition() { |
|
469 |
return (position == null ? Position.NOPOS : position.getPreferredPosition()); |
|
470 |
} |
|
471 |
||
472 |
protected int getIntEndPosition() { |
|
473 |
return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable())); |
|
474 |
} |
|
475 |
||
476 |
public long getStartPosition() { |
|
477 |
return getIntStartPosition(); |
|
478 |
} |
|
479 |
||
480 |
public long getPosition() { |
|
481 |
return getIntPosition(); |
|
482 |
} |
|
483 |
||
484 |
public long getEndPosition() { |
|
485 |
return getIntEndPosition(); |
|
486 |
} |
|
487 |
||
16309
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
488 |
public DiagnosticPosition getDiagnosticPosition() { |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
489 |
return position; |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
490 |
} |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
491 |
|
10 | 492 |
/** |
493 |
* Get the line number within the source referred to by this diagnostic. |
|
494 |
* @return the line number within the source referred to by this diagnostic |
|
495 |
*/ |
|
496 |
public long getLineNumber() { |
|
497 |
return line; |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* Get the column number within the line of source referred to by this diagnostic. |
|
502 |
* @return the column number within the line of source referred to by this diagnostic |
|
503 |
*/ |
|
504 |
public long getColumnNumber() { |
|
505 |
return column; |
|
506 |
} |
|
507 |
||
508 |
/** |
|
509 |
* Get the arguments to be included in the text of the diagnostic. |
|
510 |
* @return the arguments to be included in the text of the diagnostic |
|
511 |
*/ |
|
512 |
public Object[] getArgs() { |
|
513 |
return args; |
|
514 |
} |
|
515 |
||
516 |
/** |
|
517 |
* Get the prefix string associated with this type of diagnostic. |
|
518 |
* @return the prefix string associated with this type of diagnostic |
|
519 |
*/ |
|
520 |
public String getPrefix() { |
|
521 |
return getPrefix(type); |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Get the prefix string associated with a particular type of diagnostic. |
|
526 |
* @return the prefix string associated with a particular type of diagnostic |
|
527 |
*/ |
|
528 |
public String getPrefix(DiagnosticType dt) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
529 |
return defaultFormatter.formatKind(this, Locale.getDefault()); |
942 | 530 |
} |
531 |
||
10 | 532 |
/** |
533 |
* Return the standard presentation of this diagnostic. |
|
534 |
*/ |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3143
diff
changeset
|
535 |
@Override |
10 | 536 |
public String toString() { |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
537 |
return defaultFormatter.format(this,Locale.getDefault()); |
10 | 538 |
} |
539 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
540 |
private DiagnosticFormatter<JCDiagnostic> defaultFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
541 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
542 |
private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter; |
10 | 543 |
|
544 |
// Methods for javax.tools.Diagnostic |
|
545 |
||
546 |
public Diagnostic.Kind getKind() { |
|
547 |
switch (type) { |
|
548 |
case NOTE: |
|
549 |
return Diagnostic.Kind.NOTE; |
|
550 |
case WARNING: |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
551 |
return flags.contains(DiagnosticFlag.MANDATORY) |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
552 |
? Diagnostic.Kind.MANDATORY_WARNING |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
553 |
: Diagnostic.Kind.WARNING; |
10 | 554 |
case ERROR: |
555 |
return Diagnostic.Kind.ERROR; |
|
556 |
default: |
|
557 |
return Diagnostic.Kind.OTHER; |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
public String getCode() { |
|
562 |
return key; |
|
563 |
} |
|
564 |
||
565 |
public String getMessage(Locale locale) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
566 |
return defaultFormatter.formatMessage(this, locale); |
10 | 567 |
} |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
568 |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
569 |
public void setFlag(DiagnosticFlag flag) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
570 |
flags.add(flag); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
571 |
|
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
572 |
if (type == DiagnosticType.ERROR) { |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
573 |
switch (flag) { |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
574 |
case SYNTAX: |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
575 |
flags.remove(DiagnosticFlag.RECOVERABLE); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
576 |
break; |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
577 |
case RESOLVE_ERROR: |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
578 |
flags.add(DiagnosticFlag.RECOVERABLE); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
579 |
break; |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
580 |
} |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
581 |
} |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
582 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
583 |
|
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
584 |
public boolean isFlagSet(DiagnosticFlag flag) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
585 |
return flags.contains(flag); |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
586 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
587 |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
588 |
public static class MultilineDiagnostic extends JCDiagnostic { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
589 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
590 |
private final List<JCDiagnostic> subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
591 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
592 |
public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
593 |
super(other.defaultFormatter, |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
594 |
other.getType(), |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
595 |
other.getLintCategory(), |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
596 |
other.flags, |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
597 |
other.getDiagnosticSource(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
598 |
other.position, |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
599 |
other.getCode(), |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
600 |
other.getArgs()); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
601 |
this.subdiagnostics = subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
602 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
603 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
604 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
605 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
606 |
return subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
607 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
608 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
609 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
610 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
611 |
return true; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
612 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
613 |
} |
10 | 614 |
} |