org.codehaus.groovy.control
Class ProcessingUnit

java.lang.Object
  extended byorg.codehaus.groovy.control.ProcessingUnit
Direct Known Subclasses:
CompilationUnit, SourceUnit

public abstract class ProcessingUnit
extends java.lang.Object

A base class for data structures that can collect messages and errors during processing.

Version:
$Id: ProcessingUnit.java,v 1.8 2005/02/17 10:56:46 jstrachan Exp $
Author:
Chris Poirier

Field Summary
protected  java.lang.ClassLoader classLoader
          The ClassLoader to use during processing
protected  CompilerConfiguration configuration
          Configuration and other settings that control processing
protected  java.util.LinkedList errors
          ErrorMessages collected during processing
protected  boolean fatal
          Set on the first fatal error
protected  java.io.PrintWriter output
          A place to send warning output
protected  int phase
          The current phase
protected  boolean phaseComplete
          Set true if phase is finished
protected  int tolerance
          The number of non-fatal errors to allow before fail()
protected  int warningLevel
          Warnings will be filtered on this level
protected  java.util.LinkedList warnings
          WarningMessages collected during processing
 
Constructor Summary
ProcessingUnit(CompilerConfiguration configuration, java.lang.ClassLoader classLoader)
          Initialize the ProcessingUnit to the empty state.
 
Method Summary
 void addError(Message message)
          Adds a non-fatal error to the message set.
 void addError(Message message, boolean fatal)
          Adds an optionally-fatal error to the message set.
 void addException(java.lang.Exception cause)
           
 void addFatalError(Message message)
          Adds a fatal exception to the message set and throws the unit as a PhaseFailedException.
 void addWarning(WarningMessage message)
          Adds a WarningMessage to the message set.
 void completePhase()
          Marks the current phase complete and processes any errors.
 void configure(CompilerConfiguration configuration)
          Reconfigures the ProcessingUnit.
protected  void fail()
          Causes the current phase to fail by throwing a CompilationFailedException.
 java.lang.ClassLoader getClassLoader()
          Returns the class loader in use by this ProcessingUnit.
 CompilerConfiguration getConfiguration()
           
 Message getError(int index)
          Returns the specified error message, or null.
 int getErrorCount()
          Returns the number of errors.
 java.util.List getErrors()
          Returns the list of errors, or null if there are none.
 java.lang.Exception getException(int index)
          Convenience routine to return the specified error's underlying Exception, or null if it isn't one.
 int getPhase()
          Returns the current phase.
 java.lang.String getPhaseDescription()
          Returns the description for the current phase.
 SyntaxException getSyntaxError(int index)
          Convenience routine to return 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.
 java.util.List getWarnings()
          Returns the list of warnings, or null if there are none.
 void gotoPhase(int phase)
          Wraps up any pending operations for the current phase and switches to the next phase.
 boolean hasErrors()
          Returns true if there are any errors pending.
 void nextPhase()
          A synonym for gotoPhase( phase + 1 ).
 void setClassLoader(java.lang.ClassLoader loader)
          Sets the class loader for use by this ProcessingUnit.
 void setConfiguration(CompilerConfiguration configuration)
           
 void write(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 Detail

warnings

protected java.util.LinkedList warnings
WarningMessages collected during processing


errors

protected java.util.LinkedList errors
ErrorMessages collected during processing


fatal

protected boolean fatal
Set on the first fatal error


phase

protected int phase
The current phase


phaseComplete

protected boolean phaseComplete
Set true if phase is finished


configuration

protected CompilerConfiguration configuration
Configuration and other settings that control processing


warningLevel

protected int warningLevel
Warnings will be filtered on this level


output

protected java.io.PrintWriter output
A place to send warning output


tolerance

protected int tolerance
The number of non-fatal errors to allow before fail()


classLoader

protected java.lang.ClassLoader classLoader
The ClassLoader to use during processing

Constructor Detail

ProcessingUnit

public ProcessingUnit(CompilerConfiguration configuration,
                      java.lang.ClassLoader classLoader)
Initialize the ProcessingUnit to the empty state.

Method Detail

configure

public void configure(CompilerConfiguration configuration)
Reconfigures the ProcessingUnit.


getConfiguration

public CompilerConfiguration getConfiguration()

setConfiguration

public void setConfiguration(CompilerConfiguration configuration)

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the class loader in use by this ProcessingUnit.


setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Sets the class loader for use by this ProcessingUnit.


getPhase

public int getPhase()
Returns the current phase.


getPhaseDescription

public java.lang.String getPhaseDescription()
Returns the description for the current phase.


getWarnings

public java.util.List getWarnings()
Returns the list of warnings, or null if there are none.


getErrors

public java.util.List 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

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


getError

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


getSyntaxError

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


getException

public java.lang.Exception getException(int index)
Convenience routine to return the specified error's underlying Exception, or null if it isn't one.


addWarning

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


addError

public void addError(Message message)
              throws CompilationFailedException
Adds a non-fatal error to the message set.

Throws:
CompilationFailedException

addError

public void addError(Message message,
                     boolean fatal)
              throws CompilationFailedException
Adds an optionally-fatal error to the message set. Throws the unit as a PhaseFailedException, if the error is fatal.

Throws:
CompilationFailedException

addFatalError

public void addFatalError(Message message)
                   throws CompilationFailedException
Adds a fatal exception to the message set and throws the unit as a PhaseFailedException.

Throws:
CompilationFailedException

addException

public void addException(java.lang.Exception cause)
                  throws CompilationFailedException
Throws:
CompilationFailedException

hasErrors

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


completePhase

public void completePhase()
                   throws CompilationFailedException
Marks the current phase complete and processes any errors.

Throws:
CompilationFailedException

nextPhase

public void nextPhase()
               throws CompilationFailedException
A synonym for gotoPhase( phase + 1 ).

Throws:
CompilationFailedException

gotoPhase

public void gotoPhase(int phase)
               throws CompilationFailedException
Wraps up any pending operations for the current phase and switches to the next phase.

Throws:
CompilationFailedException

fail

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

Throws:
CompilationFailedException

write

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



Copyright © 2003-2005 The Codehaus. All Rights Reserved.