ErrorCollector (Groovy 5.0.0)

Package: org.codehaus.groovy.control

## [Java] Class ErrorCollector

- org.codehaus.groovy.control.ErrorCollector

- All Implemented Interfaces and Traits:
    Serializable

      public class ErrorCollector
      extends Object
      implements Serializable

  A base class for collecting messages and errors during processing. Each CompilationUnit should have an ErrorCollector, and the SourceUnits should share their ErrorCollector with the CompilationUnit.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected CompilerConfiguration` | `configuration` | Configuration and other settings that control processing
    `protected LinkedList<Message>` | `errors` | ErrorMessages collected during processing
    `protected LinkedList<WarningMessage>` | `warnings` | WarningMessages collected during processing

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ErrorCollector(CompilerConfiguration configuration)` Initialize the ErrorReporter.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addCollectorContents(ErrorCollector that)`
    `` | `public void` | `addError(Message message)` Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.
    `` | `public void` | `addError(Message message, boolean fatal)` Adds an optionally-fatal error to the message set.
    `` | `public void` | `addError(SyntaxException error, SourceUnit source)`
    `` | `public void` | `addError(String error, CSTNode context, SourceUnit source)`
    `` | `public void` | `addErrorAndContinue(String error, ASTNode node, SourceUnit source)`
    `` | `public void` | `addErrorAndContinue(SyntaxException error, SourceUnit source)`
    `` | `public void` | `addErrorAndContinue(Message message)` Adds an error to the message set, but does not cause a failure.
    `` | `public void` | `addException(Exception exception, SourceUnit source)`
    `` | `public void` | `addFatalError(Message message)` Adds an error to the message set and throws CompilationFailedException.
    `` | `public void` | `addWarning(WarningMessage message)` Adds a warning to the message set.
    `` | `public void` | `addWarning(int importance, String text, CSTNode context, SourceUnit source)` Adds a warning to the message set if it is relevant.
    `` | `public void` | `addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source)` Adds a warning to the message set if it is relevant.
    `` | `protected void` | `failIfErrors()` Causes the current phase to fail by throwing a CompilationFailedException.
    `` | `public CompilerConfiguration` | `getConfiguration()` Returns: the compiler configuration used to create this error collector
    `` | `public Message` | `getError(int index)` Returns the specified error message, or null.
    `` | `public int` | `getErrorCount()` Returns the number of errors.
    `` | `public List<? extends Message>` | `getErrors()` Returns the list of errors, or null if there are none.
    `` | `public Exception` | `getException(int index)` Returns the specified error's underlying Exception, or null if it isn't one.
    `` | `public Message` | `getLastError()` Returns the last error reported.
    `` | `public SyntaxException` | `getSyntaxError(int index)` Returns the specified error's underlying SyntaxException, or null if it isn't one.
    `` | `public WarningMessage` | `getWarning(int index)` Returns the specified warning message, or null.
    `` | `public int` | `getWarningCount()` Returns the number of warnings.
    `` | `public List<WarningMessage>` | `getWarnings()` Returns the list of warnings, or null if there are none.
    `` | `public boolean` | `hasErrors()` Returns true if there are any errors pending.
    `` | `public boolean` | `hasWarnings()` Returns true if there are any warnings pending.
    `` | `public void` | `write(PrintWriter writer, Janitor janitor)` Writes error messages to the specified PrintWriter.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### protected final CompilerConfiguration configuration

      Configuration and other settings that control processing

    - #### protected LinkedList<Message> errors

      ErrorMessages collected during processing

    - #### protected LinkedList<WarningMessage> warnings

      WarningMessages collected during processing

  - ### Constructor Detail

    - #### public ErrorCollector(CompilerConfiguration configuration)

      Initialize the ErrorReporter.

  - ### Method Detail

    - #### public void addCollectorContents(ErrorCollector that)

    - #### public void addError(Message message)

      Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded. The message is not required to have a source line and column specified, but it is best practice to try and include that information.

    - #### public void addError(Message message, boolean fatal)

      Adds an optionally-fatal error to the message set. The message is not required to have a source line and column specified, but it is best practice to try and include that information.

      Parameters:
        `fatal` - if true then processing will stop

    - #### public void addError(SyntaxException error, SourceUnit source)

    - #### public void addError(String error, CSTNode context, SourceUnit source)

    - #### public void addErrorAndContinue(String error, ASTNode node, SourceUnit source)

    - #### public void addErrorAndContinue(SyntaxException error, SourceUnit source)

    - #### public void addErrorAndContinue(Message message)

      Adds an error to the message set, but does not cause a failure. The message is not required to have a source line and column specified, but it is best practice to try and include that information.

    - #### public void addException(Exception exception, SourceUnit source)

    - #### public void addFatalError(Message message)

      Adds an error to the message set and throws CompilationFailedException.

    - #### public void addWarning(WarningMessage message)

      Adds a warning to the message set.

    - #### public void addWarning(int importance, String text, CSTNode context, SourceUnit source)

      Adds a warning to the message set if it is relevant.

    - #### public void addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source)

      Adds a warning to the message set if it is relevant.

    - #### protected void failIfErrors()

      Causes the current phase to fail by throwing a CompilationFailedException.

    - #### public CompilerConfiguration getConfiguration()

      Returns:
        the compiler configuration used to create this error collector

    - #### public Message getError(int index)

      Returns the specified error message, or null.

    - #### public int getErrorCount()

      Returns the number of errors.

    - #### public List<? extends Message> getErrors()

      Returns the list of errors, or null if there are none.

    - #### public Exception getException(int index)

      Returns the specified error's underlying Exception, or null if it isn't one.

    - #### public Message getLastError()

      Returns the last error reported.

    - #### public SyntaxException getSyntaxError(int index)

      Returns the specified error's underlying SyntaxException, or null if it isn't one.

    - #### public WarningMessage getWarning(int index)

      Returns the specified warning message, or null.

    - #### public int getWarningCount()

      Returns the number of warnings.

    - #### public List<WarningMessage> getWarnings()

      Returns the list of warnings, or null if there are none.

    - #### public boolean hasErrors()

      Returns true if there are any errors pending.

    - #### public boolean hasWarnings()

      Returns true if there are any warnings pending.

    - #### public void write(PrintWriter writer, Janitor janitor)

      Writes error messages to the specified PrintWriter.