Save This Page
Home » groovy-src-1.6.3 » org.codehaus » groovy » control » [javadoc | source]
org.codehaus.groovy.control
public class: CompilationUnit [javadoc | source]
java.lang.Object
   org.codehaus.groovy.control.ProcessingUnit
      org.codehaus.groovy.control.CompilationUnit

Direct Known Subclasses:
    JavaStubCompilationUnit, JavaAwareCompilationUnit

Collects all compilation data as it is generated by the compiler system. Allows additional source units to be added and compilation run again (to affect only the deltas).
Nested Class Summary:
abstract public static class  CompilationUnit.ClassgenCallback  A callback interface you can use to "accompany" the classgen() code as it traverses the ClassNode tree. You will be called-back for each primary and inner class. Use setClassgenCallback() before running compile() to set your callback. 
abstract public static class  CompilationUnit.ProgressCallback  A callback interface you can use to get a callback after every unit of the compile process. You will be called-back with a ProcessingUnit and a phase indicator. Use setProgressCallback() before running compile() to set your callback. 
abstract public static class  CompilationUnit.SourceUnitOperation  An callback interface for use in the applyToSourceUnits loop driver. 
abstract public static class  CompilationUnit.PrimaryClassNodeOperation  An callback interface for use in the applyToSourceUnits loop driver. 
abstract public static class  CompilationUnit.GroovyClassOperation   
Field Summary
protected  Map sources     
protected  Map summariesBySourceName     
protected  Map summariesByPublicClassName     
protected  Map classSourcesByPublicClassName     
protected  List names     
protected  LinkedList queuedSources     
protected  CompileUnit ast     
protected  List generatedClasses     
protected  Verifier verifier     
protected  boolean debug     
protected  boolean configured     
protected  CompilationUnit.ClassgenCallback classgenCallback     
protected  CompilationUnit.ProgressCallback progressCallback     
protected  ResolveVisitor resolveVisitor     
protected  StaticImportVisitor staticImportVisitor     
protected  OptimizerVisitor optimizer     
 LinkedList[] phaseOperations     
Fields inherited from org.codehaus.groovy.control.ProcessingUnit:
phase,  phaseComplete,  configuration,  classLoader,  errorCollector
Constructor:
 public CompilationUnit() 
 public CompilationUnit(GroovyClassLoader loader) 
    Initializes the CompilationUnit with defaults except for class loader.
 public CompilationUnit(CompilerConfiguration configuration) 
    Initializes the CompilationUnit with no security considerations.
 public CompilationUnit(CompilerConfiguration configuration,
    CodeSource security,
    GroovyClassLoader loader) 
    Initializes the CompilationUnit with a CodeSource for controlling security stuff and a class loader for loading classes.
 public CompilationUnit(CompilerConfiguration configuration,
    CodeSource security,
    GroovyClassLoader loader,
    GroovyClassLoader transformLoader) 
    Initializes the CompilationUnit with a CodeSource for controlling security stuff, a class loader for loading classes, and a class loader for loading AST transformations. Note The transform loader must be able to load compiler classes. That means CompilationUnit.class.classLoader must be at last a parent to transformLoader. The other loader has no such constraint.
    Parameters:
    transformLoader - - the loader for transforms
    loader - - loader used to resolve classes against during compilation
    security - - security setting for the compilation
    configuration - - compilation configuration
Method from org.codehaus.groovy.control.CompilationUnit Summary:
addClassNode,   addPhaseOperation,   addPhaseOperation,   addPhaseOperation,   addSource,   addSource,   addSource,   addSource,   addSources,   addSources,   applyToGeneratedGroovyClasses,   applyToPrimaryClassNodes,   applyToSourceUnits,   compile,   compile,   configure,   createClassVisitor,   dequeued,   getAST,   getClassNode,   getClassSourcesByPublicClassName,   getClasses,   getFirstClassNode,   getSummariesByPublicClassName,   getSummariesBySourceName,   getTransformLoader,   isPublicClass,   iterator,   mark,   setClassgenCallback,   setProgressCallback
Methods from org.codehaus.groovy.control.ProcessingUnit:
completePhase,   configure,   getClassLoader,   getConfiguration,   getErrorCollector,   getPhase,   getPhaseDescription,   gotoPhase,   nextPhase,   setClassLoader,   setConfiguration
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.codehaus.groovy.control.CompilationUnit Detail:
 public  void addClassNode(ClassNode node) 
    Adds a ClassNode directly to the unit (ie. without source). WARNING: the source is needed for error reporting, using this method without setting a SourceUnit will cause NullPinterExceptions
 public  void addPhaseOperation(CompilationUnit.GroovyClassOperation op) 
 public  void addPhaseOperation(CompilationUnit.SourceUnitOperation op,
    int phase) 
 public  void addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op,
    int phase) 
 public SourceUnit addSource(File file) 
    Adds a source file to the unit.
 public SourceUnit addSource(URL url) 
    Adds a source file to the unit.
 public SourceUnit addSource(SourceUnit source) 
    Adds a SourceUnit to the unit.
 public SourceUnit addSource(String name,
    InputStream stream) 
    Adds a InputStream source to the unit.
 public  void addSources(String[] paths) 
    Adds a set of file paths to the unit.
 public  void addSources(File[] files) 
    Adds a set of source files to the unit.
 public  void applyToGeneratedGroovyClasses(CompilationUnit.GroovyClassOperation body) throws CompilationFailedException 
 public  void applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation body) throws CompilationFailedException 
    A loop driver for applying operations to all primary ClassNodes in our AST. Automatically skips units that have already been processed through the current phase.
 public  void applyToSourceUnits(CompilationUnit.SourceUnitOperation body) throws CompilationFailedException 
    A loop driver for applying operations to all SourceUnits. Automatically skips units that have already been processed through the current phase.
 public  void compile() throws CompilationFailedException 
    Synonym for compile(Phases.ALL).
 public  void compile(int throughPhase) throws CompilationFailedException 
    Compiles the compilation unit from sources.
 public  void configure(CompilerConfiguration configuration) 
    Configures its debugging mode and classloader classpath from a given compiler configuration. This cannot be done more than once due to limitations in URLClassLoader .
 protected ClassVisitor createClassVisitor() 
 protected boolean dequeued() throws CompilationFailedException 
    Dequeues any source units add through addSource and resets the compiler phase to initialization.

    Note: this does not mean a file is recompiled. If a SoucreUnit has already passed a phase it is skipped until a higher phase is reached.

 public CompileUnit getAST() 
    Returns the CompileUnit that roots our AST.
 public ClassNode getClassNode(String name) 
    Convenience routine to get the named ClassNode.
 public Map getClassSourcesByPublicClassName() 
 public List getClasses() 
    Get the GroovyClasses generated by compile().
 public ClassNode getFirstClassNode() 
    Convenience routine to get the first ClassNode, for when you are sure there is only one.
 public Map getSummariesByPublicClassName() 
 public Map getSummariesBySourceName() 
    Get the source summaries
 public GroovyClassLoader getTransformLoader() 
    Returns the class loader for loading AST transformations.
 public boolean isPublicClass(String className) 
 public Iterator iterator() 
    Returns an iterator on the unit's SourceUnits.
 protected  void mark() throws CompilationFailedException 
    Updates the phase marker on all sources.
 public  void setClassgenCallback(CompilationUnit.ClassgenCallback visitor) 
    Sets a ClassgenCallback. You can have only one, and setting it to null removes any existing setting.
 public  void setProgressCallback(CompilationUnit.ProgressCallback callback) 
    Sets a ProgressCallback. You can have only one, and setting it to null removes any existing setting.