Groovy 2.2.1

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


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 Map classSourcesByPublicClassName

protected CompilationUnit.ClassgenCallback classgenCallback

Initializes the CompilationUnit with defaults.

protected boolean configured

protected boolean debug

protected List generatedClasses

protected List names

protected OptimizerVisitor optimizer

protected CompilationUnit.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()

CompilationUnit(GroovyClassLoader loader)

CompilationUnit(CompilerConfiguration configuration)

CompilationUnit(CompilerConfiguration configuration, CodeSource security, GroovyClassLoader loader)

CompilationUnit(CompilerConfiguration configuration, 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(File file)

Adds a InputStream source to the unit.

SourceUnit addSource(URL url)

SourceUnit addSource(String name, InputStream stream)

SourceUnit addSource(String name, String scriptText)

SourceUnit addSource(SourceUnit source)

Returns an iterator on the unit's SourceUnits.

void addSources(String[] paths)

Adds a set of source files to the unit.

void addSources(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(String name)

ClassNodeResolver getClassNodeResolver()

Map getClassSourcesByPublicClassName()

List getClasses()

Convenience routine to get the named ClassNode.

CompilationUnit.ClassgenCallback getClassgenCallback()

ClassNode getFirstClassNode()

CompilationUnit.ProgressCallback getProgressCallback()

Map getSummariesByPublicClassName()

Get the GroovyClasses generated by compile().

Map getSummariesBySourceName()

GroovyClassLoader getTransformLoader()

Returns the class loader for loading AST transformations.

boolean isPublicClass(String className)

Iterator iterator()

protected void mark()

Marks a single SourceUnit with the current phase, if it isn't already there yet.

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 Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

ast

protected CompileUnit ast


astTransformationsContext

protected ASTTransformationsContext astTransformationsContext


classNodeResolver

protected ClassNodeResolver classNodeResolver


classSourcesByPublicClassName

protected Map classSourcesByPublicClassName


classgenCallback

protected CompilationUnit.ClassgenCallback classgenCallback
Initializes the CompilationUnit with defaults.


configured

protected boolean configured


debug

protected boolean debug


generatedClasses

protected List generatedClasses


names

protected List names


optimizer

protected OptimizerVisitor optimizer


progressCallback

protected CompilationUnit.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()


CompilationUnit

public CompilationUnit(GroovyClassLoader loader)


CompilationUnit

public CompilationUnit(CompilerConfiguration configuration)


CompilationUnit

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


CompilationUnit

public CompilationUnit(CompilerConfiguration configuration, 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(File file)
Adds a InputStream source to the unit.


addSource

public SourceUnit addSource(URL url)


addSource

public SourceUnit addSource(String name, InputStream stream)


addSource

public SourceUnit addSource(String name, String scriptText)


addSource

public SourceUnit addSource(SourceUnit source)
Returns an iterator on the unit's SourceUnits.


addSources

public void addSources(String[] paths)
Adds a set of source files to the unit.


addSources

public void addSources(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(String name)


getClassNodeResolver

public ClassNodeResolver getClassNodeResolver()


getClassSourcesByPublicClassName

public Map getClassSourcesByPublicClassName()


getClasses

public 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 Map getSummariesByPublicClassName()
Get the GroovyClasses generated by compile().


getSummariesBySourceName

public Map getSummariesBySourceName()


getTransformLoader

public GroovyClassLoader getTransformLoader()
Returns the class loader for loading AST transformations.
Returns:
- the transform class loader


isPublicClass

public boolean isPublicClass(String className)


iterator

public Iterator iterator()


mark

protected void mark()
Marks a single SourceUnit with the current phase, if it isn't already there yet.


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


 

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