99 * @param log The log on which to generate any diagnostics |
99 * @param log The log on which to generate any diagnostics |
100 * @param verbose Specify whether or not detailed messages about |
100 * @param verbose Specify whether or not detailed messages about |
101 * individual instances should be given, or whether an aggregate |
101 * individual instances should be given, or whether an aggregate |
102 * message should be generated at the end of the compilation. |
102 * message should be generated at the end of the compilation. |
103 * Typically set via -Xlint:option. |
103 * Typically set via -Xlint:option. |
|
104 * @param enforceMandatory |
|
105 * True if mandatory warnings and notes are being enforced. |
104 * @param prefix A common prefix for the set of message keys for |
106 * @param prefix A common prefix for the set of message keys for |
105 * the messages that may be generated. |
107 * the messages that may be generated. |
106 */ |
108 */ |
107 public MandatoryWarningHandler(Log log, boolean verbose, String prefix) { |
109 public MandatoryWarningHandler(Log log, boolean verbose, |
|
110 boolean enforceMandatory, String prefix) { |
108 this.log = log; |
111 this.log = log; |
109 this.verbose = verbose; |
112 this.verbose = verbose; |
110 this.prefix = prefix; |
113 this.prefix = prefix; |
|
114 this.enforceMandatory = enforceMandatory; |
111 } |
115 } |
112 |
116 |
113 /** |
117 /** |
114 * Report a mandatory warning. |
118 * Report a mandatory warning. |
115 */ |
119 */ |
120 if (sourcesWithReportedWarnings == null) |
124 if (sourcesWithReportedWarnings == null) |
121 sourcesWithReportedWarnings = new HashSet<JavaFileObject>(); |
125 sourcesWithReportedWarnings = new HashSet<JavaFileObject>(); |
122 |
126 |
123 if (log.nwarnings < log.MaxWarnings) { |
127 if (log.nwarnings < log.MaxWarnings) { |
124 // generate message and remember the source file |
128 // generate message and remember the source file |
125 log.mandatoryWarning(pos, msg, args); |
129 logMandatoryWarning(pos, msg, args); |
126 sourcesWithReportedWarnings.add(currentSource); |
130 sourcesWithReportedWarnings.add(currentSource); |
127 } else if (deferredDiagnosticKind == null) { |
131 } else if (deferredDiagnosticKind == null) { |
128 // set up deferred message |
132 // set up deferred message |
129 if (sourcesWithReportedWarnings.contains(currentSource)) { |
133 if (sourcesWithReportedWarnings.contains(currentSource)) { |
130 // more errors in a file that already has reported warnings |
134 // more errors in a file that already has reported warnings |
161 * Report any diagnostic that might have been deferred by previous calls of report(). |
165 * Report any diagnostic that might have been deferred by previous calls of report(). |
162 */ |
166 */ |
163 public void reportDeferredDiagnostic() { |
167 public void reportDeferredDiagnostic() { |
164 if (deferredDiagnosticKind != null) { |
168 if (deferredDiagnosticKind != null) { |
165 if (deferredDiagnosticArg == null) |
169 if (deferredDiagnosticArg == null) |
166 log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix)); |
170 logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix)); |
167 else |
171 else |
168 log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg); |
172 logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg); |
169 |
173 |
170 if (!verbose) |
174 if (!verbose) |
171 log.mandatoryNote(deferredDiagnosticSource, prefix + ".recompile"); |
175 logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile"); |
172 } |
176 } |
173 } |
177 } |
174 |
178 |
175 /** |
179 /** |
176 * Check two objects, each possibly null, are either both null or are equal. |
180 * Check two objects, each possibly null, are either both null or are equal. |
222 * deferred diagnostic message, based on deferredDiagnosticKind. |
226 * deferred diagnostic message, based on deferredDiagnosticKind. |
223 * This variable should normally be set/updated whenever |
227 * This variable should normally be set/updated whenever |
224 * deferredDiagnosticKind is updated. |
228 * deferredDiagnosticKind is updated. |
225 */ |
229 */ |
226 private Object deferredDiagnosticArg; |
230 private Object deferredDiagnosticArg; |
|
231 |
|
232 /** |
|
233 * True if mandatory warnings and notes are being enforced. |
|
234 */ |
|
235 private final boolean enforceMandatory; |
|
236 |
|
237 /** |
|
238 * Reports a mandatory warning to the log. If mandatory warnings |
|
239 * are not being enforced, treat this as an ordinary warning. |
|
240 */ |
|
241 private void logMandatoryWarning(DiagnosticPosition pos, String msg, |
|
242 Object... args) { |
|
243 if (enforceMandatory) |
|
244 log.mandatoryWarning(pos, msg, args); |
|
245 else |
|
246 log.warning(pos, msg, args); |
|
247 } |
|
248 |
|
249 /** |
|
250 * Reports a mandatory note to the log. If mandatory notes are |
|
251 * not being enforced, treat this as an ordinary note. |
|
252 */ |
|
253 private void logMandatoryNote(JavaFileObject file, String msg, Object... args) { |
|
254 if (enforceMandatory) |
|
255 log.mandatoryNote(file, msg, args); |
|
256 else |
|
257 log.note(file, msg, args); |
|
258 } |
227 } |
259 } |