1 /* |
1 /* |
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
29 import java.util.Set; |
29 import java.util.Set; |
30 import javax.tools.JavaFileObject; |
30 import javax.tools.JavaFileObject; |
31 |
31 |
32 import com.sun.tools.javac.code.Lint.LintCategory; |
32 import com.sun.tools.javac.code.Lint.LintCategory; |
33 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
33 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
34 import com.sun.tools.javac.util.JCDiagnostic.Note; |
|
35 import com.sun.tools.javac.util.JCDiagnostic.Warning; |
34 |
36 |
35 |
37 |
36 /** |
38 /** |
37 * A handler to process mandatory warnings, setting up a deferred diagnostic |
39 * A handler to process mandatory warnings, setting up a deferred diagnostic |
38 * to be printed at the end of the compilation if some warnings get suppressed |
40 * to be printed at the end of the compilation if some warnings get suppressed |
119 } |
121 } |
120 |
122 |
121 /** |
123 /** |
122 * Report a mandatory warning. |
124 * Report a mandatory warning. |
123 */ |
125 */ |
124 public void report(DiagnosticPosition pos, String msg, Object... args) { |
126 public void report(DiagnosticPosition pos, Warning warnKey) { |
125 JavaFileObject currentSource = log.currentSourceFile(); |
127 JavaFileObject currentSource = log.currentSourceFile(); |
126 |
128 |
127 if (verbose) { |
129 if (verbose) { |
128 if (sourcesWithReportedWarnings == null) |
130 if (sourcesWithReportedWarnings == null) |
129 sourcesWithReportedWarnings = new HashSet<>(); |
131 sourcesWithReportedWarnings = new HashSet<>(); |
130 |
132 |
131 if (log.nwarnings < log.MaxWarnings) { |
133 if (log.nwarnings < log.MaxWarnings) { |
132 // generate message and remember the source file |
134 // generate message and remember the source file |
133 logMandatoryWarning(pos, msg, args); |
135 logMandatoryWarning(pos, warnKey); |
134 sourcesWithReportedWarnings.add(currentSource); |
136 sourcesWithReportedWarnings.add(currentSource); |
135 } else if (deferredDiagnosticKind == null) { |
137 } else if (deferredDiagnosticKind == null) { |
136 // set up deferred message |
138 // set up deferred message |
137 if (sourcesWithReportedWarnings.contains(currentSource)) { |
139 if (sourcesWithReportedWarnings.contains(currentSource)) { |
138 // more errors in a file that already has reported warnings |
140 // more errors in a file that already has reported warnings |
246 |
248 |
247 /** |
249 /** |
248 * Reports a mandatory warning to the log. If mandatory warnings |
250 * Reports a mandatory warning to the log. If mandatory warnings |
249 * are not being enforced, treat this as an ordinary warning. |
251 * are not being enforced, treat this as an ordinary warning. |
250 */ |
252 */ |
251 private void logMandatoryWarning(DiagnosticPosition pos, String msg, |
253 private void logMandatoryWarning(DiagnosticPosition pos, Warning warnKey) { |
252 Object... args) { |
|
253 // Note: the following log methods are safe if lintCategory is null. |
254 // Note: the following log methods are safe if lintCategory is null. |
254 if (enforceMandatory) |
255 if (enforceMandatory) |
255 log.mandatoryWarning(lintCategory, pos, msg, args); |
256 log.mandatoryWarning(lintCategory, pos, warnKey); |
256 else |
257 else |
257 log.warning(lintCategory, pos, msg, args); |
258 log.warning(lintCategory, pos, warnKey); |
258 } |
259 } |
259 |
260 |
260 /** |
261 /** |
261 * Reports a mandatory note to the log. If mandatory notes are |
262 * Reports a mandatory note to the log. If mandatory notes are |
262 * not being enforced, treat this as an ordinary note. |
263 * not being enforced, treat this as an ordinary note. |
263 */ |
264 */ |
264 private void logMandatoryNote(JavaFileObject file, String msg, Object... args) { |
265 private void logMandatoryNote(JavaFileObject file, String msg, Object... args) { |
265 if (enforceMandatory) |
266 if (enforceMandatory) |
266 log.mandatoryNote(file, msg, args); |
267 log.mandatoryNote(file, new Note("compiler", msg, args)); |
267 else |
268 else |
268 log.note(file, msg, args); |
269 log.note(file, new Note("compiler", msg, args)); |
269 } |
270 } |
270 } |
271 } |