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
Modifier and TypeFieldDescriptionprotected CompilerConfiguration
Configuration and other settings that control processingprotected LinkedList
ErrorMessages collected during processingprotected LinkedList
WarningMessages collected during processing -
Constructor Summary
ConstructorDescriptionErrorCollector
(CompilerConfiguration configuration) Initialize the ErrorReporter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addError
(String text, CSTNode context, SourceUnit source) Convenience wrapper for addError().void
Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.void
Adds an optionally-fatal error to the message set.void
addError
(SyntaxException error, SourceUnit source) Convenience wrapper for addError().void
addErrorAndContinue
(Message message) Adds an error to the message set, but does not cause a failure.void
addException
(Exception cause, SourceUnit source) void
addFatalError
(Message message) Adds a fatal exception to the message set and throws the unit as a PhaseFailedException.void
addWarning
(int importance, String text, Object data, CSTNode context, SourceUnit source) Convenience wrapper for addWarning() that won't create an object unless it is relevant.void
addWarning
(int importance, String text, CSTNode context, SourceUnit source) Convenience wrapper for addWarning() that won't create an object unless it is relevant.void
addWarning
(WarningMessage message) Adds a WarningMessage to the message set.protected void
Causes the current phase to fail by throwing a CompilationFailedException.getError
(int index) Returns the specified error message, or null.int
Returns the number of errors.Returns the list of errors, or null if there are none.getException
(int index) Convenience routine to return the specified error's underlying Exception, or null if it isn't one.Returns the last error reportedgetSyntaxError
(int index) Convenience routine to return the specified error's underlying SyntaxException, or null if it isn't one.getWarning
(int index) Returns the specified warning message, or null.int
Returns the number of warnings.Returns the list of warnings, or null if there are none.boolean
Returns true if there are any errors pending.boolean
Returns true if there are any warnings pending.void
write
(PrintWriter writer, Janitor janitor) Writes error messages to the specified PrintWriter.
-
Field Details
-
warnings
WarningMessages collected during processing -
errors
ErrorMessages collected during processing -
configuration
Configuration and other settings that control processing
-
-
Constructor Details
-
ErrorCollector
Initialize the ErrorReporter.
-
-
Method Details
-
addCollectorContents
-
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
Convenience wrapper for addError().- Throws:
CompilationFailedException
-
addError
public void addError(String text, CSTNode context, SourceUnit source) throws CompilationFailedException Convenience wrapper for addError().- Throws:
CompilationFailedException
-
addFatalError
Adds a fatal exception to the message set and throws the unit as a PhaseFailedException.- Throws:
CompilationFailedException
-
addException
- Throws:
CompilationFailedException
-
hasErrors
public boolean hasErrors()Returns true if there are any errors pending. -
getConfiguration
- Returns:
- the compiler configuration used to create this error collector
-
hasWarnings
public boolean hasWarnings()Returns true if there are any warnings pending. -
getWarnings
Returns the list of warnings, or null if there are none. -
getErrors
Returns the list of errors, or null if there are none. -
getWarningCount
public int getWarningCount()Returns the number of warnings. -
getErrorCount
public int getErrorCount()Returns the number of errors. -
getWarning
Returns the specified warning message, or null. -
getError
Returns the specified error message, or null. -
getLastError
Returns the last error reported -
getSyntaxError
Convenience routine to return the specified error's underlying SyntaxException, or null if it isn't one. -
getException
Convenience routine to return the specified error's underlying Exception, or null if it isn't one. -
addWarning
Adds a WarningMessage to the message set. -
addWarning
Convenience wrapper for addWarning() that won't create an object unless it is relevant. -
addWarning
public void addWarning(int importance, String text, Object data, CSTNode context, SourceUnit source) Convenience wrapper for addWarning() that won't create an object unless it is relevant. -
failIfErrors
Causes the current phase to fail by throwing a CompilationFailedException.- Throws:
CompilationFailedException
-
write
Writes error messages to the specified PrintWriter.
-