Groovy Documentation

## org.codehaus.groovy.control
[Java] Class CompilationUnit

    java.lang.Object
      org.codehaus.groovy.control.ProcessingUnit
          org.codehaus.groovy.control.CompilationUnit

    public class CompilationUnit
    extends ProcessingUnit

The CompilationUnit collects all compilation data as it is generated by the compiler system. You can use this object to add additional source units to the compilation, or force the compilation to be run again (to affect only the deltas).
You can also add PhaseOperations to this compilation using the addPhaseOperation method. This is commonly used when you want to wire a new AST Transformation into the compilation.

Authors:
  Chris Poirier
  Jochen Theodorou
  Roshan Dawrani

Version:
  \$Id\$

Nested Class Summary
`static class` | `CompilationUnit.ClassgenCallback` Sets a ClassgenCallback.
`static class` | `CompilationUnit.GroovyClassOperation`
`static class` | `CompilationUnit.PrimaryClassNodeOperation`
`static class` | `CompilationUnit.ProgressCallback`
`static class` | `CompilationUnit.SourceUnitOperation`

Field Summary
`protected CompileUnit` | `ast`
`protected ASTTransformationsContext` | `astTransformationsContext`
`protected ClassNodeResolver` | `classNodeResolver`
`protected java.util.Map` | `classSourcesByPublicClassName`
`protected CompilationUnit.ClassgenCallback` | `classgenCallback` Initializes the CompilationUnit with defaults.
`protected boolean` | `configured`
`protected boolean` | `debug`
`protected java.util.List` | `generatedClasses`
`protected java.util.List` | `names`
`protected OptimizerVisitor` | `optimizer`
`protected CompilationUnit.ProgressCallback` | `progressCallback`
`protected java.util.LinkedList` | `queuedSources`
`protected ResolveVisitor` | `resolveVisitor`
`protected java.util.Map` | `sources`
`protected StaticImportVisitor` | `staticImportVisitor`
`protected java.util.Map` | `summariesByPublicClassName`
`protected java.util.Map` | `summariesBySourceName`
`protected Verifier` | `verifier`

Fields inherited from class ProcessingUnit
classLoader, configuration, errorCollector, phase, phaseComplete

Constructor Summary
`CompilationUnit()`
`CompilationUnit(GroovyClassLoader loader)`
`CompilationUnit(CompilerConfiguration configuration)`
`CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader)`
`CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader, GroovyClassLoader transformLoader)`

Method Summary
`void` | `addClassNode(ClassNode node)` Adds a ClassNode directly to the unit (ie. without source).
`void` | `addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)`
`void` | `addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)`
`void` | `addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase)`
`void` | `addPhaseOperation(CompilationUnit.GroovyClassOperation op)`
`SourceUnit` | `addSource(java.io.File file)` Adds a InputStream source to the unit.
`SourceUnit` | `addSource(java.net.URL url)`
`SourceUnit` | `addSource(java.lang.String name, java.io.InputStream stream)`
`SourceUnit` | `addSource(java.lang.String name, java.lang.String scriptText)`
`SourceUnit` | `addSource(SourceUnit source)` Returns an iterator on the unit's SourceUnits.
`void` | `addSources(java.lang.String[] paths)` Adds a set of source files to the unit.
`void` | `addSources(java.io.File[] files)` Adds a source file to the unit.
`void` | `applyToGeneratedGroovyClasses(CompilationUnit.GroovyClassOperation body)`
`void` | `applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation body)`
`void` | `applyToSourceUnits(CompilationUnit.SourceUnitOperation body)`
`void` | `compile()`
`void` | `compile(int throughPhase)`
`void` | `configure(CompilerConfiguration configuration)`
`protected org.objectweb.asm.ClassVisitor` | `createClassVisitor()` Updates the phase marker on all sources.
`protected boolean` | `dequeued()` Resolves all types
`CompileUnit` | `getAST()`
`ASTTransformationsContext` | `getASTTransformationsContext()` @return the AST transformations current context
`ClassNode` | `getClassNode(java.lang.String name)`
`ClassNodeResolver` | `getClassNodeResolver()`
`java.util.Map` | `getClassSourcesByPublicClassName()`
`java.util.List` | `getClasses()` Convenience routine to get the named ClassNode.
`CompilationUnit.ClassgenCallback` | `getClassgenCallback()`
`ClassNode` | `getFirstClassNode()`
`CompilationUnit.ProgressCallback` | `getProgressCallback()`
`java.util.Map` | `getSummariesByPublicClassName()` Get the GroovyClasses generated by compile().
`java.util.Map` | `getSummariesBySourceName()`
`GroovyClassLoader` | `getTransformLoader()` Returns the class loader for loading AST transformations.
`boolean` | `isPublicClass(java.lang.String className)`
`java.util.Iterator` | `iterator()`
`protected void` | `mark()` An callback interface for use in the applyToSourceUnits loop driver.
`void` | `setClassNodeResolver(ClassNodeResolver classNodeResolver)`
`void` | `setClassgenCallback(CompilationUnit.ClassgenCallback visitor)` Sets a ProgressCallback.
`void` | `setProgressCallback(CompilationUnit.ProgressCallback callback)` Synonym for compile(Phases.ALL).

Methods inherited from class ProcessingUnit
completePhase, configure, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, nextPhase, setClassLoader, setConfiguration

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### ast

    protected CompileUnit ast

### astTransformationsContext

    protected ASTTransformationsContext astTransformationsContext

### classNodeResolver

    protected ClassNodeResolver classNodeResolver

### classSourcesByPublicClassName

    protected java.util.Map classSourcesByPublicClassName

### classgenCallback

    protected CompilationUnit.ClassgenCallback classgenCallback

  Initializes the CompilationUnit with defaults.

### configured

    protected boolean configured

### debug

    protected boolean debug

### generatedClasses

    protected java.util.List generatedClasses

### names

    protected java.util.List names

### optimizer

    protected OptimizerVisitor optimizer

### progressCallback

    protected CompilationUnit.ProgressCallback progressCallback

### queuedSources

    protected java.util.LinkedList queuedSources

### resolveVisitor

    protected ResolveVisitor resolveVisitor

### sources

    protected java.util.Map sources

### staticImportVisitor

    protected StaticImportVisitor staticImportVisitor

### summariesByPublicClassName

    protected java.util.Map summariesByPublicClassName

### summariesBySourceName

    protected java.util.Map summariesBySourceName

### verifier

    protected Verifier verifier

Constructor Detail

### CompilationUnit

    public CompilationUnit()

### CompilationUnit

    public CompilationUnit(GroovyClassLoader loader)

### CompilationUnit

    public CompilationUnit(CompilerConfiguration configuration)

### CompilationUnit

    public CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader)

### CompilationUnit

    public CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader, GroovyClassLoader transformLoader)

Method Detail

### addClassNode

    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

### addNewPhaseOperation

    public void addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(CompilationUnit.GroovyClassOperation op)

### addSource

    public SourceUnit addSource(java.io.File file)

  Adds a InputStream source to the unit.

### addSource

    public SourceUnit addSource(java.net.URL url)

### addSource

    public SourceUnit addSource(java.lang.String name, java.io.InputStream stream)

### addSource

    public SourceUnit addSource(java.lang.String name, java.lang.String scriptText)

### addSource

    public SourceUnit addSource(SourceUnit source)

  Returns an iterator on the unit's SourceUnits.

### addSources

    public void addSources(java.lang.String[] paths)

  Adds a set of source files to the unit.

### addSources

    public void addSources(java.io.File[] files)

  Adds a source file to the unit.

### applyToGeneratedGroovyClasses

    public void applyToGeneratedGroovyClasses(CompilationUnit.GroovyClassOperation body)

### applyToPrimaryClassNodes

    public void applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation body)

### applyToSourceUnits

    public void applyToSourceUnits(CompilationUnit.SourceUnitOperation body)

### compile

    public void compile()

### compile

    public void compile(int throughPhase)

### configure

    public void configure(CompilerConfiguration configuration)

### createClassVisitor

    protected org.objectweb.asm.ClassVisitor createClassVisitor()

  Updates the phase marker on all sources.

### dequeued

    protected boolean dequeued()

  Resolves all types

### getAST

    public CompileUnit getAST()

### getASTTransformationsContext

    public ASTTransformationsContext getASTTransformationsContext()

  Returns:
    the AST transformations current context

### getClassNode

    public ClassNode getClassNode(java.lang.String name)

### getClassNodeResolver

    public ClassNodeResolver getClassNodeResolver()

### getClassSourcesByPublicClassName

    public java.util.Map getClassSourcesByPublicClassName()

### getClasses

    public java.util.List getClasses()

  Convenience routine to get the named ClassNode.

### getClassgenCallback

    public CompilationUnit.ClassgenCallback getClassgenCallback()

### getFirstClassNode

    public ClassNode getFirstClassNode()

### getProgressCallback

    public CompilationUnit.ProgressCallback getProgressCallback()

### getSummariesByPublicClassName

    public java.util.Map getSummariesByPublicClassName()

  Get the GroovyClasses generated by compile().

### getSummariesBySourceName

    public java.util.Map getSummariesBySourceName()

### getTransformLoader

    public GroovyClassLoader getTransformLoader()

  Returns the class loader for loading AST transformations.
  Returns:
    - the transform class loader

### isPublicClass

    public boolean isPublicClass(java.lang.String className)

### iterator

    public java.util.Iterator iterator()

### mark

    protected void mark()

  An callback interface for use in the applyToSourceUnits loop driver.

### setClassNodeResolver

    public void setClassNodeResolver(ClassNodeResolver classNodeResolver)

### setClassgenCallback

    public void setClassgenCallback(CompilationUnit.ClassgenCallback visitor)

  Sets a ProgressCallback. You can have only one, and setting it to null removes any existing setting.

### setProgressCallback

    public void setProgressCallback(CompilationUnit.ProgressCallback callback)

  Synonym for compile(Phases.ALL).

Groovy Documentation