Package gnu.text
Class SourceMessages
- java.lang.Object
-
- gnu.text.SourceLocator.Simple
-
- gnu.text.SourceMessages
-
- All Implemented Interfaces:
SourceLocator,SourceLocator,Locator
public class SourceMessages extends SourceLocator.Simple
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. Similar functionality as JAVA6's javax.tools.DiagnosticCollector.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple
-
-
Field Summary
Fields Modifier and Type Field Description static booleandebugStackTraceOnErrorIf true, print out stack trace with any error.static booleandebugStackTraceOnWarningIf true, print out stack trace with any warning.booleansortMessagesTrue if we should sort messages by line number.booleanstripDirectoriesstatic booleanstripDirectoriesDefault-
Fields inherited from class gnu.text.SourceLocator.Simple
filename, position
-
-
Constructor Summary
Constructors Constructor Description SourceMessages()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckErrors(Appendable out, int max)Checks if an error was seen; if so, prints and clears the messages.voidclear()Clear the contained errors and warnings.voidclearErrors()Clear the error count (only).voiderror(char severity, SourceLocator location, String message)voiderror(char severity, SourceLocator location, String message, String code)voiderror(char severity, String message)Record a new error at the current default source file location.voiderror(char severity, String filename, int line, int column, String message)Record a new error.voiderror(char severity, String filename, int line, int column, String message, String code)voiderror(char severity, String message, String code)voiderror(char severity, String message, Throwable exception)voiderror(SourceError error)Link in an error.intgetColumnNumber()The default column number to use for a new error.intgetCount(String severities)Get number of diagnostics whose severity is one of the characters in the argument.intgetEndColumn()Column (one-origin) of end of range; unknown/unspecified is -1.intgetEndLine()Line number (one-origin) of end of range; unknown/unspecified is -1.intgetErrorCount()Get the number of errors (not counting warnings).SourceErrorgetErrors()StringgetFileName()The default filename to use for a new error.intgetLineNumber()The default line number to use for a new error.StringgetPublicId()intgetStartColumn()Column (one-origin) of start of range; unknown/unspecified is -1.intgetStartLine()Line number (one-origin) of start of range; unknown/unspecified is -1.StringgetSystemId()booleanisStableSourceLocation()True if position is unlikely to change.voidprintAll(Appendable out, int max)Print all the error messages to an Appendable.booleanseenErrors()Return true iff errors (not warnings) have been seen.booleanseenErrorsOrWarnings()voidsetColumn(int column)Set the default column number to use for a new error.voidsetLocation(SourceLocator locator)Copies the current position of locator.voidsetSourceLocator(SourceLocator locator)Links our location to the one give.SourceLocatorswapSourceLocator(SourceLocator locator)StringtoString(int max)Convert this to a String containing the recorded errors.
-
-
-
Field Detail
-
stripDirectoriesDefault
public static boolean stripDirectoriesDefault
-
stripDirectories
public boolean stripDirectories
-
debugStackTraceOnWarning
public static boolean debugStackTraceOnWarning
If true, print out stack trace with any warning.
-
debugStackTraceOnError
public static boolean debugStackTraceOnError
If true, print out stack trace with any error.
-
sortMessages
public boolean sortMessages
True if we should sort messages by line number.
-
-
Method Detail
-
getErrors
public SourceError getErrors()
-
seenErrors
public boolean seenErrors()
Return true iff errors (not warnings) have been seen.
-
seenErrorsOrWarnings
public boolean seenErrorsOrWarnings()
-
getErrorCount
public int getErrorCount()
Get the number of errors (not counting warnings).
-
getCount
public int getCount(String severities)
Get number of diagnostics whose severity is one of the characters in the argument.
-
clearErrors
public void clearErrors()
Clear the error count (only).
-
clear
public void clear()
Clear the contained errors and warnings.
-
error
public void error(SourceError error)
Link in an error.
-
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 errorline- the (1-origin) line number or 0 if unknowncolumn- the (1-origin) column number or 0 if unknownmessage- the error message
-
error
public void error(char severity, SourceLocator location, String 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, String code)
-
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
-
printAll
public void printAll(Appendable out, int max)
Print all the error messages to an Appendable.
-
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
-
checkErrors
public boolean checkErrors(Appendable out, int max)
Checks if an error was seen; if so, prints and clears the messages.- Parameters:
out- where to write the error message tomax- maximum number of messages to print (can be 0)
-
setSourceLocator
public final void setSourceLocator(SourceLocator locator)
Links our location to the one give.
-
swapSourceLocator
public final SourceLocator swapSourceLocator(SourceLocator locator)
-
setLocation
public final void setLocation(SourceLocator locator)
Copies the current position of locator.- Overrides:
setLocationin classSourceLocator.Simple
-
getPublicId
public String getPublicId()
- Specified by:
getPublicIdin interfaceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Overrides:
getPublicIdin classSourceLocator.Simple
-
getSystemId
public String getSystemId()
- Specified by:
getSystemIdin interfaceLocator- Specified by:
getSystemIdin interfaceSourceLocator- Specified by:
getSystemIdin interfaceSourceLocator- Overrides:
getSystemIdin classSourceLocator.Simple
-
isStableSourceLocation
public boolean isStableSourceLocation()
Description copied from interface:SourceLocatorTrue if position is unlikely to change. True for an expression but not an input file.- Specified by:
isStableSourceLocationin interfaceSourceLocator- Overrides:
isStableSourceLocationin classSourceLocator.Simple
-
getFileName
public final String getFileName()
The default filename to use for a new error.- Specified by:
getFileNamein interfaceSourceLocator- Overrides:
getFileNamein classSourceLocator.Simple
-
getLineNumber
public final int getLineNumber()
The default line number to use for a new error.- Specified by:
getLineNumberin interfaceLocator- Specified by:
getLineNumberin interfaceSourceLocator- Specified by:
getLineNumberin interfaceSourceLocator- Overrides:
getLineNumberin classSourceLocator.Simple
-
getColumnNumber
public final int getColumnNumber()
The default column number to use for a new error.- Specified by:
getColumnNumberin interfaceLocator- Specified by:
getColumnNumberin interfaceSourceLocator- Specified by:
getColumnNumberin interfaceSourceLocator- Overrides:
getColumnNumberin classSourceLocator.Simple
-
getStartLine
public int getStartLine()
Description copied from interface:SourceLocatorLine number (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartLinein interfaceSourceLocator- Overrides:
getStartLinein classSourceLocator.Simple
-
getStartColumn
public int getStartColumn()
Description copied from interface:SourceLocatorColumn (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartColumnin interfaceSourceLocator- Overrides:
getStartColumnin classSourceLocator.Simple
-
getEndLine
public int getEndLine()
Description copied from interface:SourceLocatorLine number (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndLinein interfaceSourceLocator- Overrides:
getEndLinein classSourceLocator.Simple
-
getEndColumn
public int getEndColumn()
Description copied from interface:SourceLocatorColumn (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndColumnin interfaceSourceLocator- Overrides:
getEndColumnin classSourceLocator.Simple
-
setColumn
public void setColumn(int column)
Set the default column number to use for a new error.
-
-