Top Description Fields Constructors Methods
org.codehaus.groovy.control

public Class ErrorCollector

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
org.codehaus.groovy.ast.ASTNode, org.codehaus.groovy.control.messages.ExceptionMessage, .LocatedMessage, .Message, .SyntaxErrorMessage, .WarningMessage, org.codehaus.groovy.syntax.CSTNode, .SyntaxException, java.io.PrintWriter, .Serializable, java.util.LinkedList, .List

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

Modifier and TypeField and Description
protected final CompilerConfiguration
configuration

Configuration and other settings that control processing

protected LinkedList<Message>
errors

ErrorMessages collected during processing

private static final long
protected LinkedList<WarningMessage>
warnings

WarningMessages collected during processing

Constructor Summary

AccessConstructor and Description
public
ErrorCollector(final CompilerConfiguration configuration)

Initialize the ErrorReporter.

Method Summary

Modifier and TypeMethod and Description
public void
public void
addError(final 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(final Message message, final boolean
if true then then processing will stop
fatal
)

Adds an optionally-fatal error to the message set.

public void
addError(final SyntaxException error, final SourceUnit source)

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

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

public void
addErrorAndContinue(final SyntaxException error, final SourceUnit source)

public void
addErrorAndContinue(final Message message)

Adds an error to the message set, but does not cause a failure.

public void
addException(final Exception exception, final SourceUnit source)

public void
addFatalError(final Message message)

Adds an error to the message set and throws CompilationFailedException.

public void
addWarning(final WarningMessage message)

Adds a warning to the message set.

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

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

public void
addWarning(final int importance, final String text, final Object data, final CSTNode context, final 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

Returns:

the compiler configuration used to create this error collector
getConfiguration
()

public Message
getError(final 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(final 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(final int index)

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

public WarningMessage
getWarning(final 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.

private void
write(final PrintWriter writer, final Janitor janitor, final List<? extends Message> messages, final String txt)

public void
write(final PrintWriter writer, final Janitor janitor)

Writes error messages to the specified PrintWriter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurationback to summary
protected final CompilerConfiguration configuration

Configuration and other settings that control processing

errorsback to summary
protected LinkedList<Message> errors

ErrorMessages collected during processing

serialVersionUIDback to summary
private static final long serialVersionUID
warningsback to summary
protected LinkedList<WarningMessage> warnings

WarningMessages collected during processing

Constructor Detail

ErrorCollectorback to summary
public ErrorCollector(final CompilerConfiguration configuration)

Initialize the ErrorReporter.

Method Detail

addCollectorContentsback to summary
public void addCollectorContents(final ErrorCollector that)
addErrorback to summary
public void addError(final 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.

addErrorback to summary
public void addError(final Message message, final 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:boolean

if true then then processing will stop

addErrorback to summary
public void addError(final SyntaxException error, final SourceUnit source) throws CompilationFailedException
addErrorback to summary
public void addError(final String error, final CSTNode context, final SourceUnit source) throws CompilationFailedException
addErrorAndContinueback to summary
public void addErrorAndContinue(final String error, final ASTNode node, final SourceUnit source)
addErrorAndContinueback to summary
public void addErrorAndContinue(final SyntaxException error, final SourceUnit source)
addErrorAndContinueback to summary
public void addErrorAndContinue(final 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.

addExceptionback to summary
public void addException(final Exception exception, final SourceUnit source) throws CompilationFailedException
addFatalErrorback to summary
public void addFatalError(final Message message) throws CompilationFailedException

Adds an error to the message set and throws CompilationFailedException.

addWarningback to summary
public void addWarning(final WarningMessage message)

Adds a warning to the message set.

addWarningback to summary
public void addWarning(final int importance, final String text, final CSTNode context, final SourceUnit source)

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

addWarningback to summary
public void addWarning(final int importance, final String text, final Object data, final CSTNode context, final SourceUnit source)

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

failIfErrorsback to summary
protected void failIfErrors() throws CompilationFailedException

Causes the current phase to fail by throwing a CompilationFailedException.

getConfigurationback to summary
public CompilerConfiguration getConfiguration()
Returns:CompilerConfiguration

the compiler configuration used to create this error collector

getErrorback to summary
public Message getError(final int index)

Returns the specified error message, or null.

getErrorCountback to summary
public int getErrorCount()

Returns the number of errors.

getErrorsback to summary
public List<? extends Message> getErrors()

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

getExceptionback to summary
public Exception getException(final int index)

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

getLastErrorback to summary
public Message getLastError()

Returns the last error reported.

getSyntaxErrorback to summary
public SyntaxException getSyntaxError(final int index)

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

getWarningback to summary
public WarningMessage getWarning(final int index)

Returns the specified warning message, or null.

getWarningCountback to summary
public int getWarningCount()

Returns the number of warnings.

getWarningsback to summary
public List<WarningMessage> getWarnings()

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

hasErrorsback to summary
public boolean hasErrors()

Returns true if there are any errors pending.

hasWarningsback to summary
public boolean hasWarnings()

Returns true if there are any warnings pending.

writeback to summary
private void write(final PrintWriter writer, final Janitor janitor, final List<? extends Message> messages, final String txt)
writeback to summary
public void write(final PrintWriter writer, final Janitor janitor)

Writes error messages to the specified PrintWriter.