Package gnu.text

Class SourceMessages

  • All Implemented Interfaces:
    SourceLocator, javax.xml.transform.SourceLocator, org.xml.sax.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      SourceMessages()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkErrors​(java.lang.Appendable 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, SourceLocator location, java.lang.String message)  
      void error​(char severity, SourceLocator location, java.lang.String message, java.lang.String code)  
      void error​(char severity, java.lang.String message)
      Record a new error at the current default source file location.
      void error​(char severity, java.lang.String filename, int line, int column, java.lang.String message)
      Record a new error.
      void error​(char severity, java.lang.String filename, int line, int column, java.lang.String message, java.lang.String code)  
      void error​(char severity, java.lang.String message, java.lang.String code)  
      void error​(char severity, java.lang.String message, java.lang.Throwable exception)  
      void error​(SourceError error)
      Link in an error.
      int getColumnNumber()
      The default column number to use for a new error.
      int getCount​(java.lang.String severities)
      Get number of diagnostics whose severity is one of the characters in the argument.
      int getEndColumn()
      Column (one-origin) of end of range; unknown/unspecified is -1.
      int getEndLine()
      Line number (one-origin) of end of range; unknown/unspecified is -1.
      int getErrorCount()
      Get the number of errors (not counting warnings).
      SourceError getErrors()  
      java.lang.String getFileName()
      The default filename to use for a new error.
      int getLineNumber()
      The default line number to use for a new error.
      java.lang.String getPublicId()  
      int getStartColumn()
      Column (one-origin) of start of range; unknown/unspecified is -1.
      int getStartLine()
      Line number (one-origin) of start of range; unknown/unspecified is -1.
      java.lang.String getSystemId()  
      boolean isStableSourceLocation()
      True if position is unlikely to change.
      void printAll​(java.lang.Appendable out, int max)
      Print all the error messages to an Appendable.
      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 setLocation​(SourceLocator locator)
      Copies the current position of locator.
      void setSourceLocator​(SourceLocator locator)
      Links our location to the one give.
      SourceLocator swapSourceLocator​(SourceLocator locator)  
      java.lang.String toString​(int max)
      Convert this to a String containing the recorded errors.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • SourceMessages

        public SourceMessages()
    • Method Detail

      • 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​(java.lang.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,
                          java.lang.String filename,
                          int line,
                          int column,
                          java.lang.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,
                          SourceLocator location,
                          java.lang.String message)
      • error

        public void error​(char severity,
                          java.lang.String filename,
                          int line,
                          int column,
                          java.lang.String message,
                          java.lang.String code)
      • error

        public void error​(char severity,
                          SourceLocator location,
                          java.lang.String message,
                          java.lang.String code)
      • error

        public void error​(char severity,
                          java.lang.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,
                          java.lang.String message,
                          java.lang.Throwable exception)
      • error

        public void error​(char severity,
                          java.lang.String message,
                          java.lang.String code)
      • printAll

        public void printAll​(java.lang.Appendable out,
                             int max)
        Print all the error messages to an Appendable.
      • toString

        public java.lang.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​(java.lang.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 to
        max - maximum number of messages to print (can be 0)
      • setSourceLocator

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

        public java.lang.String getPublicId()
        Specified by:
        getPublicId in interface org.xml.sax.Locator
        Specified by:
        getPublicId in interface SourceLocator
        Specified by:
        getPublicId in interface javax.xml.transform.SourceLocator
        Overrides:
        getPublicId in class SourceLocator.Simple
      • getSystemId

        public java.lang.String getSystemId()
        Specified by:
        getSystemId in interface org.xml.sax.Locator
        Specified by:
        getSystemId in interface SourceLocator
        Specified by:
        getSystemId in interface javax.xml.transform.SourceLocator
        Overrides:
        getSystemId in class SourceLocator.Simple
      • getLineNumber

        public final int getLineNumber()
        The default line number to use for a new error.
        Specified by:
        getLineNumber in interface org.xml.sax.Locator
        Specified by:
        getLineNumber in interface SourceLocator
        Specified by:
        getLineNumber in interface javax.xml.transform.SourceLocator
        Overrides:
        getLineNumber in class SourceLocator.Simple
      • getColumnNumber

        public final int getColumnNumber()
        The default column number to use for a new error.
        Specified by:
        getColumnNumber in interface org.xml.sax.Locator
        Specified by:
        getColumnNumber in interface SourceLocator
        Specified by:
        getColumnNumber in interface javax.xml.transform.SourceLocator
        Overrides:
        getColumnNumber in class SourceLocator.Simple
      • setColumn

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