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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInputResource(String path)Adds an input resource to be processed by Spoon (either a file or a folder).voidaddInputResource(SpoonResource resource)adds a resource to be parsed to build the spoon modelvoidaddProcessor(String name)Adds a processor (fully qualified name).<T extends CtElement>
voidaddProcessor(Processor<T> processor)Adds an instance of a processor.voidaddTemplateResource(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.JSAPDefines the common arguments for sub-launchers.protected com.martiansoftware.jsap.JSAPResultReturns the command-line given launching arguments in JSAP format.protected SpoonModelBuildergetCompilerInstance(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 voidA default program entry point (instantiates a launcher with the given arguments and callsrun()).protected com.martiansoftware.jsap.JSAPResultParses the arguments given by the command line.static CtClass<?>parseClass(String code)returns the AST of an inline classvoidWrite the transformed files to diskvoidvoidprocess()Processes the model with the processors given previously withSpoonAPI.addProcessor(String)protected voidprotected voidvoidrun()Runs Spoon using the given compiler, with the given run options.voidRuns Spoon with these arguments (used by the "main" method)voidvoidsetBinaryOutputDirectory(File outputDirectory)Sets the output directory for binary generated.voidsetBinaryOutputDirectory(String path)Sets the output directory for binary generated.voidsetOutputFilter(String... qualifedNames)Creates a filter from names in argument when the output-type is defined on classes.voidsetOutputFilter(Filter<CtType<?>> typeFilter)Applies a filter when the output-type is defined on classes.voidsetSourceOutputDirectory(File outputDirectory)Sets the output directory for source generated.voidsetSourceOutputDirectory(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- TheFactorythat 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:SpoonAPIRuns Spoon with these arguments (used by the "main" method) -
setArgs
-
printUsage
public void printUsage() -
addInputResource
Description copied from interface:SpoonAPIAdds an input resource to be processed by Spoon (either a file or a folder).- Specified by:
addInputResourcein interfaceSpoonAPI
-
addInputResource
adds a resource to be parsed to build the spoon model -
addProcessor
Description copied from interface:SpoonAPIAdds a processor (fully qualified name).- Specified by:
addProcessorin interfaceSpoonAPI
-
addProcessor
Description copied from interface:SpoonAPIAdds an instance of a processor. The user is responsible for keeping a pointer to it for later retrieving some processing information.- Specified by:
addProcessorin interfaceSpoonAPI
-
addTemplateResource
-
getEnvironment
Description copied from interface:SpoonAPIReturns the current environment. This environment is modifiable.- Specified by:
getEnvironmentin 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:SpoonAPICreates a new Spoon compiler (for building the model)- Specified by:
createCompilerin interfaceSpoonAPI
-
createCompiler
Creates a new Spoon Java compiler with a default factory and a list of input sources. -
createFactory
Description copied from interface:SpoonAPICreates a new Spoon factory (may be overridden)- Specified by:
createFactoryin interfaceSpoonAPI
-
getFactory
Description copied from interface:SpoonAPIReturns the current factory- Specified by:
getFactoryin interfaceSpoonAPI
-
createEnvironment
Description copied from interface:SpoonAPICreates a new Spoon environment (may be overridden)- Specified by:
createEnvironmentin 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:SpoonAPIBuilds the model- Specified by:
buildModelin interfaceSpoonAPI
-
process
public void process()Description copied from interface:SpoonAPIProcesses the model with the processors given previously withSpoonAPI.addProcessor(String) -
prettyprint
public void prettyprint()Description copied from interface:SpoonAPIWrite the transformed files to disk- Specified by:
prettyprintin interfaceSpoonAPI
-
getModelBuilder
-
setSourceOutputDirectory
Description copied from interface:SpoonAPISets the output directory for source generated.- Specified by:
setSourceOutputDirectoryin interfaceSpoonAPI- Parameters:
path- Path for the output directory.
-
setSourceOutputDirectory
Description copied from interface:SpoonAPISets the output directory for source generated.- Specified by:
setSourceOutputDirectoryin interfaceSpoonAPI- Parameters:
outputDirectory-Filefor output directory.
-
setOutputFilter
Description copied from interface:SpoonAPIApplies a filter when the output-type is defined on classes.- Specified by:
setOutputFilterin interfaceSpoonAPI- Parameters:
typeFilter- Filter on CtType to know which type Spoon must print.
-
setOutputFilter
Description copied from interface:SpoonAPICreates a filter from names in argument when the output-type is defined on classes.- Specified by:
setOutputFilterin interfaceSpoonAPI- Parameters:
qualifedNames- Names of class in fully qualified name to know which type Spoon must print.
-
setBinaryOutputDirectory
Description copied from interface:SpoonAPISets the output directory for binary generated.- Specified by:
setBinaryOutputDirectoryin interfaceSpoonAPI- Parameters:
path- Path for the binary output directory.
-
setBinaryOutputDirectory
Description copied from interface:SpoonAPISets the output directory for binary generated.- Specified by:
setBinaryOutputDirectoryin interfaceSpoonAPI- Parameters:
outputDirectory-Filefor the binary output directory.
-
getModel
Description copied from interface:SpoonAPIReturns the model built from the sources given viaSpoonAPI.addInputResource(String) -
parseClass
returns the AST of an inline class
-