Package spoon
Interface SpoonModelBuilder
- All Known Implementing Classes:
JDTBasedSpoonCompiler
,JDTSnippetCompiler
public interface SpoonModelBuilder
Responsible for building a spoon model from Java source code.
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:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The types of compilable elements FILES - compiles the java files from the file system, which were registered byaddInputSource(File)
andaddTemplateSource(File)
CTTYPES - compiles virtual java files, which are dynamically generated from the all top level classes of the CtModel byDefaultJavaPrettyPrinter
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Addsfilter
.void
addInputSource(File source)
Adds a file/directory to be built.void
addInputSource(SpoonResource source)
Adds a file/directory (as aSpoonResource
) to be built.void
addInputSources(List<SpoonResource> resources)
Adds a list of files/directories (as aSpoonResource
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 aSpoonResource
) 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.Gets the binary output directory of the compiler.Returns a copy of the internal list ofCompilationUnitFilter
s.Returns the working factoryGets all the files/directories given as input sources to this builder (seeaddInputSource(File)
).String[]
Gets the classpath that is used to build/compile the input sources.Gets the output directory of this compiler.String[]
Gets the classpath that is used to build the template sources.Gets all the files/directories given as template sources to this builder (seeaddTemplateSource(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
Removesfilter
.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.
-
Method Details
-
build
boolean build()Builds the program's model with this compiler's factory and stores the result into this factory. Note that this method should only be used once on a given factory.- Returns:
- true if the Java was successfully compiled with the core Java compiler, false if some errors were encountered while compiling
- Throws:
SpoonException
- when a building problem occurs- See Also:
getSourceClasspath()
,getTemplateClasspath()
-
build
Builds the program's model with this compiler's factory and stores the result into this factory. Note that this method should only be used once on a given factory.- Parameters:
builder
- Parameters given at JDT compiler.- Returns:
- true if the Java was successfully compiled with the core Java compiler, false if some errors were encountered while compiling
- Throws:
SpoonException
- when a building problem occurs- See Also:
getSourceClasspath()
,getTemplateClasspath()
-
compile
Generates the bytecode associated to the classes stored in this compiler's factory. The bytecode is generated in the directory given bygetBinaryOutputDirectory()
. 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.- See Also:
getSourceClasspath()
-
instantiateAndProcess
Takes a list of fully qualified name processors and instantiates them to process the Java model. -
process
Processes the Java model with the given processors. -
generateProcessedSourceFiles
Generates the source code associated to the classes stored in this compiler's factory. The source code is generated in the directory given bygetSourceOutputDirectory()
.- Parameters:
outputType
- the output method
-
generateProcessedSourceFiles
Generates the source code associated to the classes stored in this compiler's factory. The source code is generated in the directory given bygetSourceOutputDirectory()
.- Parameters:
outputType
- the output methodtypeFilter
- Filter on CtType to know which type Spoon must print.
-
addInputSource
Adds a file/directory to be built. By default, the files could be Java source files or Jar files. Directories are processed recursively.- Parameters:
source
- file or directory to add
-
addInputSource
Adds a file/directory (as aSpoonResource
) to be built. By default, the files could be Java source files or Jar files. Directories are processed recursively.- Parameters:
source
- file or directory to add
-
addInputSources
Adds a list of files/directories (as aSpoonResource
to be built. By default, the files could be Java source files of Java files. Directories are processed recursively.- Parameters:
resources
- files or directories to add.
-
getInputSources
Gets all the files/directories given as input sources to this builder (seeaddInputSource(File)
). -
addTemplateSource
Adds a file/directory 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.- Parameters:
source
- file or directory to add
-
addTemplateSource
Adds a file/directory (as aSpoonResource
) 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.- Parameters:
source
- file or directory to add
-
addTemplateSources
Adds a list of files/directories (as a CtResource) 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.- Parameters:
resources
- files or directories to add.
-
getTemplateSources
Gets all the files/directories given as template sources to this builder (seeaddTemplateSource(File)
). -
getSourceOutputDirectory
File getSourceOutputDirectory()Gets the output directory of this compiler. -
setBinaryOutputDirectory
Sets the output directory for binary generated.- Parameters:
binaryOutputDirectory
-File
for binary output directory.
-
getBinaryOutputDirectory
File getBinaryOutputDirectory()Gets the binary output directory of the compiler. -
getSourceClasspath
String[] getSourceClasspath()Gets the classpath that is used to build/compile the input sources. -
setSourceClasspath
Sets the classpath that is used to build/compile the input sources. Each element of the array is either a jar file or a folder containing bytecode files. -
getTemplateClasspath
String[] getTemplateClasspath()Gets the classpath that is used to build the template sources. SeesetSourceClasspath(java.lang.String...)
for the meaning of the returned string. -
setTemplateClasspath
Sets the classpath that is used to build the template sources. -
getFactory
Factory getFactory()Returns the working factory -
addCompilationUnitFilter
Addsfilter
.- Parameters:
filter
- TheCompilationUnitFilter
to add.
-
removeCompilationUnitFilter
Removesfilter
. Does nothing, iffilter
has not been added beforehand.- Parameters:
filter
- TheCompilationUnitFilter
to remove.
-
getCompilationUnitFilter
List<CompilationUnitFilter> getCompilationUnitFilter()Returns a copy of the internal list ofCompilationUnitFilter
s.- Returns:
- A copy of the internal list of
CompilationUnitFilter
s.
-