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.
Modifiers | Name | Description |
---|---|---|
interface |
CompilationUnit.ClassgenCallback |
A callback interface you can use to "accompany" the classgen() code as it traverses the ClassNode tree. |
static class |
CompilationUnit.GroovyClassOperation |
|
interface |
CompilationUnit.IGroovyClassOperation |
|
interface |
CompilationUnit.IPrimaryClassNodeOperation |
|
interface |
CompilationUnit.ISourceUnitOperation |
|
static class |
CompilationUnit.PrimaryClassNodeOperation |
|
interface |
CompilationUnit.ProgressCallback |
A callback interface you can use to get a callback after every unit of the compile process. |
static class |
CompilationUnit.SourceUnitOperation |
Modifiers | Name | Description |
---|---|---|
protected CompileUnit |
ast |
|
protected ASTTransformationsContext |
astTransformationsContext |
The AST transformations state data. |
protected ClassNodeResolver |
classNodeResolver |
|
protected CompilationUnit.ClassgenCallback |
classgenCallback |
A callback for use during classgen |
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. |
Fields inherited from class | Fields |
---|---|
class ProcessingUnit |
classLoader, configuration, errorCollector, phase, phaseComplete |
Constructor and description |
---|
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 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. |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
addClassNode(ClassNode node) Adds a ClassNode directly to the unit (ie. without source). |
|
void |
addFirstPhaseOperation(IPrimaryClassNodeOperation op, int phase) |
|
void |
addFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) |
|
void |
addJavaCompilationUnits(Set<JavaFileObject> javaCompilationUnitSet) |
|
void |
addNewPhaseOperation(ISourceUnitOperation op, int phase) |
|
void |
addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) |
|
void |
addPhaseOperation(IGroovyClassOperation op) |
|
void |
addPhaseOperation(ISourceUnitOperation op, int phase) |
|
void |
addPhaseOperation(IPrimaryClassNodeOperation op, int phase) |
|
void |
addPhaseOperation(CompilationUnit.GroovyClassOperation op) |
|
void |
addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) |
|
void |
addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) |
|
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 |
applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation op) |
|
void |
applyToSourceUnits(CompilationUnit.SourceUnitOperation op) |
|
void |
call(SourceUnit source, GeneratorContext context, ClassNode classNode) |
|
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()
|
|
ClassNode |
getClassNode(String name) Convenience routine to get the named ClassNode. |
|
ClassNodeResolver |
getClassNodeResolver() |
|
List<GroovyClass> |
getClasses() Get the GroovyClasses generated by compile(). |
|
CompilationUnit.ClassgenCallback |
getClassgenCallback() |
|
protected String |
getCommonSuperClass(String arg1, String arg2) |
|
ClassNode |
getFirstClassNode() Convenience routine to get the first ClassNode, for when you are sure there is only one. |
|
Set<JavaFileObject> |
getJavaCompilationUnitSet() |
|
CompilationUnit.ProgressCallback |
getProgressCallback() |
|
protected SourceUnit |
getSourceUnit() |
|
protected SourceUnit |
getSourceUnit() |
|
GroovyClassLoader |
getTransformLoader()
|
|
boolean |
hasNext() |
|
Iterator<SourceUnit> |
iterator() Returns an iterator on the unit's SourceUnits. |
|
protected void |
mark() Updates the phase marker on all sources. |
|
boolean |
needSortedInput() |
|
SourceUnit |
next() |
|
void |
remove() |
|
void |
setClassNodeResolver(ClassNodeResolver classNodeResolver) |
|
void |
setClassgenCallback(CompilationUnit.ClassgenCallback visitor) Sets a ClassgenCallback. |
|
void |
setProgressCallback(CompilationUnit.ProgressCallback callback) Sets a ProgressCallback. |
|
Expression |
transform(Expression expression) |
Methods inherited from class | Name |
---|---|
class ProcessingUnit |
completePhase, configure, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration |
The AST transformations state data.
A callback for use during classgen
True after the first configure(CompilerConfiguration) operation.
Controls behavior of classgen and other routines.
A callback for use during compile()
The source units from which this unit is built.
Initializes the CompilationUnit with defaults.
Initializes the CompilationUnit with defaults except for class loader.
Initializes the CompilationUnit with no security considerations.
Initializes the CompilationUnit with a CodeSource for controlling security stuff and a class loader for loading classes.
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 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 configurationAdds 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
Adds a source file to the unit.
Adds a source file to the unit.
Adds a InputStream source to the unit.
Adds a SourceUnit to the unit.
Adds a set of file paths to the unit.
Adds a set of source files to the unit.
Synonym for compile(Phases.ALL)
.
Compiles the compilation unit from sources.
Configures its debugging mode and classloader classpath from a given compiler configuration. This cannot be done more than once due to limitations in URLClassLoader.
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 SourceUnit has already passed a phase it is skipped until a higher phase is reached.
Returns the CompileUnit that roots our AST.
Get the GroovyClasses generated by compile().
Convenience routine to get the first ClassNode, for when you are sure there is only one.
Returns an iterator on the unit's SourceUnits.
Updates the phase marker on all sources.
Sets a ClassgenCallback. You can have only one, and setting
it to null
removes any existing setting.
Sets a ProgressCallback. You can have only one, and setting
it to null
removes any existing setting.
Copyright © 2003-2020 The Apache Software Foundation. All rights reserved.