public class CompilationUnit extends ProcessingUnit
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.
Modifier and Type | Class and Description |
---|---|
static interface |
CompilationUnit.ClassgenCallback
A callback interface you can use to "accompany" the classgen()
code as it traverses the ClassNode tree.
|
static class |
CompilationUnit.GroovyClassOperation
Deprecated.
|
static interface |
CompilationUnit.IGroovyClassOperation |
static interface |
CompilationUnit.IPrimaryClassNodeOperation |
static interface |
CompilationUnit.ISourceUnitOperation |
static class |
CompilationUnit.PrimaryClassNodeOperation
Deprecated.
|
static interface |
CompilationUnit.ProgressCallback
A callback interface you can use to get a callback after every
unit of the compile process.
|
static class |
CompilationUnit.SourceUnitOperation
Deprecated.
|
Modifier and Type | Field and Description |
---|---|
protected CompileUnit |
ast
The overall AST for this CompilationUnit.
|
protected ASTTransformationsContext |
astTransformationsContext
The AST transformations state data.
|
protected CompilationUnit.ClassgenCallback |
classgenCallback
A callback for use during
classgen |
protected ClassNodeResolver |
classNodeResolver |
protected boolean |
configured
True after the first
configure(CompilerConfiguration) operation. |
protected boolean |
debug
Controls behavior of
classgen and other routines. |
protected CompilationUnit.ProgressCallback |
progressCallback
A callback for use during
compile() |
protected Queue<SourceUnit> |
queuedSources |
protected ResolveVisitor |
resolveVisitor |
protected Map<String,SourceUnit> |
sources
The source units from which this unit is built.
|
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,
CodeSource codeSource,
GroovyClassLoader loader)
Initializes the CompilationUnit with a CodeSource for controlling
security stuff and a class loader for loading classes.
|
CompilationUnit(CompilerConfiguration configuration,
CodeSource codeSource,
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.
|
void |
addFirstPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op,
int phase) |
void |
addFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op,
int phase)
Deprecated.
|
void |
addJavaCompilationUnits(Set<JavaFileObject> javaCompilationUnitSet) |
void |
addNewPhaseOperation(CompilationUnit.ISourceUnitOperation op,
int phase) |
void |
addNewPhaseOperation(CompilationUnit.SourceUnitOperation op,
int phase)
Deprecated.
|
void |
addPhaseOperation(CompilationUnit.GroovyClassOperation op)
Deprecated.
|
void |
addPhaseOperation(CompilationUnit.IGroovyClassOperation op) |
void |
addPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op,
int phase) |
void |
addPhaseOperation(CompilationUnit.ISourceUnitOperation op,
int phase) |
void |
addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op,
int phase)
Deprecated.
|
void |
addPhaseOperation(CompilationUnit.SourceUnitOperation op,
int phase)
Deprecated.
|
SourceUnit |
addSource(File file)
Adds a source file to the unit.
|
SourceUnit |
addSource(SourceUnit source)
Adds a SourceUnit to the unit.
|
SourceUnit |
addSource(String name,
InputStream stream)
Adds a InputStream source to the unit.
|
SourceUnit |
addSource(String name,
String scriptText) |
SourceUnit |
addSource(URL url)
Adds a source file to the unit.
|
void |
addSources(File[] files)
Adds a set of source files to the unit.
|
void |
addSources(String[] paths)
Adds a set of file paths to the unit.
|
void |
applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation op)
Deprecated.
|
void |
applyToSourceUnits(CompilationUnit.SourceUnitOperation op)
Deprecated.
|
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() |
List<GroovyClass> |
getClasses()
Get the GroovyClasses generated by compile().
|
CompilationUnit.ClassgenCallback |
getClassgenCallback() |
ClassNode |
getClassNode(String name)
Convenience routine to get the named ClassNode.
|
ClassNodeResolver |
getClassNodeResolver() |
ClassNode |
getFirstClassNode()
Convenience routine to get the first ClassNode, for
when you are sure there is only one.
|
Set<JavaFileObject> |
getJavaCompilationUnitSet() |
CompilationUnit.ProgressCallback |
getProgressCallback() |
GroovyClassLoader |
getTransformLoader() |
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 |
setClassNodeResolver(ClassNodeResolver classNodeResolver) |
void |
setProgressCallback(CompilationUnit.ProgressCallback callback)
Sets a ProgressCallback.
|
completePhase, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration
protected CompileUnit ast
protected Map<String,SourceUnit> sources
protected Queue<SourceUnit> queuedSources
protected boolean debug
classgen
and other routines.protected boolean configured
configure(CompilerConfiguration)
operation.protected CompilationUnit.ClassgenCallback classgenCallback
classgen
protected CompilationUnit.ProgressCallback progressCallback
compile()
protected ClassNodeResolver classNodeResolver
protected ResolveVisitor resolveVisitor
protected ASTTransformationsContext astTransformationsContext
public CompilationUnit()
public CompilationUnit(GroovyClassLoader loader)
public CompilationUnit(CompilerConfiguration configuration)
public CompilationUnit(CompilerConfiguration configuration, CodeSource codeSource, GroovyClassLoader loader)
public CompilationUnit(CompilerConfiguration configuration, CodeSource codeSource, GroovyClassLoader loader, GroovyClassLoader transformLoader)
Note: The transform loader must be able to load compiler classes.
That means ProcessingUnit.classLoader
must be at last a parent to transformLoader
.
The other loader has no such constraint.
transformLoader
- - the loader for transformsloader
- - loader used to resolve classes against during compilationcodeSource
- - security setting for the compilationconfiguration
- - compilation configurationpublic void addPhaseOperation(CompilationUnit.IGroovyClassOperation op)
public void addPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase)
public void addPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase)
public void addFirstPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase)
public void addNewPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase)
public void configure(CompilerConfiguration configuration)
URLClassLoader
.configure
in class ProcessingUnit
public CompileUnit getAST()
public List<GroovyClass> getClasses()
public ClassNode getFirstClassNode()
public ClassNode getClassNode(String name)
public ASTTransformationsContext getASTTransformationsContext()
public ClassNodeResolver getClassNodeResolver()
public void setClassNodeResolver(ClassNodeResolver classNodeResolver)
public Set<JavaFileObject> getJavaCompilationUnitSet()
public void addJavaCompilationUnits(Set<JavaFileObject> javaCompilationUnitSet)
public GroovyClassLoader getTransformLoader()
public void addSources(String[] paths)
public void addSources(File[] files)
public SourceUnit addSource(File file)
public SourceUnit addSource(URL url)
public SourceUnit addSource(String name, InputStream stream)
public SourceUnit addSource(String name, String scriptText)
public SourceUnit addSource(SourceUnit source)
public Iterator<SourceUnit> iterator()
public void addClassNode(ClassNode node)
public CompilationUnit.ClassgenCallback getClassgenCallback()
public void setClassgenCallback(CompilationUnit.ClassgenCallback visitor)
null
removes any existing setting.public CompilationUnit.ProgressCallback getProgressCallback()
public void setProgressCallback(CompilationUnit.ProgressCallback callback)
null
removes any existing setting.public void compile() throws CompilationFailedException
compile(Phases.ALL)
.CompilationFailedException
public void compile(int throughPhase) throws CompilationFailedException
CompilationFailedException
protected boolean dequeued() throws CompilationFailedException
Note: this does not mean a file is recompiled. If a SourceUnit has already passed a phase it is skipped until a higher phase is reached.
CompilationFailedException
protected org.objectweb.asm.ClassVisitor createClassVisitor()
protected void mark() throws CompilationFailedException
CompilationFailedException
@Deprecated public void addPhaseOperation(CompilationUnit.GroovyClassOperation op)
@Deprecated public void addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)
@Deprecated public void addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase)
@Deprecated public void addFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase)
@Deprecated public void addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase)
@Deprecated public void applyToSourceUnits(CompilationUnit.SourceUnitOperation op) throws CompilationFailedException
CompilationFailedException
@Deprecated public void applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation op) throws CompilationFailedException
CompilationFailedException