Package org.codehaus.groovy.control

# Class ErrorCollector

java.lang.Object
org.codehaus.groovy.control.ErrorCollector

All Implemented Interfaces:
  `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.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `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 Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCollectorContents(ErrorCollector that)`
  Merges the recorded warnings and errors from another collector into this one.
  `void`
  `addError(String error, CSTNode context, SourceUnit source)`
  Adds a source-located error message.
  `void`
  `addError(Message message)`
  Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.
  `void`
  `addError(Message message, boolean fatal)`
  Adds an optionally-fatal error to the message set.
  `void`
  `addError(SyntaxException error, SourceUnit source)`
  Adds a syntax error and fails if it is marked fatal or exceeds tolerance.
  `void`
  `addErrorAndContinue(String error, ASTNode node, SourceUnit source)`
  Adds a syntax error for the supplied AST node without failing immediately.
  `void`
  `addErrorAndContinue(Message message)`
  Adds an error to the message set, but does not cause a failure.
  `void`
  `addErrorAndContinue(SyntaxException error, SourceUnit source)`
  Adds a syntax error without failing immediately.
  `void`
  `addException(Exception exception, SourceUnit source)`
  Adds an exception-based error for the supplied source unit and then fails.
  `void`
  `addFatalError(Message message)`
  Adds an error to the message set and throws CompilationFailedException.
  `void`
  `addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source)`
  Adds a warning to the message set if it is relevant.
  `void`
  `addWarning(int importance, String text, CSTNode context, SourceUnit source)`
  Adds a warning to the message set if it is relevant.
  `void`
  `addWarning(WarningMessage message)`
  Adds a warning to the message set.
  `protected void`
  `failIfErrors()`
  Causes the current phase to fail by throwing a CompilationFailedException.
  `CompilerConfiguration`
  `getConfiguration()`
  `Message`
  `getError(int index)`
  Returns the specified error message, or null.
  `int`
  `getErrorCount()`
  Returns the number of errors.
  `List<? extends Message>`
  `getErrors()`
  Returns the list of errors, or null if there are none.
  `Exception`
  `getException(int index)`
  Returns the specified error's underlying Exception, or null if it isn't one.
  `Message`
  `getLastError()`
  Returns the last error reported.
  `SyntaxException`
  `getSyntaxError(int index)`
  Returns the specified error's underlying SyntaxException, or null if it isn't one.
  `WarningMessage`
  `getWarning(int index)`
  Returns the specified warning message, or null.
  `int`
  `getWarningCount()`
  Returns the number of warnings.
  `List<WarningMessage>`
  `getWarnings()`
  Returns the list of warnings, or null if there are none.
  `boolean`
  `hasErrors()`
  Returns true if there are any errors pending.
  `boolean`
  `hasWarnings()`
  Returns true if there are any warnings pending.
  `void`
  `write(PrintWriter writer, Janitor janitor)`
  Writes error messages to the specified PrintWriter.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### errors

    protected LinkedList<Message> errors
    ErrorMessages collected during processing

  - ### warnings

    protected LinkedList<WarningMessage> warnings
    WarningMessages collected during processing

  - ### configuration

    protected final CompilerConfiguration configuration
    Configuration and other settings that control processing

- ## Constructor Details

  - ### ErrorCollector

    public ErrorCollector(CompilerConfiguration configuration)
    Initialize the ErrorReporter.

- ## Method Details

  - ### addCollectorContents

    public void addCollectorContents(ErrorCollector that)
    Merges the recorded warnings and errors from another collector into this one.
    Parameters:
      `that` - the collector whose contents should be appended

  - ### addErrorAndContinue

    public void addErrorAndContinue(String error, ASTNode node, SourceUnit source)
    Adds a syntax error for the supplied AST node without failing immediately.
    Parameters:
      `error` - the error message
      `node` - the offending AST node
      `source` - the source unit containing the node

  - ### addErrorAndContinue

    public void addErrorAndContinue(SyntaxException error, SourceUnit source)
    Adds a syntax error without failing immediately.
    Parameters:
      `error` - the syntax error
      `source` - the source unit containing the error

  - ### addErrorAndContinue

    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.

  - ### addError

    public void addError(Message message) throws CompilationFailedException
    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.
    Throws:
      `CompilationFailedException`

  - ### addError

    public void addError(Message message, boolean fatal) throws CompilationFailedException
    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
    Throws:
      `CompilationFailedException`

  - ### addError

    public void addError(SyntaxException error, SourceUnit source) throws CompilationFailedException
    Adds a syntax error and fails if it is marked fatal or exceeds tolerance.
    Parameters:
      `error` - the syntax error
      `source` - the source unit containing the error
    Throws:
      `CompilationFailedException` - if compilation must stop

  - ### addError

    public void addError(String error, CSTNode context, SourceUnit source) throws CompilationFailedException
    Adds a source-located error message.
    Parameters:
      `error` - the error text
      `context` - the CST node describing the source location
      `source` - the source unit containing the error
    Throws:
      `CompilationFailedException` - if compilation must stop

  - ### addException

    public void addException(Exception exception, SourceUnit source) throws CompilationFailedException
    Adds an exception-based error for the supplied source unit and then fails.
    Parameters:
      `exception` - the exception to report
      `source` - the source unit being processed
    Throws:
      `CompilationFailedException` - if compilation must stop

  - ### addFatalError

    public void addFatalError(Message message) throws CompilationFailedException
    Adds an error to the message set and throws CompilationFailedException.
    Throws:
      `CompilationFailedException`

  - ### addWarning

    public void addWarning(WarningMessage message)
    Adds a warning to the message set.

  - ### addWarning

    public void addWarning(int importance, String text, CSTNode context, SourceUnit source)
    Adds a warning to the message set if it is relevant.

  - ### addWarning

    public void addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source)
    Adds a warning to the message set if it is relevant.

  - ### getConfiguration

    public CompilerConfiguration getConfiguration()
    Returns:
      the compiler configuration used to create this error collector

  - ### getErrorCount

    public int getErrorCount()
    Returns the number of errors.

  - ### getError

    public Message getError(int index)
    Returns the specified error message, or null.

  - ### getErrors

    public List<? extends Message> getErrors()
    Returns the list of errors, or null if there are none.

  - ### hasErrors

    public boolean hasErrors()
    Returns true if there are any errors pending.

  - ### getWarningCount

    public int getWarningCount()
    Returns the number of warnings.

  - ### getWarning

    public WarningMessage getWarning(int index)
    Returns the specified warning message, or null.

  - ### getWarnings

    public List<WarningMessage> getWarnings()
    Returns the list of warnings, or null if there are none.

  - ### hasWarnings

    public boolean hasWarnings()
    Returns true if there are any warnings pending.

  - ### getLastError

    public Message getLastError()
    Returns the last error reported.

  - ### getException

    public Exception getException(int index)
    Returns the specified error's underlying Exception, or null if it isn't one.

  - ### getSyntaxError

    public SyntaxException getSyntaxError(int index)
    Returns the specified error's underlying SyntaxException, or null if it isn't one.

  - ### failIfErrors

    protected void failIfErrors() throws CompilationFailedException
    Causes the current phase to fail by throwing a CompilationFailedException.
    Throws:
      `CompilationFailedException`

  - ### write

    public void write(PrintWriter writer, Janitor janitor)
    Writes error messages to the specified PrintWriter.