com.sun.tools.javac.util
Class Log

java.lang.Object
  extended by com.sun.tools.javac.util.AbstractLog
      extended by com.sun.tools.javac.util.Log
Direct Known Subclasses:
Bark, Messager

public class Log
extends AbstractLog

A class for error logs. Reports errors and warnings, and keeps track of error numbers and positions.

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.


Field Summary
private  DiagnosticFormatter<JCDiagnostic> diagFormatter
          Formatter for diagnostics
protected  DiagnosticListener<? super JavaFileObject> diagListener
          Diagnostic listener, if provided through programmatic interface to javac (JSR 199).
 boolean dumpOnError
          Print stack trace on errors?
 boolean emitWarnings
          Switch: emit warning messages.
 java.io.PrintWriter errWriter
           
 java.util.Set<java.lang.String> expectDiagKeys
          Keys for expected diagnostics
static Context.Key<Log> logKey
          The context key for the log.
 int MaxErrors
          The maximum number of errors/warnings that are reported.
 int MaxWarnings
           
private  JavacMessages messages
          JavacMessages object used for localization
 boolean multipleErrors
          Print multiple errors for same source locations.
 int nerrors
          The number of errors encountered so far.
 java.io.PrintWriter noticeWriter
           
 int nwarnings
          The number of warnings encountered so far.
static Context.Key<java.io.PrintWriter> outKey
          The context key for the output PrintWriter.
 boolean promptOnError
          Switch: prompt user on each error.
private  java.util.Set<Pair<JavaFileObject,java.lang.Integer>> recorded
          A set of all errors generated so far.
 java.io.PrintWriter warnWriter
           
 
Fields inherited from class com.sun.tools.javac.util.AbstractLog
diags, source, sourceMap
 
Constructor Summary
protected Log(Context context)
          Construct a log with default settings.
protected Log(Context context, java.io.PrintWriter defaultWriter)
          Construct a log with all output redirected.
protected Log(Context context, java.io.PrintWriter errWriter, java.io.PrintWriter warnWriter, java.io.PrintWriter noticeWriter)
          Deprecated. 
 
Method Summary
 JavaFileObject currentSourceFile()
          Return current sourcefile.
(package private) static java.io.PrintWriter defaultWriter(Context context)
          The default writer for diagnostics
protected  void directError(java.lang.String key, java.lang.Object... args)
           
 void flush()
          Flush the logs
static java.lang.String format(java.lang.String fmt, java.lang.Object... args)
           
private  int getIntOption(Options options, java.lang.String optionName, int defaultValue)
           
static java.lang.String getLocalizedString(java.lang.String key, java.lang.Object... args)
          Find a localized string in the resource bundle.
protected  java.io.PrintWriter getWriterForDiagnosticType(JCDiagnostic.DiagnosticType dt)
          Deprecated. 
 boolean hasDiagnosticListener()
           
static Log instance(Context context)
          Get the Log instance for this context.
private  void printErrLine(int pos, java.io.PrintWriter writer)
          Print the faulty source code line and point to the error.
static void printLines(java.io.PrintWriter writer, java.lang.String msg)
          Print the text of a message, translating newlines appropriately for the platform.
private  void printRawError(int pos, java.lang.String msg)
          print an error or warning message:
 void prompt()
          Prompt user after an error.
 void rawError(int pos, java.lang.String msg)
          report an error:
 void rawWarning(int pos, java.lang.String msg)
          report a warning:
 void report(JCDiagnostic diagnostic)
          Common diagnostic handling.
 void setEndPosTable(JavaFileObject name, java.util.Map<JCTree,java.lang.Integer> table)
           
protected  boolean shouldReport(JavaFileObject file, int pos)
          Returns true if an error needs to be reported for a given source name and pos.
 void strictWarning(JCDiagnostic.DiagnosticPosition pos, java.lang.String key, java.lang.Object... args)
          Report a warning that cannot be suppressed.
protected  void writeDiagnostic(JCDiagnostic diag)
          Write out a diagnostic.
 
Methods inherited from class com.sun.tools.javac.util.AbstractLog
currentSource, error, error, error, getSource, mandatoryNote, mandatoryWarning, note, note, note, note, useSource, warning, warning, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logKey

public static final Context.Key<Log> logKey
The context key for the log.


outKey

public static final Context.Key<java.io.PrintWriter> outKey
The context key for the output PrintWriter.


errWriter

public final java.io.PrintWriter errWriter

warnWriter

public final java.io.PrintWriter warnWriter

noticeWriter

public final java.io.PrintWriter noticeWriter

MaxErrors

public final int MaxErrors
The maximum number of errors/warnings that are reported.


MaxWarnings

public final int MaxWarnings

promptOnError

public boolean promptOnError
Switch: prompt user on each error.


emitWarnings

public boolean emitWarnings
Switch: emit warning messages.


dumpOnError

public boolean dumpOnError
Print stack trace on errors?


multipleErrors

public boolean multipleErrors
Print multiple errors for same source locations.


diagListener

protected DiagnosticListener<? super JavaFileObject> diagListener
Diagnostic listener, if provided through programmatic interface to javac (JSR 199).


diagFormatter

private DiagnosticFormatter<JCDiagnostic> diagFormatter
Formatter for diagnostics


expectDiagKeys

public java.util.Set<java.lang.String> expectDiagKeys
Keys for expected diagnostics


messages

private JavacMessages messages
JavacMessages object used for localization


nerrors

public int nerrors
The number of errors encountered so far.


nwarnings

public int nwarnings
The number of warnings encountered so far.


recorded

private java.util.Set<Pair<JavaFileObject,java.lang.Integer>> recorded
A set of all errors generated so far. This is used to avoid printing an error message more than once. For each error, a pair consisting of the source file name and source code position of the error is added to the set.

Constructor Detail

Log

@Deprecated
protected Log(Context context,
                         java.io.PrintWriter errWriter,
                         java.io.PrintWriter warnWriter,
                         java.io.PrintWriter noticeWriter)
Deprecated. 

Construct a log with given I/O redirections.


Log

protected Log(Context context)
Construct a log with default settings.


Log

protected Log(Context context,
              java.io.PrintWriter defaultWriter)
Construct a log with all output redirected.

Method Detail

getIntOption

private int getIntOption(Options options,
                         java.lang.String optionName,
                         int defaultValue)

defaultWriter

static final java.io.PrintWriter defaultWriter(Context context)
The default writer for diagnostics


instance

public static Log instance(Context context)
Get the Log instance for this context.


hasDiagnosticListener

public boolean hasDiagnosticListener()

setEndPosTable

public void setEndPosTable(JavaFileObject name,
                           java.util.Map<JCTree,java.lang.Integer> table)

currentSourceFile

public JavaFileObject currentSourceFile()
Return current sourcefile.


flush

public void flush()
Flush the logs


shouldReport

protected boolean shouldReport(JavaFileObject file,
                               int pos)
Returns true if an error needs to be reported for a given source name and pos.


prompt

public void prompt()
Prompt user after an error.


printErrLine

private void printErrLine(int pos,
                          java.io.PrintWriter writer)
Print the faulty source code line and point to the error.

Parameters:
pos - Buffer index of the error position, must be on current line

printLines

public static void printLines(java.io.PrintWriter writer,
                              java.lang.String msg)
Print the text of a message, translating newlines appropriately for the platform.


directError

protected void directError(java.lang.String key,
                           java.lang.Object... args)
Specified by:
directError in class AbstractLog

strictWarning

public void strictWarning(JCDiagnostic.DiagnosticPosition pos,
                          java.lang.String key,
                          java.lang.Object... args)
Report a warning that cannot be suppressed.

Parameters:
pos - The source position at which to report the warning.
key - The key for the localized warning message.
args - Fields of the warning message.

report

public void report(JCDiagnostic diagnostic)
Common diagnostic handling. The diagnostic is counted, and depending on the options and how many diagnostics have been reported so far, the diagnostic may be handed off to writeDiagnostic.

Specified by:
report in class AbstractLog

writeDiagnostic

protected void writeDiagnostic(JCDiagnostic diag)
Write out a diagnostic.


getWriterForDiagnosticType

@Deprecated
protected java.io.PrintWriter getWriterForDiagnosticType(JCDiagnostic.DiagnosticType dt)
Deprecated. 


getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.lang.Object... args)
Find a localized string in the resource bundle.

Parameters:
key - The key for the localized string.
args - Fields to substitute into the string.

printRawError

private void printRawError(int pos,
                           java.lang.String msg)
print an error or warning message:


rawError

public void rawError(int pos,
                     java.lang.String msg)
report an error:


rawWarning

public void rawWarning(int pos,
                       java.lang.String msg)
report a warning:


format

public static java.lang.String format(java.lang.String fmt,
                                      java.lang.Object... args)