Package org.codehaus.groovy.control
Class ErrorCollector
java.lang.Object
org.codehaus.groovy.control.ErrorCollector
- All Implemented Interfaces:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CompilerConfigurationConfiguration and other settings that control processingprotected LinkedList<Message>ErrorMessages collected during processingprotected LinkedList<WarningMessage>WarningMessages collected during processing -
Constructor Summary
ConstructorsConstructorDescriptionErrorCollector(CompilerConfiguration configuration) Initialize the ErrorReporter. -
Method Summary
Modifier and TypeMethodDescriptionvoidMerges the recorded warnings and errors from another collector into this one.voidaddError(String error, CSTNode context, SourceUnit source) Adds a source-located error message.voidAdds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.voidAdds an optionally-fatal error to the message set.voidaddError(SyntaxException error, SourceUnit source) Adds a syntax error and fails if it is marked fatal or exceeds tolerance.voidaddErrorAndContinue(String error, ASTNode node, SourceUnit source) Adds a syntax error for the supplied AST node without failing immediately.voidaddErrorAndContinue(Message message) Adds an error to the message set, but does not cause a failure.voidaddErrorAndContinue(SyntaxException error, SourceUnit source) Adds a syntax error without failing immediately.voidaddException(Exception exception, SourceUnit source) Adds an exception-based error for the supplied source unit and then fails.voidaddFatalError(Message message) Adds an error to the message set and throws CompilationFailedException.voidaddWarning(int importance, String text, Object data, CSTNode context, SourceUnit source) Adds a warning to the message set if it is relevant.voidaddWarning(int importance, 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 voidCauses the current phase to fail by throwing a CompilationFailedException.getError(int index) Returns the specified error message, or null.intReturns the number of errors.Returns the list of errors, or null if there are none.getException(int index) Returns the specified error's underlying Exception, or null if it isn't one.Returns the last error reported.getSyntaxError(int index) Returns the specified error's underlying SyntaxException, or null if it isn't one.getWarning(int index) Returns the specified warning message, or null.intReturns the number of warnings.Returns the list of warnings, or null if there are none.booleanReturns true if there are any errors pending.booleanReturns true if there are any warnings pending.voidwrite(PrintWriter writer, Janitor janitor) Writes error messages to the specified PrintWriter.
-
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
Merges the recorded warnings and errors from another collector into this one.- Parameters:
that- the collector whose contents should be appended
-
addErrorAndContinue
Adds a syntax error for the supplied AST node without failing immediately.- Parameters:
error- the error messagenode- the offending AST nodesource- the source unit containing the node
-
addErrorAndContinue
Adds a syntax error without failing immediately.- Parameters:
error- the syntax errorsource- the source unit containing the error
-
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 processing will stop- Throws:
CompilationFailedException
-
addError
Adds a syntax error and fails if it is marked fatal or exceeds tolerance.- Parameters:
error- the syntax errorsource- 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 textcontext- the CST node describing the source locationsource- the source unit containing the error- Throws:
CompilationFailedException- if compilation must stop
-
addException
Adds an exception-based error for the supplied source unit and then fails.- Parameters:
exception- the exception to reportsource- the source unit being processed- Throws:
CompilationFailedException- if compilation must stop
-
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, String text, 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
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.
-