ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.util
Class ErrorSet

java.lang.Object
  extended byjavafe.util.ErrorSet

public class ErrorSet
extends java.lang.Object

The ErrorSet class is responsible for displaying cautions, warnings, ordinary errors, and fatal errors to the user. It maintains counts of how many cautions, warnings, and errors have been reported so far.

Currently, reporting is done via printing all messages to System.out. Messages are accompanied by an indication of whether they are a caution, a warning, an ordinary error, or a fatal error.

Messages are printed as soon as they are reported. A future version of ErrorSet may group together messages concerning the same file to be printed in location sorted order once the file has been processed fully. (This will require adding some kind of end_of_file(F) call.)

Rough rules for determining what class to report something as:

Error:
something that is definitely wrong and which prevents processing everything the tool was requested to work on.
Fatal Error:
similar except that it prevents any further processing at all. (Tools may continue after ordinary errors by aborting processing of some, but not all, parts of the input program.)
Caution:
(1) something that is technically illegal according to the language spec(s), but the tool accepts anyways for compatibility with other tools. (It must not force aborting.)
(2) something that is not technically illegal, but is likely to be misleading. (The user is encouraged to adjust the environment or the code to remove the caution.)
Warning:
something that the Tool believes, but is not sure, is a serious problem - used for static checking reports.

See Also:
Location, FatalError

Nested Class Summary
static interface ErrorSet.Reporter
           
static class ErrorSet.StandardReporter
           
 
Field Summary
private static java.lang.String CAUTION
          * Common code for reporting: * *
static int cautions
          The number of cautions reported so far.
private static java.lang.String ERROR
           
static int errors
          The number of errors reported so far, including fatal errors.
private static java.lang.String FATALERROR
           
static int fatals
          The number of fatal errors so far (some may have been caught and handled)
static boolean gag
          If gag is true, then no output is produced by ErrorSet methods (useful for test harnesses).
private static ErrorSet.Reporter reporter
           
private static int savedCautions
           
private static int savedErrorsWarnings
           
private static int TABSTOP
           
private static java.lang.String WARNING
           
static int warnings
          The number of warnings reported so far.
 
Constructor Summary
private ErrorSet()
           
 
Method Summary
static void assocLoc(int loc)
           
static void caution(int loc, java.lang.String msg)
          Report a caution associated with a location.
static void caution(int loc, java.lang.String msg, int addLoc)
           
static void caution(java.lang.String msg)
          Report a caution.
static boolean cautionsSinceMark()
           
static void clear()
          Resets all error and warning counts.
static void displayColumn(int loc)
          See documentation for two-argument version of displayColumn.
static void displayColumn(int loc, ClipPolicy policy)
          Display (part of) the line that loc occurs on, then indicate via a caret (^) which column loc points to.
static void dump(java.lang.String s)
          Prints to System.out the given String (if not null) and a current stack trace, to be used for debugging with print statements.
static void error(int loc, java.lang.String msg)
          Report an ordinary error associated with a location.
static void error(int loc, java.lang.String msg, int addLoc)
           
static void error(java.lang.String msg)
          Report an ordinary error.
static boolean errorsSinceMark()
           
static void fatal(int loc, java.lang.String msg)
          Report a fatal error associated with a location.
static void fatal(java.lang.String msg)
          Report a fatal error.
private static java.io.InputStream getFile(int loc)
          Return a new InputStream for the file that loc refers to or null if an I/O error occurs while attempting to open the stream.
private static java.lang.String getLine(int loc)
          Return the line loc refers to or null if an I/O error occurs while attempting to read the line in.
static ErrorSet.Reporter getReporter()
          Returns the current output reporter.
static void mark()
           
static void notImplemented(boolean print, int loc, java.lang.String msg)
          Special call to report unimplemented features, so they can be caught and handled more easily.
private static void report(int loc, java.lang.String type, java.lang.String msg)
          Report information associated with a location.
static void report(java.lang.String msg)
          Reports a general message, implemented here in order to have a single location through which error reporting happens.
private static void report(java.lang.String type, java.lang.String msg)
          Report general information.
static ErrorSet.Reporter setReporter(ErrorSet.Reporter r)
          Sets the reporter to be used to convey information to the user; returns the previous value of the reporter.
static void warning(int loc, java.lang.String msg)
          Report a warning associated with a location.
static void warning(java.lang.String msg)
          Report a warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cautions

public static int cautions
The number of cautions reported so far.


warnings

public static int warnings
The number of warnings reported so far.


errors

public static int errors
The number of errors reported so far, including fatal errors.


fatals

public static int fatals
The number of fatal errors so far (some may have been caught and handled)


gag

public static boolean gag
If gag is true, then no output is produced by ErrorSet methods (useful for test harnesses). Defaults to false.


savedErrorsWarnings

private static int savedErrorsWarnings

savedCautions

private static int savedCautions

CAUTION

private static final java.lang.String CAUTION
* Common code for reporting: * *

See Also:
Constant Field Values

WARNING

private static final java.lang.String WARNING
See Also:
Constant Field Values

ERROR

private static final java.lang.String ERROR
See Also:
Constant Field Values

FATALERROR

private static final java.lang.String FATALERROR
See Also:
Constant Field Values

TABSTOP

private static final int TABSTOP
See Also:
Constant Field Values

reporter

private static ErrorSet.Reporter reporter
Constructor Detail

ErrorSet

private ErrorSet()
Method Detail

clear

public static void clear()
Resets all error and warning counts.


mark

public static void mark()

errorsSinceMark

public static boolean errorsSinceMark()

cautionsSinceMark

public static boolean cautionsSinceMark()

caution

public static void caution(java.lang.String msg)
Report a caution.

The message will be marked as a caution when it is displayed to the user. Increments cautions by one.


caution

public static void caution(int loc,
                           java.lang.String msg)
Report a caution associated with a location.

Precondition: loc must be a regular location or a whole file location.

The message will be marked as a caution when it is displayed to the user. Increments cautions by one.


caution

public static void caution(int loc,
                           java.lang.String msg,
                           int addLoc)

warning

public static void warning(java.lang.String msg)
Report a warning.

The message will be marked as a warning when it is displayed to the user. Increments warnings by one.


warning

public static void warning(int loc,
                           java.lang.String msg)
Report a warning associated with a location.

Precondition: loc must be a regular location or a whole file location.

The message will be marked as a warning when it is displayed to the user. Increments warnings by one.


error

public static void error(java.lang.String msg)
Report an ordinary error.

The message will be marked as an error when it is displayed to the user. Increments errors by one.


error

public static void error(int loc,
                         java.lang.String msg)
Report an ordinary error associated with a location.

Precondition: loc must be a regular location or a whole file location.

The message will be marked as an error when it is displayed to the user. Increments errors by one.


error

public static void error(int loc,
                         java.lang.String msg,
                         int addLoc)

assocLoc

public static void assocLoc(int loc)

fatal

public static void fatal(java.lang.String msg)
Report a fatal error. Warning: This method does not return normally!

The variable errors is incremented by one, the error reported as a fatal error, and then an unchecked FatalError exception is thrown. The top level of a Tool is responsible for catching the FatalError, so that it can do whatever cleanup is required before exiting.


fatal

public static void fatal(int loc,
                         java.lang.String msg)
Report a fatal error associated with a location. Warning: This method does not return normally!

Precondition: loc must be a regular location or a whole file location.

The variable errors is incremented by one, the error reported as a fatal error, and then an unchecked FatalError exception is thrown. The top level of a Tool is responsible for catching the FatalError, so that it can do whatever cleanup is required before exiting.


notImplemented

public static void notImplemented(boolean print,
                                  int loc,
                                  java.lang.String msg)
Special call to report unimplemented features, so they can be caught and handled more easily.


report

private static void report(java.lang.String type,
                           java.lang.String msg)
Report general information.

Type contains a non-null String describing the type of the information (usually one of the above constants). The information itself is contained in the non-null String msg.

This function is not responsible for incrementing counts or other ErrorSet functionality.


report

public static void report(java.lang.String msg)
Reports a general message, implemented here in order to have a single location through which error reporting happens.


report

private static void report(int loc,
                           java.lang.String type,
                           java.lang.String msg)
Report information associated with a location.

Type contains a non-null String describing the type of the information (usually one of the above constants). The information itself is contained in the non-null String msg.

Precondition: loc must be a regular location or a whole file location.

This function is not responsible for incrementing counts or other ErrorSet functionality.


getFile

private static java.io.InputStream getFile(int loc)
Return a new InputStream for the file that loc refers to or null if an I/O error occurs while attempting to open the stream.

Precondition: loc must be a regular location or a whole file location.

No error is reported if an I/O error occurs.


getLine

private static java.lang.String getLine(int loc)
Return the line loc refers to or null if an I/O error occurs while attempting to read the line in.

Precondition: loc is a regular location (e.g., not a whole-file location).

No error is reported if an I/O error occurs.


displayColumn

public static void displayColumn(int loc)
See documentation for two-argument version of displayColumn. This version differs in that the default clip policy is applied.


displayColumn

public static void displayColumn(int loc,
                                 ClipPolicy policy)
Display (part of) the line that loc occurs on, then indicate via a caret (^) which column loc points to.

Tabs are expanded before the line is displayed using 8-character tab stops. 8 spaces is perhaps not what the user intended, but there will not be any other lines portrayed against which it must match, and the caret positioning will be consistent with the 8 character spacing; at worst, the line will be spread out more than it would be with shorter tabs.

Precondition: loc is a regular location (e.g., not a whole-file location).

If an I/O error does occur, then the user is informed of the column number and that the line in question is not available; no error is reported. By using a non-null policy argument, a caller can fine- tune the policy used for introducing ellipses in the printed line.


dump

public static void dump(java.lang.String s)
Prints to System.out the given String (if not null) and a current stack trace, to be used for debugging with print statements.


getReporter

public static ErrorSet.Reporter getReporter()
Returns the current output reporter.

Returns:
the current reporter

setReporter

public static ErrorSet.Reporter setReporter(ErrorSet.Reporter r)
Sets the reporter to be used to convey information to the user; returns the previous value of the reporter.

Parameters:
r - The new value of the single reporter object.
Returns:
The previous value of the reporter object.

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage