author | jlahoda |
Fri, 15 Feb 2019 12:09:53 +0100 | |
changeset 53773 | 454d54d8af1c |
parent 48721 | ef3557eb4306 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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; |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
31 |
import java.util.stream.Stream; |
10 | 32 |
|
33 |
import javax.tools.Diagnostic; |
|
34 |
import javax.tools.JavaFileObject; |
|
35 |
||
942 | 36 |
import com.sun.tools.javac.api.DiagnosticFormatter; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
37 |
import com.sun.tools.javac.code.Lint.LintCategory; |
13077 | 38 |
import com.sun.tools.javac.tree.EndPosTable; |
10 | 39 |
import com.sun.tools.javac.tree.JCTree; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
40 |
import com.sun.tools.javac.util.DefinedBy.Api; |
10 | 41 |
|
42 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; |
|
43 |
||
44 |
/** An abstraction of a diagnostic message generated by the compiler. |
|
45 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
46 |
* <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
|
47 |
* If you write code that depends on this, you do so at your own risk. |
10 | 48 |
* This code and its internal interfaces are subject to change or |
49 |
* deletion without notice.</b> |
|
50 |
*/ |
|
51 |
public class JCDiagnostic implements Diagnostic<JavaFileObject> { |
|
52 |
/** A factory for creating diagnostic objects. */ |
|
53 |
public static class Factory { |
|
54 |
/** The context key for the diagnostic factory. */ |
|
22163 | 55 |
protected static final Context.Key<JCDiagnostic.Factory> diagnosticFactoryKey = new Context.Key<>(); |
10 | 56 |
|
57 |
/** Get the Factory instance for this context. */ |
|
58 |
public static Factory instance(Context context) { |
|
59 |
Factory instance = context.get(diagnosticFactoryKey); |
|
60 |
if (instance == null) |
|
61 |
instance = new Factory(context); |
|
62 |
return instance; |
|
63 |
} |
|
64 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
65 |
DiagnosticFormatter<JCDiagnostic> formatter; |
10 | 66 |
final String prefix; |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
67 |
final Set<DiagnosticFlag> defaultErrorFlags; |
10 | 68 |
|
69 |
/** Create a new diagnostic factory. */ |
|
70 |
protected Factory(Context context) { |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
71 |
this(JavacMessages.instance(context), "compiler"); |
10 | 72 |
context.put(diagnosticFactoryKey, this); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
73 |
|
11052 | 74 |
final Options options = Options.instance(context); |
75 |
initOptions(options); |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
40504
diff
changeset
|
76 |
options.addListener(() -> initOptions(options)); |
11052 | 77 |
} |
78 |
||
79 |
private void initOptions(Options options) { |
|
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
80 |
if (options.isSet("onlySyntaxErrorsUnrecoverable")) |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
81 |
defaultErrorFlags.add(DiagnosticFlag.RECOVERABLE); |
10 | 82 |
} |
83 |
||
84 |
/** Create a new diagnostic factory. */ |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
85 |
public Factory(JavacMessages messages, String prefix) { |
10 | 86 |
this.prefix = prefix; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
87 |
this.formatter = new BasicDiagnosticFormatter(messages); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
88 |
defaultErrorFlags = EnumSet.of(DiagnosticFlag.MANDATORY); |
10 | 89 |
} |
90 |
||
91 |
/** |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
92 |
* Create an error diagnostic |
10 | 93 |
* @param source The source of the compilation unit, if any, in which to report the error. |
94 |
* @param pos The source position at which to report the error. |
|
95 |
* @param key The key for the localized error message. |
|
96 |
* @param args Fields of the error message. |
|
97 |
*/ |
|
98 |
public JCDiagnostic error( |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
99 |
DiagnosticFlag flag, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
100 |
return error(flag, source, pos, errorKey(key, args)); |
10 | 101 |
} |
102 |
||
103 |
/** |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
104 |
* Create an error diagnostic |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
105 |
* @param source The source of the compilation unit, if any, in which to report the error. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
106 |
* @param pos The source position at which to report the error. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
107 |
* @param errorKey The key for the localized error message. |
10 | 108 |
*/ |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
109 |
public JCDiagnostic error( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
110 |
DiagnosticFlag flag, DiagnosticSource source, DiagnosticPosition pos, Error errorKey) { |
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
111 |
JCDiagnostic diag = create(null, EnumSet.copyOf(defaultErrorFlags), source, pos, errorKey); |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
112 |
if (flag != null) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
113 |
diag.setFlag(flag); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
114 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
115 |
return diag; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
116 |
} |
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 |
* 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
|
120 |
* @param lc The lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
121 |
* @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
|
122 |
* @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
|
123 |
* @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
|
124 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
125 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
126 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
127 |
public JCDiagnostic mandatoryWarning( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
128 |
LintCategory lc, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
129 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
130 |
return mandatoryWarning(lc, source, pos, warningKey(key, args)); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
131 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
132 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
133 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
134 |
* Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
135 |
* @param lc The lint category for the diagnostic |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
136 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
137 |
* @param pos The source position at which to report the warning. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
138 |
* @param warningKey The key for the localized warning message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
139 |
* @see MandatoryWarningHandler |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
140 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
141 |
public JCDiagnostic mandatoryWarning( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
142 |
LintCategory lc, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
143 |
DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
144 |
return create(lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, warningKey); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
145 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
146 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
147 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
148 |
* Create a warning diagnostic. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
149 |
* @param lc The lint category for the diagnostic |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
150 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
151 |
* @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
|
152 |
* @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
|
153 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
154 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
155 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
156 |
public JCDiagnostic warning( |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
157 |
LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
158 |
return warning(lc, source, pos, warningKey(key, args)); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
159 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
160 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
161 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
162 |
* Create a warning diagnostic. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
163 |
* @param lc The lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
164 |
* @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
|
165 |
* @param pos The source position at which to report the warning. |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
166 |
* @param warningKey The key for the localized warning message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
167 |
* @see MandatoryWarningHandler |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
168 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
169 |
public JCDiagnostic warning( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
170 |
LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
171 |
return create(lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, warningKey); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
172 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
173 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
174 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
175 |
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
176 |
* @param source The source of the compilation unit, if any, in which to report the warning. |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
177 |
* @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
|
178 |
* @param args Fields of the warning message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
179 |
* @see MandatoryWarningHandler |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
180 |
*/ |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
181 |
public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
182 |
return mandatoryNote(source, noteKey(key, args)); |
10 | 183 |
} |
184 |
||
185 |
/** |
|
186 |
* Create a note diagnostic that will not be hidden by the -nowarn or -Xlint:none options. |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
187 |
* @param noteKey The key for the localized note message. |
10 | 188 |
* @see MandatoryWarningHandler |
189 |
*/ |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
190 |
public JCDiagnostic mandatoryNote(DiagnosticSource source, Note noteKey) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
191 |
return create(null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, noteKey); |
10 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Create a note diagnostic. |
|
196 |
* @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
|
197 |
* @param args Fields of the message. |
10 | 198 |
*/ |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
199 |
public JCDiagnostic note( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
200 |
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
201 |
return note(source, pos, noteKey(key, args)); |
10 | 202 |
} |
203 |
||
204 |
/** |
|
205 |
* Create a note diagnostic. |
|
206 |
* @param source The source of the compilation unit, if any, in which to report the note. |
|
207 |
* @param pos The source position at which to report the note. |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
208 |
* @param noteKey The key for the localized note message. |
10 | 209 |
*/ |
210 |
public JCDiagnostic note( |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
211 |
DiagnosticSource source, DiagnosticPosition pos, Note noteKey) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
212 |
return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, noteKey); |
10 | 213 |
} |
214 |
||
215 |
/** |
|
216 |
* 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
|
217 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
218 |
* @param args Fields of the message. |
10 | 219 |
*/ |
220 |
public JCDiagnostic fragment(String key, Object... args) { |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
221 |
return fragment(fragmentKey(key, args)); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
222 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
223 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
224 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
225 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
226 |
* @param fragmentKey The key for the localized subdiagnostic message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
227 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
228 |
public JCDiagnostic fragment(Fragment fragmentKey) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
229 |
return create(null, EnumSet.noneOf(DiagnosticFlag.class), null, null, fragmentKey); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
230 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
231 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
232 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
233 |
* 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
|
234 |
* no lint category. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
235 |
* @param kind The diagnostic kind |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
236 |
* @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
|
237 |
* @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
|
238 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
239 |
* @param args Fields of the message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
240 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
241 |
public JCDiagnostic create( |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
242 |
DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
243 |
return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args)); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
244 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
245 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
246 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
247 |
* Create a new diagnostic of the given kind, which is not mandatory and which has |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
248 |
* no lint category. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
249 |
* @param source The source of the compilation unit, if any, in which to report the message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
250 |
* @param pos The source position at which to report the message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
251 |
* @param diagnosticInfo The key for the localized message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
252 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
253 |
public JCDiagnostic create( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
254 |
DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
255 |
return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, diagnosticInfo); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
256 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
257 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
258 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
259 |
* Create a new diagnostic of the given kind. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
260 |
* @param kind The diagnostic kind |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
261 |
* @param lc The lint category, if applicable, or null |
14259 | 262 |
* @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
|
263 |
* @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
|
264 |
* @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
|
265 |
* @param key The key for the localized message. |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
266 |
* @param args Fields of the message. |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1591
diff
changeset
|
267 |
*/ |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
268 |
public JCDiagnostic create(DiagnosticType kind, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
269 |
LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
270 |
return create(lc, flags, source, pos, DiagnosticInfo.of(kind, prefix, key, args)); |
10 | 271 |
} |
272 |
||
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
273 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
274 |
* Create a new diagnostic with given key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
275 |
* @param lc The lint category, if applicable, or null |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
276 |
* @param flags The set of flags for the diagnostic |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
277 |
* @param source The source of the compilation unit, if any, in which to report the message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
278 |
* @param pos The source position at which to report the message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
279 |
* @param diagnosticInfo The key for the localized message. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
280 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
281 |
public JCDiagnostic create( |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
282 |
LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
283 |
return new JCDiagnostic(formatter, normalize(diagnosticInfo), lc, flags, source, pos); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
284 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
285 |
//where |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
286 |
DiagnosticInfo normalize(DiagnosticInfo diagnosticInfo) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
287 |
//replace all nested FragmentKey with full-blown JCDiagnostic objects |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
288 |
return DiagnosticInfo.of(diagnosticInfo.type, diagnosticInfo.prefix, diagnosticInfo.code, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
289 |
Stream.of(diagnosticInfo.args).map(o -> { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
290 |
return (o instanceof Fragment) ? |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
291 |
fragment((Fragment)o) : o; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
292 |
}).toArray()); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
293 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
294 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
295 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
296 |
* Create a new error key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
297 |
*/ |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
298 |
public Error errorKey(String code, Object... args) { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
299 |
return (Error)DiagnosticInfo.of(ERROR, prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
300 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
301 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
302 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
303 |
* Create a new warning key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
304 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
305 |
Warning warningKey(String code, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
306 |
return (Warning)DiagnosticInfo.of(WARNING, prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
307 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
308 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
309 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
310 |
* Create a new note key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
311 |
*/ |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
312 |
public Note noteKey(String code, Object... args) { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
313 |
return (Note)DiagnosticInfo.of(NOTE, prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
314 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
315 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
316 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
317 |
* Create a new fragment key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
318 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
319 |
Fragment fragmentKey(String code, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
320 |
return (Fragment)DiagnosticInfo.of(FRAGMENT, prefix, code, args); |
10 | 321 |
} |
322 |
} |
|
323 |
||
324 |
||
325 |
||
326 |
/** |
|
327 |
* Create a fragment diagnostic, for use as an argument in other diagnostics |
|
328 |
* @param key The key for the localized error message. |
|
329 |
* @param args Fields of the error message. |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
330 |
* |
10 | 331 |
*/ |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
332 |
@Deprecated |
10 | 333 |
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
|
334 |
return new JCDiagnostic(getFragmentFormatter(), |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
335 |
DiagnosticInfo.of(FRAGMENT, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
336 |
"compiler", |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
337 |
key, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
338 |
args), |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
339 |
null, |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
340 |
EnumSet.noneOf(DiagnosticFlag.class), |
10 | 341 |
null, |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
342 |
null); |
10 | 343 |
} |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
344 |
//where |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
345 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
346 |
public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() { |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
347 |
if (fragmentFormatter == null) { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
348 |
fragmentFormatter = new BasicDiagnosticFormatter(JavacMessages.getDefaultMessages()); |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
349 |
} |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
350 |
return fragmentFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
351 |
} |
10 | 352 |
|
353 |
/** |
|
354 |
* A DiagnosticType defines the type of the diagnostic. |
|
355 |
**/ |
|
356 |
public enum DiagnosticType { |
|
357 |
/** A fragment of an enclosing diagnostic. */ |
|
358 |
FRAGMENT("misc"), |
|
359 |
/** A note: similar to, but less serious than, a warning. */ |
|
360 |
NOTE("note"), |
|
361 |
/** A warning. */ |
|
362 |
WARNING("warn"), |
|
363 |
/** An error. */ |
|
364 |
ERROR("err"); |
|
365 |
||
366 |
final String key; |
|
367 |
||
368 |
/** Create a DiagnosticType. |
|
369 |
* @param key A string used to create the resource key for the diagnostic. |
|
370 |
*/ |
|
371 |
DiagnosticType(String key) { |
|
372 |
this.key = key; |
|
373 |
} |
|
22163 | 374 |
} |
10 | 375 |
|
376 |
/** |
|
377 |
* A DiagnosticPosition provides information about the positions in a file |
|
378 |
* that gave rise to a diagnostic. It always defines a "preferred" position |
|
379 |
* that most accurately defines the location of the diagnostic, it may also |
|
380 |
* provide a related tree node that spans that location. |
|
381 |
*/ |
|
382 |
public static interface DiagnosticPosition { |
|
383 |
/** Gets the tree node, if any, to which the diagnostic applies. */ |
|
384 |
JCTree getTree(); |
|
385 |
/** If there is a tree node, get the start position of the tree node. |
|
386 |
* Otherwise, just returns the same as getPreferredPosition(). */ |
|
387 |
int getStartPosition(); |
|
388 |
/** Get the position within the file that most accurately defines the |
|
389 |
* location for the diagnostic. */ |
|
390 |
int getPreferredPosition(); |
|
391 |
/** If there is a tree node, and if endPositions are available, get |
|
392 |
* the end position of the tree node. Otherwise, just returns the |
|
393 |
* same as getPreferredPosition(). */ |
|
11055 | 394 |
int getEndPosition(EndPosTable endPosTable); |
10 | 395 |
} |
396 |
||
397 |
/** |
|
398 |
* A DiagnosticPosition that simply identifies a position, but no related |
|
399 |
* tree node, as the location for a diagnostic. Used for scanner and parser |
|
400 |
* diagnostics. */ |
|
401 |
public static class SimpleDiagnosticPosition implements DiagnosticPosition { |
|
402 |
public SimpleDiagnosticPosition(int pos) { |
|
403 |
this.pos = pos; |
|
404 |
} |
|
405 |
||
406 |
public JCTree getTree() { |
|
407 |
return null; |
|
408 |
} |
|
409 |
||
410 |
public int getStartPosition() { |
|
411 |
return pos; |
|
412 |
} |
|
413 |
||
414 |
public int getPreferredPosition() { |
|
415 |
return pos; |
|
416 |
} |
|
417 |
||
11055 | 418 |
public int getEndPosition(EndPosTable endPosTable) { |
10 | 419 |
return pos; |
420 |
} |
|
421 |
||
422 |
private final int pos; |
|
423 |
} |
|
424 |
||
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
425 |
public enum DiagnosticFlag { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
426 |
MANDATORY, |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
427 |
RESOLVE_ERROR, |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
428 |
SYNTAX, |
16326
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
16309
diff
changeset
|
429 |
RECOVERABLE, |
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
16309
diff
changeset
|
430 |
NON_DEFERRABLE, |
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
431 |
COMPRESSED, |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
48721
diff
changeset
|
432 |
/** Flag for diagnostics that were reported through API methods. |
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
433 |
*/ |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
48721
diff
changeset
|
434 |
API, |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
28455
diff
changeset
|
435 |
/** Flag for not-supported-in-source-X errors. |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
28455
diff
changeset
|
436 |
*/ |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
28455
diff
changeset
|
437 |
SOURCE_LEVEL; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
438 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
439 |
|
10 | 440 |
private final DiagnosticSource source; |
441 |
private final DiagnosticPosition position; |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
442 |
private final DiagnosticInfo diagnosticInfo; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
443 |
private final Set<DiagnosticFlag> flags; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
444 |
private final LintCategory lintCategory; |
10 | 445 |
|
25010 | 446 |
/** source line position (set lazily) */ |
447 |
private SourcePosition sourcePosition; |
|
448 |
||
449 |
/** |
|
450 |
* This class is used to defer the line/column position fetch logic after diagnostic construction. |
|
451 |
*/ |
|
452 |
class SourcePosition { |
|
453 |
||
454 |
private final int line; |
|
455 |
private final int column; |
|
456 |
||
457 |
SourcePosition() { |
|
458 |
int n = (position == null ? Position.NOPOS : position.getPreferredPosition()); |
|
459 |
if (n == Position.NOPOS || source == null) |
|
460 |
line = column = -1; |
|
461 |
else { |
|
462 |
line = source.getLineNumber(n); |
|
463 |
column = source.getColumnNumber(n, true); |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
public int getLineNumber() { |
|
468 |
return line; |
|
469 |
} |
|
470 |
||
471 |
public int getColumnNumber() { |
|
472 |
return column; |
|
473 |
} |
|
474 |
} |
|
475 |
||
10 | 476 |
/** |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
477 |
* A diagnostic key object encapsulates basic properties of a diagnostic, such as the resource key, |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
478 |
* the arguments and the kind associated with the diagnostic object. Diagnostic keys can be either |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
479 |
* created programmatically (by using the supplied factory method) or obtained through build-time |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
480 |
* generated factory methods. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
481 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
482 |
public static abstract class DiagnosticInfo { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
483 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
484 |
/** The diagnostic kind (i.e. error). */ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
485 |
DiagnosticType type; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
486 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
487 |
/** The diagnostic prefix (i.e. 'javac'); used to compute full resource key. */ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
488 |
String prefix; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
489 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
490 |
/** The diagnostic code (i.e. 'cannot.resolve.sym'); together with {@code prefix} it forms |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
491 |
* the full resource key. */ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
492 |
String code; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
493 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
494 |
/** The diagnostic arguments. */ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
495 |
Object[] args; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
496 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
497 |
private DiagnosticInfo(DiagnosticType type, String prefix, String code, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
498 |
this.type = type; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
499 |
this.prefix = prefix; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
500 |
this.code = code; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
501 |
this.args = args; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
502 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
503 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
504 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
505 |
* Compute the resource key. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
506 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
507 |
public String key() { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
508 |
return prefix + "." + type.key + "." + code; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
509 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
510 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
511 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
512 |
* Static factory method; build a custom diagnostic key using given kind, prefix, code and args. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
513 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
514 |
public static DiagnosticInfo of(DiagnosticType type, String prefix, String code, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
515 |
switch (type) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
516 |
case ERROR: |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
517 |
return new Error(prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
518 |
case WARNING: |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
519 |
return new Warning(prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
520 |
case NOTE: |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
521 |
return new Note(prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
522 |
case FRAGMENT: |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
523 |
return new Fragment(prefix, code, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
524 |
default: |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
525 |
Assert.error("Wrong diagnostic type: " + type); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
526 |
return null; |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
527 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
528 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
529 |
|
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
530 |
/** |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
531 |
* Returns the code for this diagnostic info, provided mainly for backward compatibility |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
532 |
*/ |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
533 |
public String getCode() { |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
534 |
return code; |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
535 |
} |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
536 |
|
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
537 |
/** |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
538 |
* Returns the arguments for this diagnostic info, provided mainly for backward compatibility |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
539 |
*/ |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
540 |
public Object[] getArgs() { |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
541 |
return args; |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
542 |
} |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
543 |
|
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
544 |
public void setArgs(Object[] args) { |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
545 |
this.args = args; |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
47216
diff
changeset
|
546 |
} |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
547 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
548 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
549 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
550 |
* Class representing error diagnostic keys. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
551 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
552 |
public static final class Error extends DiagnosticInfo { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
553 |
public Error(String prefix, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
554 |
super(DiagnosticType.ERROR, prefix, key, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
555 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
556 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
557 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
558 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
559 |
* Class representing warning diagnostic keys. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
560 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
561 |
public static final class Warning extends DiagnosticInfo { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
562 |
public Warning(String prefix, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
563 |
super(DiagnosticType.WARNING, prefix, key, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
564 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
565 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
566 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
567 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
568 |
* Class representing note diagnostic keys. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
569 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
570 |
public static final class Note extends DiagnosticInfo { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
571 |
public Note(String prefix, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
572 |
super(DiagnosticType.NOTE, prefix, key, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
573 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
574 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
575 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
576 |
/** |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
577 |
* Class representing fragment diagnostic keys. |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
578 |
*/ |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
579 |
public static final class Fragment extends DiagnosticInfo { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
580 |
public Fragment(String prefix, String key, Object... args) { |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
581 |
super(DiagnosticType.FRAGMENT, prefix, key, args); |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
582 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
583 |
} |
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
584 |
|
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
585 |
/** |
10 | 586 |
* Create a diagnostic object. |
14259 | 587 |
* @param formatter the formatter to use for the diagnostic |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
588 |
* @param diagnosticInfo the diagnostic key |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
589 |
* @param lc the lint category for the diagnostic |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
590 |
* @param source the name of the source file, or null if none. |
10 | 591 |
* @param pos the character offset within the source file, if given. |
592 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
593 |
protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter, |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
594 |
DiagnosticInfo diagnosticInfo, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
595 |
LintCategory lc, |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
596 |
Set<DiagnosticFlag> flags, |
10 | 597 |
DiagnosticSource source, |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
598 |
DiagnosticPosition pos) { |
10 | 599 |
if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) |
600 |
throw new IllegalArgumentException(); |
|
601 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
602 |
this.defaultFormatter = formatter; |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
603 |
this.diagnosticInfo = diagnosticInfo; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
604 |
this.lintCategory = lc; |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
605 |
this.flags = flags; |
10 | 606 |
this.source = source; |
607 |
this.position = pos; |
|
608 |
} |
|
609 |
||
610 |
/** |
|
611 |
* Get the type of this diagnostic. |
|
612 |
* @return the type of this diagnostic |
|
613 |
*/ |
|
614 |
public DiagnosticType getType() { |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
615 |
return diagnosticInfo.type; |
10 | 616 |
} |
617 |
||
618 |
/** |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
619 |
* Get the subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
620 |
* @return subdiagnostic list |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
621 |
*/ |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
622 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
623 |
return List.nil(); |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
624 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
625 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
626 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
627 |
return false; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
628 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
629 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
630 |
/** |
10 | 631 |
* Check whether or not this diagnostic is required to be shown. |
632 |
* @return true if this diagnostic is required to be shown. |
|
633 |
*/ |
|
634 |
public boolean isMandatory() { |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
635 |
return flags.contains(DiagnosticFlag.MANDATORY); |
10 | 636 |
} |
637 |
||
638 |
/** |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
639 |
* 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
|
640 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
641 |
public boolean hasLintCategory() { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
642 |
return (lintCategory != null); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
643 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
644 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
645 |
/** |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
646 |
* 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
|
647 |
*/ |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
648 |
public LintCategory getLintCategory() { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
649 |
return lintCategory; |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
650 |
} |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
651 |
|
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
652 |
/** |
10 | 653 |
* Get the name of the source file referred to by this diagnostic. |
654 |
* @return the name of the source referred to with this diagnostic, or null if none |
|
655 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
656 |
@DefinedBy(Api.COMPILER) |
10 | 657 |
public JavaFileObject getSource() { |
658 |
if (source == null) |
|
659 |
return null; |
|
660 |
else |
|
661 |
return source.getFile(); |
|
662 |
} |
|
663 |
||
664 |
/** |
|
665 |
* Get the source referred to by this diagnostic. |
|
666 |
* @return the source referred to with this diagnostic, or null if none |
|
667 |
*/ |
|
668 |
public DiagnosticSource getDiagnosticSource() { |
|
669 |
return source; |
|
670 |
} |
|
671 |
||
672 |
protected int getIntStartPosition() { |
|
673 |
return (position == null ? Position.NOPOS : position.getStartPosition()); |
|
674 |
} |
|
675 |
||
676 |
protected int getIntPosition() { |
|
677 |
return (position == null ? Position.NOPOS : position.getPreferredPosition()); |
|
678 |
} |
|
679 |
||
680 |
protected int getIntEndPosition() { |
|
681 |
return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable())); |
|
682 |
} |
|
683 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
684 |
@DefinedBy(Api.COMPILER) |
10 | 685 |
public long getStartPosition() { |
686 |
return getIntStartPosition(); |
|
687 |
} |
|
688 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
689 |
@DefinedBy(Api.COMPILER) |
10 | 690 |
public long getPosition() { |
691 |
return getIntPosition(); |
|
692 |
} |
|
693 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
694 |
@DefinedBy(Api.COMPILER) |
10 | 695 |
public long getEndPosition() { |
696 |
return getIntEndPosition(); |
|
697 |
} |
|
698 |
||
16309
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
699 |
public DiagnosticPosition getDiagnosticPosition() { |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
700 |
return position; |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
701 |
} |
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
15385
diff
changeset
|
702 |
|
10 | 703 |
/** |
704 |
* Get the line number within the source referred to by this diagnostic. |
|
705 |
* @return the line number within the source referred to by this diagnostic |
|
706 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
707 |
@DefinedBy(Api.COMPILER) |
10 | 708 |
public long getLineNumber() { |
25010 | 709 |
if (sourcePosition == null) { |
710 |
sourcePosition = new SourcePosition(); |
|
711 |
} |
|
712 |
return sourcePosition.getLineNumber(); |
|
10 | 713 |
} |
714 |
||
715 |
/** |
|
716 |
* Get the column number within the line of source referred to by this diagnostic. |
|
717 |
* @return the column number within the line of source referred to by this diagnostic |
|
718 |
*/ |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
719 |
@DefinedBy(Api.COMPILER) |
10 | 720 |
public long getColumnNumber() { |
25010 | 721 |
if (sourcePosition == null) { |
722 |
sourcePosition = new SourcePosition(); |
|
723 |
} |
|
724 |
return sourcePosition.getColumnNumber(); |
|
10 | 725 |
} |
726 |
||
727 |
/** |
|
728 |
* Get the arguments to be included in the text of the diagnostic. |
|
729 |
* @return the arguments to be included in the text of the diagnostic |
|
730 |
*/ |
|
731 |
public Object[] getArgs() { |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
732 |
return diagnosticInfo.args; |
10 | 733 |
} |
734 |
||
735 |
/** |
|
736 |
* Get the prefix string associated with this type of diagnostic. |
|
737 |
* @return the prefix string associated with this type of diagnostic |
|
738 |
*/ |
|
739 |
public String getPrefix() { |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
740 |
return getPrefix(diagnosticInfo.type); |
10 | 741 |
} |
742 |
||
743 |
/** |
|
744 |
* Get the prefix string associated with a particular type of diagnostic. |
|
745 |
* @return the prefix string associated with a particular type of diagnostic |
|
746 |
*/ |
|
747 |
public String getPrefix(DiagnosticType dt) { |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
748 |
return defaultFormatter.formatKind(this, Locale.getDefault()); |
942 | 749 |
} |
750 |
||
10 | 751 |
/** |
752 |
* Return the standard presentation of this diagnostic. |
|
753 |
*/ |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3143
diff
changeset
|
754 |
@Override |
10 | 755 |
public String toString() { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
756 |
return defaultFormatter.format(this, Locale.getDefault()); |
10 | 757 |
} |
758 |
||
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
759 |
private DiagnosticFormatter<JCDiagnostic> defaultFormatter; |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
760 |
@Deprecated |
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
761 |
private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter; |
10 | 762 |
|
763 |
// Methods for javax.tools.Diagnostic |
|
764 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
765 |
@DefinedBy(Api.COMPILER) |
10 | 766 |
public Diagnostic.Kind getKind() { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
767 |
switch (diagnosticInfo.type) { |
10 | 768 |
case NOTE: |
769 |
return Diagnostic.Kind.NOTE; |
|
770 |
case WARNING: |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
771 |
return flags.contains(DiagnosticFlag.MANDATORY) |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
772 |
? Diagnostic.Kind.MANDATORY_WARNING |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
773 |
: Diagnostic.Kind.WARNING; |
10 | 774 |
case ERROR: |
775 |
return Diagnostic.Kind.ERROR; |
|
776 |
default: |
|
777 |
return Diagnostic.Kind.OTHER; |
|
778 |
} |
|
779 |
} |
|
780 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
781 |
@DefinedBy(Api.COMPILER) |
10 | 782 |
public String getCode() { |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
783 |
return diagnosticInfo.key(); |
10 | 784 |
} |
785 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
786 |
@DefinedBy(Api.COMPILER) |
10 | 787 |
public String getMessage(Locale locale) { |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
942
diff
changeset
|
788 |
return defaultFormatter.formatMessage(this, locale); |
10 | 789 |
} |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
790 |
|
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
791 |
public void setFlag(DiagnosticFlag flag) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
792 |
flags.add(flag); |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
793 |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
794 |
if (diagnosticInfo.type == DiagnosticType.ERROR) { |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
795 |
switch (flag) { |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
796 |
case SYNTAX: |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
797 |
flags.remove(DiagnosticFlag.RECOVERABLE); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
798 |
break; |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
799 |
case RESOLVE_ERROR: |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
800 |
flags.add(DiagnosticFlag.RECOVERABLE); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
801 |
break; |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
802 |
} |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
6356
diff
changeset
|
803 |
} |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
804 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
805 |
|
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
806 |
public boolean isFlagSet(DiagnosticFlag flag) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
807 |
return flags.contains(flag); |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
808 |
} |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
809 |
|
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
810 |
public static class MultilineDiagnostic extends JCDiagnostic { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
811 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
812 |
private final List<JCDiagnostic> subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
813 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
814 |
public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
815 |
super(other.defaultFormatter, |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
816 |
other.diagnosticInfo, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
817 |
other.getLintCategory(), |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6151
diff
changeset
|
818 |
other.flags, |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
819 |
other.getDiagnosticSource(), |
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
26266
diff
changeset
|
820 |
other.position); |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
821 |
this.subdiagnostics = subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
822 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
823 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
824 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
825 |
public List<JCDiagnostic> getSubdiagnostics() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
826 |
return subdiagnostics; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
827 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
828 |
|
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
829 |
@Override |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
830 |
public boolean isMultiline() { |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
831 |
return true; |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
832 |
} |
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1471
diff
changeset
|
833 |
} |
10 | 834 |
} |