gnu.text

Class SourceMessages

Implemented Interfaces:
org.xml.sax.Locator, SourceLocator

public class SourceMessages
extends java.lang.Object
implements SourceLocator

A collection of (zero or more) SourceErrors. Has a "current line number" which clients can use as the default line number, or clients can explicitly provide a line number. Does not handle localization of messages.

Field Summary

static boolean
debugStackTraceOnError
If true, print out stack trace with any error.
static boolean
debugStackTraceOnWarning
If true, print out stack trace with any warning.
boolean
sortMessages
True if we should sort messages by line number.

Method Summary

boolean
checkErrors(java.io.PrintStream out, int max)
Checks if an error was seen; if so, prints and clears the messages.
boolean
checkErrors(java.io.PrintWriter out, int max)
Checks if an error was seen; if so, prints and clears the messages.
void
clear()
Clear the contained errors and warnings.
void
clearErrors()
Clear the error count (only).
void
error(char severity, String message)
Record a new error at the current default source file location.
void
error(char severity, String message, String code)
void
error(char severity, String filename, int line, int column, String message)
Record a new error.
void
error(char severity, String filename, int line, int column, String message, String code)
void
error(char severity, SourceLocator location, String message)
void
error(char severity, SourceLocator location, String message, String code)
void
error(SourceError error)
Link in an error.
int
getColumnNumber()
The default column number to use for a new error.
int
getErrorCount()
Get the number of errors (not counting warnings).
SourceError
getErrors()
String
getFileName()
The default filename to use for a new error.
int
getLineNumber()
The default line number to use for a new error.
String
getPublicId()
String
getSystemId()
boolean
isStableSourceLocation()
void
printAll(java.io.PrintStream out, int max)
Print all the error messages to a PrintStream.
void
printAll(java.io.PrintWriter out, int max)
Print all the error messages to a PrintWriter.
boolean
seenErrors()
Return true iff errors (not warnings) have been seen.
boolean
seenErrorsOrWarnings()
void
setColumn(int column)
Set the default column number to use for a new error.
void
setFile(String filename)
Set the default filename to use for a new error.
void
setLine(String filename, int line, int column)
Set the default filename, line and column to use for a new error.
void
setLine(int line)
Set the default line number to use for a new error.
void
setLocation(SourceLocator locator)
Copies the current position of locator.
void
setSourceLocator(SourceLocator locator)
Links our location to the one give.
String
toString(int max)
Convert this to a String containing the recorded errors.

Field Details

debugStackTraceOnError

public static boolean debugStackTraceOnError
If true, print out stack trace with any error.

debugStackTraceOnWarning

public static boolean debugStackTraceOnWarning
If true, print out stack trace with any warning.

sortMessages

public boolean sortMessages
True if we should sort messages by line number.

Method Details

checkErrors

public boolean checkErrors(java.io.PrintStream out,
                           int max)
Checks if an error was seen; if so, prints and clears the messages.
Parameters:
out - where to write the error message to
max - maximum number of messages to print (can be 0)

checkErrors

public boolean checkErrors(java.io.PrintWriter out,
                           int max)
Checks if an error was seen; if so, prints and clears the messages.
Parameters:
out - where to write the error message to
max - maximum number of messages to print (can be 0)

clear

public void clear()
Clear the contained errors and warnings.

clearErrors

public void clearErrors()
Clear the error count (only).

error

public void error(char severity,
                  String message)
Record a new error at the current default source file location.
Parameters:
severity - is the seriousness of the error - one of 'w' (for warning), 'e' (for error), or 'f' (for fatal error)
message - the error message

error

public void error(char severity,
                  String message,
                  String code)

error

public void error(char severity,
                  String filename,
                  int line,
                  int column,
                  String message)
Record a new error.
Parameters:
severity - is the seriousness of the error - one of 'w' (for warning), 'e' (for error), or 'f' (for fatal error)
filename - the name or URL of the file containing the error
line - the (1-origin) line number or 0 if unknown
column - the (1-origin) column number or 0 if unknown
message - the error message

error

public void error(char severity,
                  String filename,
                  int line,
                  int column,
                  String message,
                  String code)

error

public void error(char severity,
                  SourceLocator location,
                  String message)

error

public void error(char severity,
                  SourceLocator location,
                  String message,
                  String code)

error

public void error(SourceError error)
Link in an error.

getColumnNumber

public final int getColumnNumber()
The default column number to use for a new error.
Specified by:
getColumnNumber in interface SourceLocator

getErrorCount

public int getErrorCount()
Get the number of errors (not counting warnings).

getErrors

public SourceError getErrors()

getFileName

public final String getFileName()
The default filename to use for a new error.
Specified by:
getFileName in interface SourceLocator

getLineNumber

public final int getLineNumber()
The default line number to use for a new error.
Specified by:
getLineNumber in interface SourceLocator

getPublicId

public String getPublicId()
Specified by:
getPublicId in interface SourceLocator

getSystemId

public String getSystemId()
Specified by:
getSystemId in interface SourceLocator

isStableSourceLocation

public boolean isStableSourceLocation()
Specified by:
isStableSourceLocation in interface SourceLocator

printAll

public void printAll(java.io.PrintStream out,
                     int max)
Print all the error messages to a PrintStream.

printAll

public void printAll(java.io.PrintWriter out,
                     int max)
Print all the error messages to a PrintWriter.

seenErrors

public boolean seenErrors()
Return true iff errors (not warnings) have been seen.

seenErrorsOrWarnings

public boolean seenErrorsOrWarnings()

setColumn

public void setColumn(int column)
Set the default column number to use for a new error.

setFile

public void setFile(String filename)
Set the default filename to use for a new error.

setLine

public void setLine(String filename,
                    int line,
                    int column)
Set the default filename, line and column to use for a new error.

setLine

public void setLine(int line)
Set the default line number to use for a new error.

setLocation

public final void setLocation(SourceLocator locator)
Copies the current position of locator.

setSourceLocator

public final void setSourceLocator(SourceLocator locator)
Links our location to the one give.

toString

public String toString(int max)
Convert this to a String containing the recorded errors.
Parameters:
max - the maximum number of error error to list
Returns:
a String with one '\n'-terminated line per recorded error