Package org.codehaus.groovy.control
Class ErrorCollector
java.lang.Object
org.codehaus.groovy.control.ErrorCollector
- All Implemented Interfaces:
java.io.Serializable
public class ErrorCollector
extends java.lang.Object
implements java.io.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 CompilerConfigurationconfigurationConfiguration and other settings that control processingprotected java.util.LinkedList<Message>errorsErrorMessages collected during processingprotected java.util.LinkedList<WarningMessage>warningsWarningMessages collected during processing -
Constructor Summary
Constructors Constructor Description ErrorCollector(CompilerConfiguration configuration)Initialize the ErrorReporter. -
Method Summary
Modifier and Type Method Description voidaddCollectorContents(ErrorCollector that)voidaddError(java.lang.String error, CSTNode context, SourceUnit source)voidaddError(Message message)Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.voidaddError(Message message, boolean fatal)Adds an optionally-fatal error to the message set.voidaddError(SyntaxException error, SourceUnit source)voidaddErrorAndContinue(java.lang.String error, ASTNode node, SourceUnit source)voidaddErrorAndContinue(Message message)Adds an error to the message set, but does not cause a failure.voidaddErrorAndContinue(SyntaxException error, SourceUnit source)voidaddException(java.lang.Exception exception, SourceUnit source)voidaddFatalError(Message message)Adds an error to the message set and throws CompilationFailedException.voidaddWarning(int importance, java.lang.String text, java.lang.Object data, CSTNode context, SourceUnit source)Adds a warning to the message set if it is relevant.voidaddWarning(int importance, java.lang.String text, CSTNode context, SourceUnit source)Adds a warning to the message set if it is relevant.voidaddWarning(WarningMessage message)Adds a warning to the message set.protected voidfailIfErrors()Causes the current phase to fail by throwing a CompilationFailedException.CompilerConfigurationgetConfiguration()MessagegetError(int index)Returns the specified error message, or null.intgetErrorCount()Returns the number of errors.java.util.List<? extends Message>getErrors()Returns the list of errors, or null if there are none.java.lang.ExceptiongetException(int index)Returns the specified error's underlying Exception, or null if it isn't one.MessagegetLastError()Returns the last error reported.SyntaxExceptiongetSyntaxError(int index)Returns the specified error's underlying SyntaxException, or null if it isn't one.WarningMessagegetWarning(int index)Returns the specified warning message, or null.intgetWarningCount()Returns the number of warnings.java.util.List<WarningMessage>getWarnings()Returns the list of warnings, or null if there are none.booleanhasErrors()Returns true if there are any errors pending.booleanhasWarnings()Returns true if there are any warnings pending.voidwrite(java.io.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
ErrorMessages collected during processing -
warnings
WarningMessages collected during processing -
configuration
Configuration and other settings that control processing
-
-
Constructor Details
-
ErrorCollector
Initialize the ErrorReporter.
-
-
Method Details
-
addCollectorContents
-
addErrorAndContinue
-
addErrorAndContinue
-
addErrorAndContinue
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
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
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 then processing will stop- Throws:
CompilationFailedException
-
addError
- Throws:
CompilationFailedException
-
addError
public void addError(java.lang.String error, CSTNode context, SourceUnit source) throws CompilationFailedException- Throws:
CompilationFailedException
-
addException
public void addException(java.lang.Exception exception, SourceUnit source) throws CompilationFailedException- Throws:
CompilationFailedException
-
addFatalError
Adds an error to the message set and throws CompilationFailedException.- Throws:
CompilationFailedException
-
addWarning
Adds a warning to the message set. -
addWarning
Adds a warning to the message set if it is relevant. -
addWarning
public void addWarning(int importance, java.lang.String text, java.lang.Object data, CSTNode context, SourceUnit source)Adds a warning to the message set if it is relevant. -
getConfiguration
- Returns:
- the compiler configuration used to create this error collector
-
getErrorCount
public int getErrorCount()Returns the number of errors. -
getError
Returns the specified error message, or null. -
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
Returns the specified warning message, or null. -
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
Returns the last error reported. -
getException
public java.lang.Exception getException(int index)Returns the specified error's underlying Exception, or null if it isn't one. -
getSyntaxError
Returns the specified error's underlying SyntaxException, or null if it isn't one. -
failIfErrors
Causes the current phase to fail by throwing a CompilationFailedException.- Throws:
CompilationFailedException
-
write
Writes error messages to the specified PrintWriter.
-