public interface SpoonModelBuilder
The Spoon model (see Factory
is built from input sources given as
files. Use build()
to create the Spoon model.
Once the model is built and stored in the factory, it
can be processed by using a instantiateAndProcess(List)
.
Create an instance of the default implementation of the Spoon compiler by
using Launcher.createCompiler()
. For example:
Modifier and Type | Interface and Description |
---|---|
static interface |
SpoonModelBuilder.InputType
The types of compilable elements
FILES - compiles the java files from the file system, which were registered by
addInputSource(File) and addTemplateSource(File)
CTTYPES - compiles virtual java files, which are dynamically generated from the all top level classes of the CtModel by DefaultJavaPrettyPrinter |
Modifier and Type | Method and Description |
---|---|
void |
addCompilationUnitFilter(CompilationUnitFilter filter)
Adds
filter . |
void |
addInputSource(File source)
Adds a file/directory to be built.
|
void |
addInputSource(SpoonResource source)
Adds a file/directory (as a
SpoonResource ) to be built. |
void |
addInputSources(List<SpoonResource> resources)
Adds a list of files/directories (as a
SpoonResource to be built. |
void |
addTemplateSource(File source)
Adds a file/directory to be used to build templates.
|
void |
addTemplateSource(SpoonResource source)
Adds a file/directory (as a
SpoonResource ) to be used to build templates. |
void |
addTemplateSources(List<SpoonResource> resources)
Adds a list of files/directories (as a CtResource) to be used to build templates.
|
boolean |
build()
Builds the program's model with this compiler's factory and stores the
result into this factory.
|
boolean |
build(JDTBuilder builder)
Builds the program's model with this compiler's factory and stores the
result into this factory.
|
boolean |
compile(SpoonModelBuilder.InputType... types)
Generates the bytecode associated to the classes stored in this
compiler's factory.
|
void |
generateProcessedSourceFiles(OutputType outputType)
Generates the source code associated to the classes stored in this
compiler's factory.
|
void |
generateProcessedSourceFiles(OutputType outputType,
Filter<CtType<?>> typeFilter)
Generates the source code associated to the classes stored in this
compiler's factory.
|
File |
getBinaryOutputDirectory()
Gets the binary output directory of the compiler.
|
List<CompilationUnitFilter> |
getCompilationUnitFilter()
Returns a copy of the internal list of
CompilationUnitFilter s. |
Factory |
getFactory()
Returns the working factory
|
Set<File> |
getInputSources()
Gets all the files/directories given as input sources to this builder
(see
addInputSource(File) ). |
String[] |
getSourceClasspath()
Gets the classpath that is used to build/compile the input sources.
|
File |
getSourceOutputDirectory()
Gets the output directory of this compiler.
|
String[] |
getTemplateClasspath()
Gets the classpath that is used to build the template sources.
|
Set<File> |
getTemplateSources()
Gets all the files/directories given as template sources to this builder
(see
addTemplateSource(File) ). |
void |
instantiateAndProcess(List<String> processors)
Takes a list of fully qualified name processors and instantiates them to process
the Java model.
|
void |
process(Collection<Processor<? extends CtElement>> processors)
Processes the Java model with the given processors.
|
void |
removeCompilationUnitFilter(CompilationUnitFilter filter)
Removes
filter . |
void |
setBinaryOutputDirectory(File binaryOutputDirectory)
Sets the output directory for binary generated.
|
void |
setSourceClasspath(String... classpath)
Sets the classpath that is used to build/compile the input sources.
|
void |
setTemplateClasspath(String... classpath)
Sets the classpath that is used to build the template sources.
|
boolean build()
SpoonException
- when a building problem occursgetSourceClasspath()
,
getTemplateClasspath()
boolean build(JDTBuilder builder)
builder
- Parameters given at JDT compiler.SpoonException
- when a building problem occursgetSourceClasspath()
,
getTemplateClasspath()
boolean compile(SpoonModelBuilder.InputType... types)
getBinaryOutputDirectory()
.
The array of types must be of size 0 or 1. If it's empty,
the types of the factory are compiled.
If it's InputType.FILES, the files given as input are compiled.
Note that the varargs ... enables this version to be backward compatible for callers.getSourceClasspath()
void instantiateAndProcess(List<String> processors)
void process(Collection<Processor<? extends CtElement>> processors)
void generateProcessedSourceFiles(OutputType outputType)
getSourceOutputDirectory()
.outputType
- the output methodvoid generateProcessedSourceFiles(OutputType outputType, Filter<CtType<?>> typeFilter)
getSourceOutputDirectory()
.outputType
- the output methodtypeFilter
- Filter on CtType to know which type Spoon must print.void addInputSource(File source)
source
- file or directory to addvoid addInputSource(SpoonResource source)
SpoonResource
) to be built. By default, the
files could be Java source files or Jar files. Directories are processed
recursively.source
- file or directory to addvoid addInputSources(List<SpoonResource> resources)
SpoonResource
to be built.
By default, the files could be Java source files of Java files. Directories
are processed recursively.resources
- files or directories to add.Set<File> getInputSources()
addInputSource(File)
).void addTemplateSource(File source)
source
- file or directory to addvoid addTemplateSource(SpoonResource source)
SpoonResource
) to be used to build templates. By
default, the files should be Java source files or Jar files containing
the sources. Directories are processed recursively. Templates are set
apart from the program to be processed for logical reasons. However, if a
template was needed to be processed, it could be added as an input
source.source
- file or directory to addvoid addTemplateSources(List<SpoonResource> resources)
resources
- files or directories to add.Set<File> getTemplateSources()
addTemplateSource(File)
).File getSourceOutputDirectory()
void setBinaryOutputDirectory(File binaryOutputDirectory)
binaryOutputDirectory
- File
for binary output directory.File getBinaryOutputDirectory()
String[] getSourceClasspath()
void setSourceClasspath(String... classpath)
String[] getTemplateClasspath()
setSourceClasspath(java.lang.String...)
for the meaning of the returned string.void setTemplateClasspath(String... classpath)
Factory getFactory()
void addCompilationUnitFilter(CompilationUnitFilter filter)
filter
.filter
- The CompilationUnitFilter
to add.void removeCompilationUnitFilter(CompilationUnitFilter filter)
filter
. Does nothing, if filter
has not been
added beforehand.filter
- The CompilationUnitFilter
to remove.List<CompilationUnitFilter> getCompilationUnitFilter()
CompilationUnitFilter
s.CompilationUnitFilter
s.Copyright © 2007–2019 Inria. All rights reserved.