Package org.codehaus.groovy.control
Class CompilationUnit
java.lang.Object
org.codehaus.groovy.control.ProcessingUnit
org.codehaus.groovy.control.CompilationUnit
- Direct Known Subclasses:
- JavaAwareCompilationUnit,- JavaStubCompilationUnit
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.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceA callback interface you can use during theclassgenphase of compilation as the compiler traverses the ClassNode tree.static classDeprecated.static interfacestatic interfacestatic interfacestatic classDeprecated.static interfaceA callback interface you can use to get a callback after every unit of the compile process.static classDeprecated.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected CompileUnitThe overall AST for this CompilationUnit.protected ASTTransformationsContextThe AST transformations state data.protected CompilationUnit.ClassgenCallbackA callback called during theclassgenphase of compilationprotected ClassNodeResolverprotected booleanTrue after the firstconfigure(CompilerConfiguration)operation.protected booleanIf set, outputs a little more information during compilation when errors occur.protected CompilationUnit.ProgressCallbackA callback for use duringcompile()protected Queue<SourceUnit>protected ResolveVisitorprotected Map<String,SourceUnit> The source units from which this unit is built.Fields inherited from class org.codehaus.groovy.control.ProcessingUnitclassLoader, configuration, errorCollector, phase, phaseComplete
- 
Constructor SummaryConstructorsConstructorDescriptionInitializes 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.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddClassNode(ClassNode node) Adds a ClassNode directly to the unit (i.e.voidaddFirstPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase) voidaddFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) Deprecated.voidaddJavaCompilationUnits(Set<JavaFileObject> javaCompilationUnitSet) voidaddNewPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase) voidaddNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) Deprecated.voidDeprecated.voidvoidaddPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase) voidaddPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase) voidaddPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) Deprecated.voidaddPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) Deprecated.Adds a source file to the unit.addSource(String name, InputStream stream) Adds a InputStream source to the unit.Adds a source file to the unit.addSource(SourceUnit source) Adds a SourceUnit to the unit.voidaddSources(File[] files) Adds a set of source files to the unit.voidaddSources(String[] paths) Adds a set of file paths to the unit.voidDeprecated.voidDeprecated.voidcompile()Synonym forcompile(Phases.ALL).voidcompile(int throughPhase) Compiles the compilation unit from sources.voidconfigure(CompilerConfiguration configuration) Configures its debugging mode and classloader classpath from a given compiler configuration.protected org.objectweb.asm.ClassVisitorprotected booleandequeued()Dequeues any source units added through addSource and resets the compiler phase to initialization.getAST()Returns the CompileUnit that roots our AST.Get the GroovyClasses generated by compile().getClassNode(String name) Convenience routine to get the named ClassNode.Convenience routine to get the first ClassNode, for when you are sure there is only one.Returns the class loader for loading AST transformations.iterator()Returns an iterator on the unit's SourceUnits.protected voidmark()Updates the phase marker on all sources.voidSets a ClassgenCallback.voidsetClassNodeResolver(ClassNodeResolver classNodeResolver) voidSets a ProgressCallback.Methods inherited from class org.codehaus.groovy.control.ProcessingUnitcompletePhase, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration
- 
Field Details- 
astThe overall AST for this CompilationUnit.
- 
sourcesThe source units from which this unit is built.
- 
queuedSources
- 
debugprotected boolean debugIf set, outputs a little more information during compilation when errors occur.
- 
configuredprotected boolean configuredTrue after the firstconfigure(CompilerConfiguration)operation.
- 
classgenCallbackA callback called during theclassgenphase of compilation
- 
progressCallbackA callback for use duringcompile()
- 
classNodeResolver
- 
resolveVisitor
- 
astTransformationsContextThe AST transformations state data.
 
- 
- 
Constructor Details- 
CompilationUnitpublic CompilationUnit()Initializes the CompilationUnit with defaults.
- 
CompilationUnitInitializes the CompilationUnit with defaults except for class loader.
- 
CompilationUnitInitializes the CompilationUnit with no security considerations.
- 
CompilationUnitpublic CompilationUnit(CompilerConfiguration configuration, CodeSource codeSource, GroovyClassLoader loader) Initializes the CompilationUnit with a CodeSource for controlling security stuff and a class loader for loading classes.
- 
CompilationUnitpublic 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.Note: The transform loader must be able to load compiler classes. That means ProcessingUnit.classLoadermust be at last a parent totransformLoader. The other loader has no such constraint.- Parameters:
- transformLoader- - the loader for transforms
- loader- - loader used to resolve classes against during compilation
- codeSource- - security setting for the compilation
- configuration- - compilation configuration
 
 
- 
- 
Method Details- 
addPhaseOperation
- 
addPhaseOperation
- 
addPhaseOperation
- 
addFirstPhaseOperation
- 
addNewPhaseOperation
- 
configureConfigures its debugging mode and classloader classpath from a given compiler configuration. This cannot be done more than once due to limitations inURLClassLoader.- Overrides:
- configurein class- ProcessingUnit
 
- 
getASTReturns the CompileUnit that roots our AST.
- 
getClassesGet the GroovyClasses generated by compile().
- 
getFirstClassNodeConvenience routine to get the first ClassNode, for when you are sure there is only one.
- 
getClassNodeConvenience routine to get the named ClassNode.
- 
getASTTransformationsContext- Returns:
- the AST transformations current context
 
- 
getClassNodeResolver
- 
setClassNodeResolver
- 
getJavaCompilationUnitSet
- 
addJavaCompilationUnits
- 
getTransformLoaderReturns the class loader for loading AST transformations.
- 
addSourcesAdds a set of file paths to the unit.
- 
addSourcesAdds a set of source files to the unit.
- 
addSourceAdds a source file to the unit.
- 
addSourceAdds a source file to the unit.
- 
addSourceAdds a InputStream source to the unit.
- 
addSource
- 
addSourceAdds a SourceUnit to the unit.
- 
iteratorReturns an iterator on the unit's SourceUnits.
- 
addClassNodeAdds a ClassNode directly to the unit (i.e. without source). WARNING: the source is needed for error reporting, using this method without setting a SourceUnit will cause NullPointerExceptions
- 
getClassgenCallback
- 
setClassgenCallbackSets a ClassgenCallback. You can have only one, and setting it tonullremoves any existing setting.
- 
getProgressCallback
- 
setProgressCallbackSets a ProgressCallback. You can have only one, and setting it tonullremoves any existing setting.
- 
compileSynonym forcompile(Phases.ALL).- Throws:
- CompilationFailedException
 
- 
compileCompiles the compilation unit from sources.- Throws:
- CompilationFailedException
 
- 
dequeuedDequeues any source units added 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:
- true if there was a queued source
- Throws:
- CompilationFailedException
 
- 
createClassVisitorprotected org.objectweb.asm.ClassVisitor createClassVisitor()
- 
markUpdates the phase marker on all sources.- Throws:
- CompilationFailedException
 
- 
addPhaseOperationDeprecated.
- 
addPhaseOperationDeprecated.
- 
addPhaseOperationDeprecated.
- 
addFirstPhaseOperation@Deprecated public void addFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) Deprecated.
- 
addNewPhaseOperationDeprecated.
- 
applyToSourceUnits@Deprecated public void applyToSourceUnits(CompilationUnit.SourceUnitOperation op) throws CompilationFailedException Deprecated.- Throws:
- CompilationFailedException
 
- 
applyToPrimaryClassNodes@Deprecated public void applyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation op) throws CompilationFailedException Deprecated.- Throws:
- CompilationFailedException
 
 
-