public class CompilationUnit extends ProcessingUnit
Modifier and Type | Class and Description |
---|---|
static class |
CompilationUnit.ClassgenCallback
A callback interface you can use to "accompany" the classgen()
code as it traverses the ClassNode tree.
|
static class |
CompilationUnit.GroovyClassOperation |
static class |
CompilationUnit.PrimaryClassNodeOperation
An callback interface for use in the applyToSourceUnits loop driver.
|
static class |
CompilationUnit.ProgressCallback
A callback interface you can use to get a callback after every
unit of the compile process.
|
static class |
CompilationUnit.SourceUnitOperation
An callback interface for use in the applyToSourceUnits loop driver.
|
Modifier and Type | Field and Description |
---|---|
protected CompileUnit |
ast |
protected ASTTransformationsContext |
astTransformationsContext |
protected CompilationUnit.ClassgenCallback |
classgenCallback |
protected java.util.Map |
classSourcesByPublicClassName |
protected boolean |
configured |
protected boolean |
debug |
protected java.util.List<GroovyClass> |
generatedClasses |
protected java.util.List<java.lang.String> |
names |
protected OptimizerVisitor |
optimizer |
protected CompilationUnit.ProgressCallback |
progressCallback |
protected java.util.LinkedList<SourceUnit> |
queuedSources |
protected ResolveVisitor |
resolveVisitor |
protected java.util.Map<java.lang.String,SourceUnit> |
sources |
protected StaticImportVisitor |
staticImportVisitor |
protected java.util.Map |
summariesByPublicClassName |
protected java.util.Map |
summariesBySourceName |
protected Verifier |
verifier |
classLoader, configuration, errorCollector, phase, phaseComplete
Constructor and Description |
---|
CompilationUnit()
Initializes the CompilationUnit with defaults.
|
CompilationUnit(CompilerConfiguration configuration)
Initializes the CompilationUnit with no security considerations.
|
CompilationUnit(CompilerConfiguration configuration,
java.security.CodeSource security,
GroovyClassLoader loader)
Initializes the CompilationUnit with a CodeSource for controlling
security stuff and a class loader for loading classes.
|
CompilationUnit(CompilerConfiguration configuration,
java.security.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.
|
CompilationUnit(GroovyClassLoader loader)
Initializes the CompilationUnit with defaults except for class loader.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassNode(ClassNode node)
Adds a ClassNode directly to the unit (ie. without source).
|
void |
addNewPhaseOperation(CompilationUnit.SourceUnitOperation op,
int phase) |
void |
addPhaseOperation(CompilationUnit.GroovyClassOperation op) |
void |
addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op,
int phase) |
void |
addPhaseOperation(CompilationUnit.SourceUnitOperation op,
int phase) |
SourceUnit |
addSource(java.io.File file)
Adds a source file to the unit.
|
SourceUnit |
addSource(SourceUnit source)
Adds a SourceUnit to the unit.
|
SourceUnit |
addSource(java.lang.String name,
java.io.InputStream stream)
Adds a InputStream source to the unit.
|
SourceUnit |
addSource(java.lang.String name,
java.lang.String scriptText) |
SourceUnit |
addSource(java.net.URL url)
Adds a source file to the unit.
|
void |
addSources(java.io.File[] files)
Adds a set of source files to the unit.
|
void |
addSources(java.lang.String[] paths)
Adds a set of file paths to the unit.
|
void |
applyToGeneratedGroovyClasses(CompilationUnit.GroovyClassOperation body) |
void |
applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation body)
A loop driver for applying operations to all primary ClassNodes in
our AST.
|
void |
applyToSourceUnits(CompilationUnit.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 org.objectweb.asm.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.
|
ASTTransformationsContext |
getASTTransformationsContext() |
java.util.List |
getClasses()
Get the GroovyClasses generated by compile().
|
CompilationUnit.ClassgenCallback |
getClassgenCallback() |
ClassNode |
getClassNode(java.lang.String name)
Convenience routine to get the named ClassNode.
|
java.util.Map |
getClassSourcesByPublicClassName() |
ClassNode |
getFirstClassNode()
Convenience routine to get the first ClassNode, for
when you are sure there is only one.
|
CompilationUnit.ProgressCallback |
getProgressCallback() |
java.util.Map |
getSummariesByPublicClassName() |
java.util.Map |
getSummariesBySourceName()
Get the source summaries
|
GroovyClassLoader |
getTransformLoader()
Returns the class loader for loading AST transformations.
|
boolean |
isPublicClass(java.lang.String className) |
java.util.Iterator<SourceUnit> |
iterator()
Returns an iterator on the unit's SourceUnits.
|
protected void |
mark()
Updates the phase marker on all sources.
|
void |
setClassgenCallback(CompilationUnit.ClassgenCallback visitor)
Sets a ClassgenCallback.
|
void |
setProgressCallback(CompilationUnit.ProgressCallback callback)
Sets a ProgressCallback.
|
completePhase, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, nextPhase, setClassLoader, setConfiguration
protected ASTTransformationsContext astTransformationsContext
protected java.util.Map<java.lang.String,SourceUnit> sources
protected java.util.Map summariesBySourceName
protected java.util.Map summariesByPublicClassName
protected java.util.Map classSourcesByPublicClassName
protected java.util.List<java.lang.String> names
protected java.util.LinkedList<SourceUnit> queuedSources
protected CompileUnit ast
protected java.util.List<GroovyClass> 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
public CompilationUnit()
public CompilationUnit(GroovyClassLoader loader)
public CompilationUnit(CompilerConfiguration configuration)
public CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader)
public CompilationUnit(CompilerConfiguration configuration, java.security.CodeSource security, GroovyClassLoader loader, GroovyClassLoader transformLoader)
transformLoader
- - the loader for transformsloader
- - loader used to resolve classes against during compilationsecurity
- - security setting for the compilationconfiguration
- - compilation configurationpublic GroovyClassLoader getTransformLoader()
public void addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)
public void addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase)
public void addPhaseOperation(CompilationUnit.GroovyClassOperation op)
public void addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)
public void configure(CompilerConfiguration configuration)
URLClassLoader
.configure
in class ProcessingUnit
public CompileUnit getAST()
public java.util.Map getSummariesBySourceName()
public java.util.Map getSummariesByPublicClassName()
public java.util.Map getClassSourcesByPublicClassName()
public boolean isPublicClass(java.lang.String className)
public java.util.List getClasses()
public ClassNode getFirstClassNode()
public ClassNode getClassNode(java.lang.String name)
public ASTTransformationsContext getASTTransformationsContext()
public void addSources(java.lang.String[] paths)
public void addSources(java.io.File[] files)
public SourceUnit addSource(java.io.File file)
public SourceUnit addSource(java.net.URL url)
public SourceUnit addSource(java.lang.String name, java.io.InputStream stream)
public SourceUnit addSource(java.lang.String name, java.lang.String scriptText)
public SourceUnit addSource(SourceUnit source)
public java.util.Iterator<SourceUnit> iterator()
public void addClassNode(ClassNode node)
public void setClassgenCallback(CompilationUnit.ClassgenCallback visitor)
public void setProgressCallback(CompilationUnit.ProgressCallback callback)
public CompilationUnit.ClassgenCallback getClassgenCallback()
public CompilationUnit.ProgressCallback getProgressCallback()
public void compile() throws CompilationFailedException
CompilationFailedException
public void compile(int throughPhase) throws CompilationFailedException
CompilationFailedException
protected boolean dequeued() throws CompilationFailedException
CompilationFailedException
protected org.objectweb.asm.ClassVisitor createClassVisitor()
protected void mark() throws CompilationFailedException
CompilationFailedException
public void applyToSourceUnits(CompilationUnit.SourceUnitOperation body) throws CompilationFailedException
CompilationFailedException
public void applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation body) throws CompilationFailedException
CompilationFailedException
public void applyToGeneratedGroovyClasses(CompilationUnit.GroovyClassOperation body) throws CompilationFailedException
CompilationFailedException