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 Object

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

Version:
$Id: ProcessingUnit.java,v 1.1 2004/04/19 07:29:44 cpoirier Exp $
Author:
Chris Poirier

Field Summary
protected  ClassLoader classLoader
           
protected  CompilerConfiguration configuration
           
protected  LinkedList errors
           
protected  boolean fatal
           
protected  PrintWriter output
           
protected  int phase
           
protected  boolean phaseComplete
           
protected  int tolerance
           
protected  int warningLevel
           
protected  LinkedList warnings
           
 
Constructor Summary
ProcessingUnit(CompilerConfiguration configuration, 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 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.
 ClassLoader getClassLoader()
          Returns the class loader in use by this ProcessingUnit.
 Message getError(int index)
          Returns the specified error message, or null.
 int getErrorCount()
          Returns the number of errors.
 List getErrors()
          Returns the list of errors, or null if there are none.
 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.
 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.
 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(ClassLoader loader)
          Sets the class loader for use by this ProcessingUnit.
 void write(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 LinkedList warnings

errors

protected LinkedList errors

fatal

protected boolean fatal

phase

protected int phase

phaseComplete

protected boolean phaseComplete

configuration

protected CompilerConfiguration configuration

warningLevel

protected int warningLevel

output

protected PrintWriter output

tolerance

protected int tolerance

classLoader

protected ClassLoader classLoader
Constructor Detail

ProcessingUnit

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

Method Detail

configure

public void configure(CompilerConfiguration configuration)
Reconfigures the ProcessingUnit.


getClassLoader

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


setClassLoader

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


getPhase

public int getPhase()
Returns the current phase.


getPhaseDescription

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


getWarnings

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


getErrors

public 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 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

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(PrintWriter writer,
                  Janitor janitor)
Writes error messages to the specified PrintWriter.



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