Package spoon
Class Launcher
java.lang.Object
spoon.Launcher
- All Implemented Interfaces:
SpoonAPI
- Direct Known Subclasses:
IncrementalLauncher
,MavenLauncher
This class implements an integrated command-line launcher for processing
programs at compile-time using the JDT-based builder (Eclipse). It takes
arguments that allow building, processing, printing, and compiling Java
programs. Launch with no arguments (see
main(String[])
) for detailed
usage.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInputResource(String path)
Adds an input resource to be processed by Spoon (either a file or a folder).void
addInputResource(SpoonResource resource)
adds a resource to be parsed to build the spoon modelvoid
addProcessor(String name)
Adds a processor (fully qualified name).<T extends CtElement>
voidaddProcessor(Processor<T> processor)
Adds an instance of a processor.void
addTemplateResource(SpoonResource resource)
Builds the modelCreates a new Spoon compiler (for building the model)createCompiler(List<SpoonResource> inputSources)
Creates a new Spoon Java compiler with a default factory and a list of input sources.createCompiler(Factory factory)
Creates a new Spoon Java compiler in order to process and compile Java source code.createCompiler(Factory factory, List<SpoonResource> inputSources)
createCompiler(Factory factory, List<SpoonResource> inputSources, List<SpoonResource> templateSources)
Creates a new Spoon Java compiler in order to process and compile Java source code.Creates a new Spoon environment (may be overridden)Creates a new Spoon factory (may be overridden)protected static com.martiansoftware.jsap.JSAP
Defines the common arguments for sub-launchers.protected com.martiansoftware.jsap.JSAPResult
Returns the command-line given launching arguments in JSAP format.protected SpoonModelBuilder
getCompilerInstance(Factory factory)
Instantiates the compiler.Returns the current environment.Returns the current factorygetModel()
Returns the model built from the sources given viaSpoonAPI.addInputResource(String)
Gets the list of processors instance to be initially applied during the processing.Gets the list of processor types to be initially applied during the processing (-p option).static void
A default program entry point (instantiates a launcher with the given arguments and callsrun()
).protected com.martiansoftware.jsap.JSAPResult
Parses the arguments given by the command line.static CtClass<?>
parseClass(String code)
returns the AST of an inline classvoid
Write the transformed files to diskvoid
void
process()
Processes the model with the processors given previously withSpoonAPI.addProcessor(String)
protected void
protected void
void
run()
Runs Spoon using the given compiler, with the given run options.void
Runs Spoon with these arguments (used by the "main" method)void
void
setBinaryOutputDirectory(File outputDirectory)
Sets the output directory for binary generated.void
setBinaryOutputDirectory(String path)
Sets the output directory for binary generated.void
setOutputFilter(String... qualifedNames)
Creates a filter from names in argument when the output-type is defined on classes.void
setOutputFilter(Filter<CtType<?>> typeFilter)
Applies a filter when the output-type is defined on classes.void
setSourceOutputDirectory(File outputDirectory)
Sets the output directory for source generated.void
setSourceOutputDirectory(String path)
Sets the output directory for source generated.
-
Field Details
-
SPOONED_CLASSES
- See Also:
- Constant Field Values
-
OUTPUTDIR
- See Also:
- Constant Field Values
-
factory
-
jsapActualArgs
protected com.martiansoftware.jsap.JSAPResult jsapActualArgs -
LOGGER
public static final org.slf4j.Logger LOGGERA default logger to be used by Spoon. -
RESOURCES_FILE_FILTER
public static final org.apache.commons.io.filefilter.IOFileFilter RESOURCES_FILE_FILTER -
ALL_DIR_FILTER
public static final org.apache.commons.io.filefilter.IOFileFilter ALL_DIR_FILTER
-
-
Constructor Details
-
Launcher
public Launcher() -
Launcher
- Parameters:
pFactory
- TheFactory
that will be utilized inbuildModel()
.- Throws:
IllegalArgumentException
- IfpFactory == null
.
-
-
Method Details
-
main
A default program entry point (instantiates a launcher with the given arguments and callsrun()
). -
run
Description copied from interface:SpoonAPI
Runs Spoon with these arguments (used by the "main" method) -
setArgs
-
printUsage
public void printUsage() -
addInputResource
Description copied from interface:SpoonAPI
Adds an input resource to be processed by Spoon (either a file or a folder).- Specified by:
addInputResource
in interfaceSpoonAPI
-
addInputResource
adds a resource to be parsed to build the spoon model -
addProcessor
Description copied from interface:SpoonAPI
Adds a processor (fully qualified name).- Specified by:
addProcessor
in interfaceSpoonAPI
-
addProcessor
Description copied from interface:SpoonAPI
Adds an instance of a processor. The user is responsible for keeping a pointer to it for later retrieving some processing information.- Specified by:
addProcessor
in interfaceSpoonAPI
-
addTemplateResource
-
getEnvironment
Description copied from interface:SpoonAPI
Returns the current environment. This environment is modifiable.- Specified by:
getEnvironment
in interfaceSpoonAPI
-
defineArgs
protected static com.martiansoftware.jsap.JSAP defineArgs()Defines the common arguments for sub-launchers.- Returns:
- the JSAP arguments
-
getArguments
protected final com.martiansoftware.jsap.JSAPResult getArguments()Returns the command-line given launching arguments in JSAP format. -
processArguments
protected void processArguments() -
reportClassPathMode
protected void reportClassPathMode() -
getProcessorTypes
Gets the list of processor types to be initially applied during the processing (-p option). -
getProcessors
Gets the list of processors instance to be initially applied during the processing. -
parseArgs
protected com.martiansoftware.jsap.JSAPResult parseArgs()Parses the arguments given by the command line.- Returns:
- the JSAP-presented arguments
-
createCompiler
Creates a new Spoon Java compiler in order to process and compile Java source code.- Parameters:
factory
- the factory this compiler works on
-
getCompilerInstance
Instantiates the compiler. This method is invoked bycreateCompiler(Factory)
to retrieve an empty compiler instance. Clients can override this method to use their custom compiler implementation.- Parameters:
factory
- the factory to pass on to the compiler.- Returns:
- a new compiler.
- See Also:
createCompiler(Factory)
-
createCompiler
-
createCompiler
public SpoonModelBuilder createCompiler(Factory factory, List<SpoonResource> inputSources, List<SpoonResource> templateSources)Creates a new Spoon Java compiler in order to process and compile Java source code. -
createCompiler
Description copied from interface:SpoonAPI
Creates a new Spoon compiler (for building the model)- Specified by:
createCompiler
in interfaceSpoonAPI
-
createCompiler
Creates a new Spoon Java compiler with a default factory and a list of input sources. -
createFactory
Description copied from interface:SpoonAPI
Creates a new Spoon factory (may be overridden)- Specified by:
createFactory
in interfaceSpoonAPI
-
getFactory
Description copied from interface:SpoonAPI
Returns the current factory- Specified by:
getFactory
in interfaceSpoonAPI
-
createEnvironment
Description copied from interface:SpoonAPI
Creates a new Spoon environment (may be overridden)- Specified by:
createEnvironment
in interfaceSpoonAPI
-
createOutputWriter
-
createPrettyPrinter
-
run
public void run()Runs Spoon using the given compiler, with the given run options. A Spoon run will perform the following tasks:- Source model building in the given compiler:
SpoonModelBuilder.build()
. - Template model building in the given factory (if any template source
is given):
SpoonModelBuilder.build()
. - Model processing with the list of given processors if any:
SpoonModelBuilder.instantiateAndProcess(List)
. - Processed Source code printing and generation (can be disabled with
OutputType.NO_OUTPUT
):SpoonModelBuilder.generateProcessedSourceFiles(OutputType)
. - Processed source code compilation (optional):
- Source model building in the given compiler:
-
buildModel
Description copied from interface:SpoonAPI
Builds the model- Specified by:
buildModel
in interfaceSpoonAPI
-
process
public void process()Description copied from interface:SpoonAPI
Processes the model with the processors given previously withSpoonAPI.addProcessor(String)
-
prettyprint
public void prettyprint()Description copied from interface:SpoonAPI
Write the transformed files to disk- Specified by:
prettyprint
in interfaceSpoonAPI
-
getModelBuilder
-
setSourceOutputDirectory
Description copied from interface:SpoonAPI
Sets the output directory for source generated.- Specified by:
setSourceOutputDirectory
in interfaceSpoonAPI
- Parameters:
path
- Path for the output directory.
-
setSourceOutputDirectory
Description copied from interface:SpoonAPI
Sets the output directory for source generated.- Specified by:
setSourceOutputDirectory
in interfaceSpoonAPI
- Parameters:
outputDirectory
-File
for output directory.
-
setOutputFilter
Description copied from interface:SpoonAPI
Applies a filter when the output-type is defined on classes.- Specified by:
setOutputFilter
in interfaceSpoonAPI
- Parameters:
typeFilter
- Filter on CtType to know which type Spoon must print.
-
setOutputFilter
Description copied from interface:SpoonAPI
Creates a filter from names in argument when the output-type is defined on classes.- Specified by:
setOutputFilter
in interfaceSpoonAPI
- Parameters:
qualifedNames
- Names of class in fully qualified name to know which type Spoon must print.
-
setBinaryOutputDirectory
Description copied from interface:SpoonAPI
Sets the output directory for binary generated.- Specified by:
setBinaryOutputDirectory
in interfaceSpoonAPI
- Parameters:
path
- Path for the binary output directory.
-
setBinaryOutputDirectory
Description copied from interface:SpoonAPI
Sets the output directory for binary generated.- Specified by:
setBinaryOutputDirectory
in interfaceSpoonAPI
- Parameters:
outputDirectory
-File
for the binary output directory.
-
getModel
Description copied from interface:SpoonAPI
Returns the model built from the sources given viaSpoonAPI.addInputResource(String)
-
parseClass
returns the AST of an inline class
-