Package spoon

Class Launcher

  • All Implemented Interfaces:
    SpoonAPI
    Direct Known Subclasses:
    IncrementalLauncher, MavenLauncher

    public class Launcher
    extends java.lang.Object
    implements SpoonAPI
    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 Detail

      • factory

        protected Factory factory
      • jsapActualArgs

        protected com.martiansoftware.jsap.JSAPResult jsapActualArgs
      • LOGGER

        public static final org.slf4j.Logger LOGGER
        A 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
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        A default program entry point (instantiates a launcher with the given arguments and calls run()).
      • run

        public void run​(java.lang.String[] args)
        Description copied from interface: SpoonAPI
        Runs Spoon with these arguments (used by the "main" method)
        Specified by:
        run in interface SpoonAPI
      • setArgs

        public void setArgs​(java.lang.String[] args2)
      • printUsage

        public void printUsage()
      • addInputResource

        public void addInputResource​(java.lang.String path)
        Description copied from interface: SpoonAPI
        Adds an input resource to be processed by Spoon (either a file or a folder).
        Specified by:
        addInputResource in interface SpoonAPI
      • addInputResource

        public void addInputResource​(SpoonResource resource)
        adds a resource to be parsed to build the spoon model
      • addProcessor

        public void addProcessor​(java.lang.String name)
        Description copied from interface: SpoonAPI
        Adds a processor (fully qualified name).
        Specified by:
        addProcessor in interface SpoonAPI
      • addProcessor

        public <T extends CtElement> void addProcessor​(Processor<T> processor)
        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 interface SpoonAPI
      • addTemplateResource

        public void addTemplateResource​(SpoonResource resource)
      • getEnvironment

        public Environment getEnvironment()
        Description copied from interface: SpoonAPI
        Returns the current environment. This environment is modifiable.
        Specified by:
        getEnvironment in interface SpoonAPI
      • 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

        protected java.util.List<java.lang.String> getProcessorTypes()
        Gets the list of processor types to be initially applied during the processing (-p option).
      • getProcessors

        protected java.util.List<Processor<? extends CtElement>> 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

        public SpoonModelBuilder createCompiler​(Factory factory)
        Creates a new Spoon Java compiler in order to process and compile Java source code.
        Parameters:
        factory - the factory this compiler works on
      • getCompilerInstance

        protected SpoonModelBuilder getCompilerInstance​(Factory factory)
        Instantiates the compiler. This method is invoked by createCompiler(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

        public SpoonModelBuilder createCompiler​(Factory factory,
                                                java.util.List<SpoonResource> inputSources,
                                                java.util.List<SpoonResource> templateSources)
        Creates a new Spoon Java compiler in order to process and compile Java source code.
      • createCompiler

        public SpoonModelBuilder createCompiler​(java.util.List<SpoonResource> inputSources)
        Creates a new Spoon Java compiler with a default factory and a list of input sources.
      • createFactory

        public Factory createFactory()
        Description copied from interface: SpoonAPI
        Creates a new Spoon factory (may be overridden)
        Specified by:
        createFactory in interface SpoonAPI
      • createPrettyPrinter

        public PrettyPrinter createPrettyPrinter()
      • prettyprint

        public void prettyprint()
        Description copied from interface: SpoonAPI
        Write the transformed files to disk
        Specified by:
        prettyprint in interface SpoonAPI
      • setSourceOutputDirectory

        public void setSourceOutputDirectory​(java.lang.String path)
        Description copied from interface: SpoonAPI
        Sets the output directory for source generated.
        Specified by:
        setSourceOutputDirectory in interface SpoonAPI
        Parameters:
        path - Path for the output directory.
      • setSourceOutputDirectory

        public void setSourceOutputDirectory​(java.io.File outputDirectory)
        Description copied from interface: SpoonAPI
        Sets the output directory for source generated.
        Specified by:
        setSourceOutputDirectory in interface SpoonAPI
        Parameters:
        outputDirectory - File for output directory.
      • setOutputFilter

        public void setOutputFilter​(Filter<CtType<?>> typeFilter)
        Description copied from interface: SpoonAPI
        Applies a filter when the output-type is defined on classes.
        Specified by:
        setOutputFilter in interface SpoonAPI
        Parameters:
        typeFilter - Filter on CtType to know which type Spoon must print.
      • setOutputFilter

        public void setOutputFilter​(java.lang.String... qualifedNames)
        Description copied from interface: SpoonAPI
        Creates a filter from names in argument when the output-type is defined on classes.
        Specified by:
        setOutputFilter in interface SpoonAPI
        Parameters:
        qualifedNames - Names of class in fully qualified name to know which type Spoon must print.
      • setBinaryOutputDirectory

        public void setBinaryOutputDirectory​(java.lang.String path)
        Description copied from interface: SpoonAPI
        Sets the output directory for binary generated.
        Specified by:
        setBinaryOutputDirectory in interface SpoonAPI
        Parameters:
        path - Path for the binary output directory.
      • setBinaryOutputDirectory

        public void setBinaryOutputDirectory​(java.io.File outputDirectory)
        Description copied from interface: SpoonAPI
        Sets the output directory for binary generated.
        Specified by:
        setBinaryOutputDirectory in interface SpoonAPI
        Parameters:
        outputDirectory - File for the binary output directory.
      • parseClass

        public static CtClass<?> parseClass​(java.lang.String code)
        returns the AST of an inline class