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
 
 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. 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceCompilationUnit.ClassgenCallbackA callback interface you can use to "accompany" the classgen() code as it traverses the ClassNode tree.static classCompilationUnit.GroovyClassOperationDeprecated.static interfaceCompilationUnit.IGroovyClassOperationstatic interfaceCompilationUnit.IPrimaryClassNodeOperationstatic interfaceCompilationUnit.ISourceUnitOperationstatic classCompilationUnit.PrimaryClassNodeOperationDeprecated.static interfaceCompilationUnit.ProgressCallbackA callback interface you can use to get a callback after every unit of the compile process.static classCompilationUnit.SourceUnitOperationDeprecated.
 - 
Field SummaryFields Modifier and Type Field Description protected CompileUnitastThe overall AST for this CompilationUnit.protected ASTTransformationsContextastTransformationsContextThe AST transformations state data.protected CompilationUnit.ClassgenCallbackclassgenCallbackA callback for use duringclassgenprotected ClassNodeResolverclassNodeResolverprotected booleanconfiguredTrue after the firstconfigure(CompilerConfiguration)operation.protected booleandebugControls behavior ofclassgenand other routines.protected CompilationUnit.ProgressCallbackprogressCallbackA callback for use duringcompile()protected Queue<SourceUnit>queuedSourcesprotected ResolveVisitorresolveVisitorprotected Map<String,SourceUnit>sourcesThe source units from which this unit is built.- 
Fields inherited from class org.codehaus.groovy.control.ProcessingUnitclassLoader, configuration, errorCollector, phase, phaseComplete
 
- 
 - 
Constructor SummaryConstructors Constructor 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.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddClassNode(ClassNode node)Adds a ClassNode directly to the unit (ie.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.voidaddPhaseOperation(CompilationUnit.GroovyClassOperation op)Deprecated.voidaddPhaseOperation(CompilationUnit.IGroovyClassOperation op)voidaddPhaseOperation(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.SourceUnitaddSource(File file)Adds a source file to the unit.SourceUnitaddSource(String name, InputStream stream)Adds a InputStream source to the unit.SourceUnitaddSource(String name, String scriptText)SourceUnitaddSource(URL url)Adds a source file to the unit.SourceUnitaddSource(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.voidapplyToPrimaryClassNodes(CompilationUnit.PrimaryClassNodeOperation op)Deprecated.voidapplyToSourceUnits(CompilationUnit.SourceUnitOperation op)Deprecated.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.ClassVisitorcreateClassVisitor()protected booleandequeued()Dequeues any source units add through addSource and resets the compiler phase to initialization.CompileUnitgetAST()Returns the CompileUnit that roots our AST.ASTTransformationsContextgetASTTransformationsContext()List<GroovyClass>getClasses()Get the GroovyClasses generated by compile().CompilationUnit.ClassgenCallbackgetClassgenCallback()ClassNodegetClassNode(String name)Convenience routine to get the named ClassNode.ClassNodeResolvergetClassNodeResolver()ClassNodegetFirstClassNode()Convenience routine to get the first ClassNode, for when you are sure there is only one.Set<JavaFileObject>getJavaCompilationUnitSet()CompilationUnit.ProgressCallbackgetProgressCallback()GroovyClassLoadergetTransformLoader()Returns the class loader for loading AST transformations.Iterator<SourceUnit>iterator()Returns an iterator on the unit's SourceUnits.protected voidmark()Updates the phase marker on all sources.voidsetClassgenCallback(CompilationUnit.ClassgenCallback visitor)Sets a ClassgenCallback.voidsetClassNodeResolver(ClassNodeResolver classNodeResolver)voidsetProgressCallback(CompilationUnit.ProgressCallback callback)Sets a ProgressCallback.- 
Methods inherited from class org.codehaus.groovy.control.ProcessingUnitcompletePhase, getClassLoader, getConfiguration, getErrorCollector, getPhase, getPhaseDescription, gotoPhase, isPhaseComplete, nextPhase, setClassLoader, setConfiguration
 
- 
 
- 
- 
- 
Field Detail- 
astprotected CompileUnit ast The overall AST for this CompilationUnit.
 - 
sourcesprotected Map<String,SourceUnit> sources The source units from which this unit is built.
 - 
queuedSourcesprotected Queue<SourceUnit> queuedSources 
 - 
debugprotected boolean debug Controls behavior ofclassgenand other routines.
 - 
configuredprotected boolean configured True after the firstconfigure(CompilerConfiguration)operation.
 - 
classgenCallbackprotected CompilationUnit.ClassgenCallback classgenCallback A callback for use duringclassgen
 - 
progressCallbackprotected CompilationUnit.ProgressCallback progressCallback A callback for use duringcompile()
 - 
classNodeResolverprotected ClassNodeResolver classNodeResolver 
 - 
resolveVisitorprotected ResolveVisitor resolveVisitor 
 - 
astTransformationsContextprotected ASTTransformationsContext astTransformationsContext The AST transformations state data.
 
- 
 - 
Constructor Detail- 
CompilationUnitpublic CompilationUnit() Initializes the CompilationUnit with defaults.
 - 
CompilationUnitpublic CompilationUnit(GroovyClassLoader loader) Initializes the CompilationUnit with defaults except for class loader.
 - 
CompilationUnitpublic CompilationUnit(CompilerConfiguration configuration) Initializes 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 Detail- 
addPhaseOperationpublic void addPhaseOperation(CompilationUnit.IGroovyClassOperation op) 
 - 
addPhaseOperationpublic void addPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase) 
 - 
addPhaseOperationpublic void addPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase) 
 - 
addFirstPhaseOperationpublic void addFirstPhaseOperation(CompilationUnit.IPrimaryClassNodeOperation op, int phase) 
 - 
addNewPhaseOperationpublic void addNewPhaseOperation(CompilationUnit.ISourceUnitOperation op, int phase) 
 - 
configurepublic void configure(CompilerConfiguration configuration) Configures 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
 
 - 
getASTpublic CompileUnit getAST() Returns the CompileUnit that roots our AST.
 - 
getClassespublic List<GroovyClass> getClasses() Get the GroovyClasses generated by compile().
 - 
getFirstClassNodepublic ClassNode getFirstClassNode() Convenience routine to get the first ClassNode, for when you are sure there is only one.
 - 
getClassNodepublic ClassNode getClassNode(String name) Convenience routine to get the named ClassNode.
 - 
getASTTransformationsContextpublic ASTTransformationsContext getASTTransformationsContext() - Returns:
- the AST transformations current context
 
 - 
getClassNodeResolverpublic ClassNodeResolver getClassNodeResolver() 
 - 
setClassNodeResolverpublic void setClassNodeResolver(ClassNodeResolver classNodeResolver) 
 - 
getJavaCompilationUnitSetpublic Set<JavaFileObject> getJavaCompilationUnitSet() 
 - 
addJavaCompilationUnitspublic void addJavaCompilationUnits(Set<JavaFileObject> javaCompilationUnitSet) 
 - 
getTransformLoaderpublic GroovyClassLoader getTransformLoader() Returns the class loader for loading AST transformations.
 - 
addSourcespublic void addSources(String[] paths) Adds a set of file paths to the unit.
 - 
addSourcespublic void addSources(File[] files) Adds a set of source files to the unit.
 - 
addSourcepublic SourceUnit addSource(File file) Adds a source file to the unit.
 - 
addSourcepublic SourceUnit addSource(URL url) Adds a source file to the unit.
 - 
addSourcepublic SourceUnit addSource(String name, InputStream stream) Adds a InputStream source to the unit.
 - 
addSourcepublic SourceUnit addSource(String name, String scriptText) 
 - 
addSourcepublic SourceUnit addSource(SourceUnit source) Adds a SourceUnit to the unit.
 - 
iteratorpublic Iterator<SourceUnit> iterator() Returns an iterator on the unit's SourceUnits.
 - 
addClassNodepublic 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
 - 
getClassgenCallbackpublic CompilationUnit.ClassgenCallback getClassgenCallback() 
 - 
setClassgenCallbackpublic void setClassgenCallback(CompilationUnit.ClassgenCallback visitor) Sets a ClassgenCallback. You can have only one, and setting it tonullremoves any existing setting.
 - 
getProgressCallbackpublic CompilationUnit.ProgressCallback getProgressCallback() 
 - 
setProgressCallbackpublic void setProgressCallback(CompilationUnit.ProgressCallback callback) Sets a ProgressCallback. You can have only one, and setting it tonullremoves any existing setting.
 - 
compilepublic void compile() throws CompilationFailedExceptionSynonym forcompile(Phases.ALL).- Throws:
- CompilationFailedException
 
 - 
compilepublic void compile(int throughPhase) throws CompilationFailedExceptionCompiles the compilation unit from sources.- Throws:
- CompilationFailedException
 
 - 
dequeuedprotected boolean dequeued() throws CompilationFailedExceptionDequeues 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:
- true if there was a queued source
- Throws:
- CompilationFailedException
 
 - 
createClassVisitorprotected org.objectweb.asm.ClassVisitor createClassVisitor() 
 - 
markprotected void mark() throws CompilationFailedExceptionUpdates the phase marker on all sources.- Throws:
- CompilationFailedException
 
 - 
addPhaseOperation@Deprecated public void addPhaseOperation(CompilationUnit.GroovyClassOperation op) Deprecated.
 - 
addPhaseOperation@Deprecated public void addPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) Deprecated.
 - 
addPhaseOperation@Deprecated public void addPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) Deprecated.
 - 
addFirstPhaseOperation@Deprecated public void addFirstPhaseOperation(CompilationUnit.PrimaryClassNodeOperation op, int phase) Deprecated.
 - 
addNewPhaseOperation@Deprecated public void addNewPhaseOperation(CompilationUnit.SourceUnitOperation op, int phase) Deprecated.
 - 
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
 
 
- 
 
-