Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.0
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.control
Class CompilationUnit

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

    class CompilationUnit
    extends ProcessingUnit

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).

author:
  Chris Poirier

author:
  Jochen Theodorou

author:
  Roshan Dawrani

version:
  $Id: CompilationUnit.java 18431 2009-11-27 13:21:46Z roshandawrani $

Nested Class Summary
`class` | `CompilationUnit.ClassgenCallback` A callback interface you can use to "accompany" the classgen() code as it traverses the ClassNode tree.
`class` | `CompilationUnit.GroovyClassOperation`
`class` | `CompilationUnit.PrimaryClassNodeOperation` An callback interface for use in the applyToSourceUnits loop driver.
`class` | `CompilationUnit.ProgressCallback` A callback interface you can use to get a callback after every unit of the compile process.
`class` | `CompilationUnit.SourceUnitOperation` An callback interface for use in the applyToSourceUnits loop driver.

Field Summary
`protected CompileUnit` | `ast`
`protected Map` | `classSourcesByPublicClassName`
`protected ClassgenCallback` | `classgenCallback`
`protected boolean` | `configured`
`protected boolean` | `debug`
`protected List` | `generatedClasses`
`protected List` | `names`
`LinkedList[]` | `newPhaseOperations`
`protected OptimizerVisitor` | `optimizer`
`LinkedList[]` | `phaseOperations`
`protected ProgressCallback` | `progressCallback`
`protected LinkedList` | `queuedSources`
`protected ResolveVisitor` | `resolveVisitor`
`protected Map` | `sources`
`protected StaticImportVisitor` | `staticImportVisitor`
`protected Map` | `summariesByPublicClassName`
`protected Map` | `summariesBySourceName`
`protected Verifier` | `verifier`

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

Constructor Summary
`CompilationUnit()` Initializes the CompilationUnit with defaults.
`CompilationUnit(GroovyClassLoader loader)` Initializes the CompilationUnit with defaults except for class loader.
`CompilationUnit(CompilerConfiguration configuration)` Initializes the CompilationUnit with no security considerations.
`CompilationUnit(CompilerConfiguration configuration, CodeSource security, GroovyClassLoader loader)` Initializes the CompilationUnit with a CodeSource for controlling security stuff and a class loader for loading classes.
`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.

Method Summary
`void` | `addClassNode(ClassNode node)` Adds a ClassNode directly to the unit (ie. without source).
`void` | `addNewPhaseOperation(SourceUnitOperation op, int phase)`
`void` | `addPhaseOperation(SourceUnitOperation op, int phase)`
`void` | `addPhaseOperation(PrimaryClassNodeOperation op, int phase)`
`void` | `addPhaseOperation(GroovyClassOperation op)`
`SourceUnit` | `addSource(File file)` Adds a source file to the unit.
`SourceUnit` | `addSource(URL url)` Adds a source file to the unit.
`SourceUnit` | `addSource(String name, InputStream stream)` Adds a InputStream source to the unit.
`SourceUnit` | `addSource(String name, String scriptText)`
`SourceUnit` | `addSource(SourceUnit source)` Adds a SourceUnit to the unit.
`void` | `addSources(String[] paths)` Adds a set of file paths to the unit.
`void` | `addSources(File[] files)` Adds a set of source files to the unit.
`void` | `applyToGeneratedGroovyClasses(GroovyClassOperation body)`
`void` | `applyToPrimaryClassNodes(PrimaryClassNodeOperation body)` A loop driver for applying operations to all primary ClassNodes in our AST.
`void` | `applyToSourceUnits(SourceUnitOperation body)` A loop driver for applying operations to all SourceUnits.
`void` | `compile()` Synonym for compile(Phases.ALL).
`void` | `compile(int throughPhase)` Compiles the compilation unit from sources.
`void` | `configure(CompilerConfiguration configuration)` Configures its debugging mode and classloader classpath from a given compiler configuration.
`protected ClassVisitor` | `createClassVisitor()`
`protected boolean` | `dequeued()` Dequeues any source units add through addSource and resets the compiler phase to initialization.
`CompileUnit` | `getAST()` Returns the CompileUnit that roots our AST.
`ClassNode` | `getClassNode(String name)` Convenience routine to get the named ClassNode.
`Map` | `getClassSourcesByPublicClassName()`
`List` | `getClasses()` Get the GroovyClasses generated by compile().
`ClassNode` | `getFirstClassNode()` Convenience routine to get the first ClassNode, for when you are sure there is only one.
`Map` | `getSummariesByPublicClassName()`
`Map` | `getSummariesBySourceName()` Get the source summaries
`GroovyClassLoader` | `getTransformLoader()` Returns the class loader for loading AST transformations.
`boolean` | `isPublicClass(String className)`
`Iterator` | `iterator()` Returns an iterator on the unit's SourceUnits.
`protected void` | `mark()` Updates the phase marker on all sources.
`void` | `setClassgenCallback(ClassgenCallback visitor)` Sets a ClassgenCallback.
`void` | `setProgressCallback(ProgressCallback callback)` Sets a ProgressCallback.

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

Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll

Field Detail

### ast

    protected CompileUnit ast

### classSourcesByPublicClassName

    protected Map classSourcesByPublicClassName

### classgenCallback

    protected ClassgenCallback classgenCallback

### configured

    protected boolean configured

### debug

    protected boolean debug

### generatedClasses

    protected List generatedClasses

### names

    protected List names

### newPhaseOperations

    LinkedList[] newPhaseOperations

### optimizer

    protected OptimizerVisitor optimizer

### phaseOperations

    LinkedList[] phaseOperations

### progressCallback

    protected ProgressCallback progressCallback

### queuedSources

    protected LinkedList queuedSources

### resolveVisitor

    protected ResolveVisitor resolveVisitor

### sources

    protected Map sources

### staticImportVisitor

    protected StaticImportVisitor staticImportVisitor

### summariesByPublicClassName

    protected Map summariesByPublicClassName

### summariesBySourceName

    protected Map summariesBySourceName

### verifier

    protected Verifier verifier

Constructor Detail

### CompilationUnit

    public CompilationUnit()

  Initializes the CompilationUnit with defaults.

### CompilationUnit

    public CompilationUnit(GroovyClassLoader loader)

  Initializes the CompilationUnit with defaults except for class loader.

### CompilationUnit

    public CompilationUnit(CompilerConfiguration configuration)

  Initializes the CompilationUnit with no security considerations.

### CompilationUnit

    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.

### CompilationUnit

    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.
  param:
    transformLoader - the loader for transforms
  param:
    loader - loader used to resolve classes against during compilation
  param:
    security - security setting for the compilation
  param:
    configuration - compilation configuration

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(SourceUnitOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(SourceUnitOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(PrimaryClassNodeOperation op, int phase)

### addPhaseOperation

    public void addPhaseOperation(GroovyClassOperation op)

### addSource

    public SourceUnit addSource(File file)

  Adds a source file to the unit.

### addSource

    public SourceUnit addSource(URL url)

  Adds a source file to the unit.

### addSource

    public SourceUnit addSource(String name, InputStream stream)

  Adds a InputStream source to the unit.

### addSource

    public SourceUnit addSource(String name, String scriptText)

### addSource

    public SourceUnit addSource(SourceUnit source)

  Adds a SourceUnit to the unit.

### addSources

    public void addSources(String[] paths)

  Adds a set of file paths to the unit.

### addSources

    public void addSources(File[] files)

  Adds a set of source files to the unit.

### applyToGeneratedGroovyClasses

    public void applyToGeneratedGroovyClasses(GroovyClassOperation body)

### applyToPrimaryClassNodes

    public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body)

  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.

### applyToSourceUnits

    public void applyToSourceUnits(SourceUnitOperation body)

  A loop driver for applying operations to all SourceUnits. Automatically skips units that have already been processed through the current phase.

### compile

    public void compile()

  Synonym for compile(Phases.ALL).

### compile

    public void compile(int throughPhase)

  Compiles the compilation unit from sources.

### configure

    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 URLClassLoader.

### createClassVisitor

    protected ClassVisitor createClassVisitor()

### dequeued

    protected boolean dequeued()

  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.
  return:
    true if there was a queued source
  throws:
    CompilationFailedException

### getAST

    public CompileUnit getAST()

  Returns the CompileUnit that roots our AST.

### getClassNode

    public ClassNode getClassNode(String name)

  Convenience routine to get the named ClassNode.

### getClassSourcesByPublicClassName

    public Map getClassSourcesByPublicClassName()

### getClasses

    public List getClasses()

  Get the GroovyClasses generated by compile().

### getFirstClassNode

    public ClassNode getFirstClassNode()

  Convenience routine to get the first ClassNode, for when you are sure there is only one.

### getSummariesByPublicClassName

    public Map getSummariesByPublicClassName()

### getSummariesBySourceName

    public Map getSummariesBySourceName()

  Get the source summaries

### getTransformLoader

    public GroovyClassLoader getTransformLoader()

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

### isPublicClass

    public boolean isPublicClass(String className)

### iterator

    public Iterator iterator()

  Returns an iterator on the unit's SourceUnits.

### mark

    protected void mark()

  Updates the phase marker on all sources.

### setClassgenCallback

    public void setClassgenCallback(ClassgenCallback visitor)

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

### setProgressCallback

    public void setProgressCallback(ProgressCallback callback)

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

Copyright © 2003-2009 The Codehaus. All rights reserved.