com.sun.tools.javac.util
Class MandatoryWarningHandler

java.lang.Object
  extended by com.sun.tools.javac.util.MandatoryWarningHandler

public class MandatoryWarningHandler
extends java.lang.Object

A handler to process mandatory warnings, setting up a deferred diagnostic to be printed at the end of the compilation if some warnings get suppressed because too many warnings have already been generated. Note that the SuppressWarnings annotation can be used to suppress warnings about conditions that would otherwise merit a warning. Such processing is done when the condition is detected, and in those cases, no call is made on any API to generate a warning at all. In consequence, this handler only gets to handle those warnings that JLS says must be generated.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
private static class MandatoryWarningHandler.DeferredDiagnosticKind
          The kinds of different deferred diagnostics that might be generated if a mandatory warning is suppressed because too many warnings have already been output.
 
Field Summary
private  java.lang.Object deferredDiagnosticArg
          An optional argument to be used when constructing the deferred diagnostic message, based on deferredDiagnosticKind.
private  MandatoryWarningHandler.DeferredDiagnosticKind deferredDiagnosticKind
          A variable indicating the latest best guess at what the final deferred diagnostic will be.
private  JavaFileObject deferredDiagnosticSource
          If deferredDiagnosticKind is IN_FILE or ADDITIONAL_IN_FILE, this variable gives the value of log.currentSource() for the file in question.
private  boolean enforceMandatory
          True if mandatory warnings and notes are being enforced.
private  Log log
          The log to which to report warnings.
private  java.lang.String prefix
          The common prefix for all I18N message keys generated by this handler.
private  java.util.Set<JavaFileObject> sourcesWithReportedWarnings
          A set containing the names of the source files for which specific warnings have been generated -- i.e.
private  boolean verbose
          Whether or not to report individual warnings, or simply to report a single aggregate warning at the end of the compilation.
 
Constructor Summary
MandatoryWarningHandler(Log log, boolean verbose, boolean enforceMandatory, java.lang.String prefix)
          Create a handler for mandatory warnings.
 
Method Summary
private static boolean equal(java.lang.Object o1, java.lang.Object o2)
          Check two objects, each possibly null, are either both null or are equal.
private  void logMandatoryNote(JavaFileObject file, java.lang.String msg, java.lang.Object... args)
          Reports a mandatory note to the log.
private  void logMandatoryWarning(JCDiagnostic.DiagnosticPosition pos, java.lang.String msg, java.lang.Object... args)
          Reports a mandatory warning to the log.
 void report(JCDiagnostic.DiagnosticPosition pos, java.lang.String msg, java.lang.Object... args)
          Report a mandatory warning.
 void reportDeferredDiagnostic()
          Report any diagnostic that might have been deferred by previous calls of report().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Log log
The log to which to report warnings.


verbose

private boolean verbose
Whether or not to report individual warnings, or simply to report a single aggregate warning at the end of the compilation.


prefix

private java.lang.String prefix
The common prefix for all I18N message keys generated by this handler.


sourcesWithReportedWarnings

private java.util.Set<JavaFileObject> sourcesWithReportedWarnings
A set containing the names of the source files for which specific warnings have been generated -- i.e. in verbose mode. If a source name appears in this list, then deferred diagnostics will be phrased to include "additionally"...


deferredDiagnosticKind

private MandatoryWarningHandler.DeferredDiagnosticKind deferredDiagnosticKind
A variable indicating the latest best guess at what the final deferred diagnostic will be. Initially as specific and helpful as possible, as more warnings are reported, the scope of the diagnostic will be broadened.


deferredDiagnosticSource

private JavaFileObject deferredDiagnosticSource
If deferredDiagnosticKind is IN_FILE or ADDITIONAL_IN_FILE, this variable gives the value of log.currentSource() for the file in question.


deferredDiagnosticArg

private java.lang.Object deferredDiagnosticArg
An optional argument to be used when constructing the deferred diagnostic message, based on deferredDiagnosticKind. This variable should normally be set/updated whenever deferredDiagnosticKind is updated.


enforceMandatory

private final boolean enforceMandatory
True if mandatory warnings and notes are being enforced.

Constructor Detail

MandatoryWarningHandler

public MandatoryWarningHandler(Log log,
                               boolean verbose,
                               boolean enforceMandatory,
                               java.lang.String prefix)
Create a handler for mandatory warnings.

Parameters:
log - The log on which to generate any diagnostics
verbose - Specify whether or not detailed messages about individual instances should be given, or whether an aggregate message should be generated at the end of the compilation. Typically set via -Xlint:option.
enforceMandatory - True if mandatory warnings and notes are being enforced.
prefix - A common prefix for the set of message keys for the messages that may be generated.
Method Detail

report

public void report(JCDiagnostic.DiagnosticPosition pos,
                   java.lang.String msg,
                   java.lang.Object... args)
Report a mandatory warning.


reportDeferredDiagnostic

public void reportDeferredDiagnostic()
Report any diagnostic that might have been deferred by previous calls of report().


equal

private static boolean equal(java.lang.Object o1,
                             java.lang.Object o2)
Check two objects, each possibly null, are either both null or are equal.


logMandatoryWarning

private void logMandatoryWarning(JCDiagnostic.DiagnosticPosition pos,
                                 java.lang.String msg,
                                 java.lang.Object... args)
Reports a mandatory warning to the log. If mandatory warnings are not being enforced, treat this as an ordinary warning.


logMandatoryNote

private void logMandatoryNote(JavaFileObject file,
                              java.lang.String msg,
                              java.lang.Object... args)
Reports a mandatory note to the log. If mandatory notes are not being enforced, treat this as an ordinary note.