src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java

changeset 60
29d2485c1085
parent 1
9a66ca7c79fa
child 168
4cdaaf4c5dca
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Fri Jun 20 11:25:03 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java	Wed Jun 25 14:24:53 2008 -0700
     1.3 @@ -101,13 +101,17 @@
     1.4       *                individual instances should be given, or whether an aggregate
     1.5       *                message should be generated at the end of the compilation.
     1.6       *                Typically set via  -Xlint:option.
     1.7 +     * @param enforceMandatory
     1.8 +     *                True if mandatory warnings and notes are being enforced.
     1.9       * @param prefix  A common prefix for the set of message keys for
    1.10       *                the messages that may be generated.
    1.11       */
    1.12 -    public MandatoryWarningHandler(Log log, boolean verbose, String prefix) {
    1.13 +    public MandatoryWarningHandler(Log log, boolean verbose,
    1.14 +                                   boolean enforceMandatory, String prefix) {
    1.15          this.log = log;
    1.16          this.verbose = verbose;
    1.17          this.prefix = prefix;
    1.18 +        this.enforceMandatory = enforceMandatory;
    1.19      }
    1.20  
    1.21      /**
    1.22 @@ -122,7 +126,7 @@
    1.23  
    1.24              if (log.nwarnings < log.MaxWarnings) {
    1.25                  // generate message and remember the source file
    1.26 -                log.mandatoryWarning(pos, msg, args);
    1.27 +                logMandatoryWarning(pos, msg, args);
    1.28                  sourcesWithReportedWarnings.add(currentSource);
    1.29              } else if (deferredDiagnosticKind == null) {
    1.30                  // set up deferred message
    1.31 @@ -163,12 +167,12 @@
    1.32      public void reportDeferredDiagnostic() {
    1.33          if (deferredDiagnosticKind != null) {
    1.34              if (deferredDiagnosticArg == null)
    1.35 -                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
    1.36 +                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
    1.37              else
    1.38 -                log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
    1.39 +                logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
    1.40  
    1.41              if (!verbose)
    1.42 -                log.mandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
    1.43 +                logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
    1.44          }
    1.45      }
    1.46  
    1.47 @@ -224,4 +228,32 @@
    1.48       * deferredDiagnosticKind is updated.
    1.49       */
    1.50      private Object deferredDiagnosticArg;
    1.51 +
    1.52 +    /**
    1.53 +     * True if mandatory warnings and notes are being enforced.
    1.54 +     */
    1.55 +    private final boolean enforceMandatory;
    1.56 +
    1.57 +    /**
    1.58 +     * Reports a mandatory warning to the log.  If mandatory warnings
    1.59 +     * are not being enforced, treat this as an ordinary warning.
    1.60 +     */
    1.61 +    private void logMandatoryWarning(DiagnosticPosition pos, String msg,
    1.62 +                                     Object... args) {
    1.63 +        if (enforceMandatory)
    1.64 +            log.mandatoryWarning(pos, msg, args);
    1.65 +        else
    1.66 +            log.warning(pos, msg, args);
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Reports a mandatory note to the log.  If mandatory notes are
    1.71 +     * not being enforced, treat this as an ordinary note.
    1.72 +     */
    1.73 +    private void logMandatoryNote(JavaFileObject file, String msg, Object... args) {
    1.74 +        if (enforceMandatory)
    1.75 +            log.mandatoryNote(file, msg, args);
    1.76 +        else
    1.77 +            log.note(file, msg, args);
    1.78 +    }
    1.79  }

mercurial