Package spoon

Class FluentLauncher

java.lang.Object
spoon.FluentLauncher

public class FluentLauncher extends Object
FluentLauncher provides a different, fluent interface for the launcher class. Setting options is done via calls like noClasspath(boolean). This class exists for giving a user a simpler fluent api, which is useable for most use cases, but not all.
  • Constructor Details

    • FluentLauncher

      public FluentLauncher()
      Creates a new FluentLauncher, wrapping default Launcher. After setting options, call buildModel() for creating the CtModel with given settings.
    • FluentLauncher

      public FluentLauncher(SpoonAPI launcher)
      Creates a new FluentLauncher, wrapping the given launcher. This constructor allows using different launchers eg. MavenLauncher with fluent api. After setting options, call buildModel() for creating the CtModel with given settings.
      Parameters:
      launcher - used for delegating methods.
  • Method Details

    • inputResource

      public FluentLauncher inputResource(String path)
      Adds an input resource to be processed by Spoon (either a file or a folder).
    • inputResource

      public FluentLauncher inputResource(Iterable<String> paths)
      Adds an input resource to be processed by Spoon (either a file or a folder).
    • processor

      public <T extends CtElement> FluentLauncher processor(Processor<T> processor)
      Adds an instance of a processor. The user is responsible for keeping a pointer to it for later retrieving some processing information.
    • processor

      public <T extends CtElement> FluentLauncher processor(Iterable<Processor<T>> processors)
      Adds an instance of a processor. The user is responsible for keeping a pointer to it for later retrieving some processing information.
    • buildModel

      public CtModel buildModel()
      Builds the model
    • outputDirectory

      public FluentLauncher outputDirectory(String path)
      Sets the output directory for source generated.
      Parameters:
      path - Path for the output directory.
    • outputDirectory

      public FluentLauncher outputDirectory(File outputDirectory)
      Sets the output directory for source generated.
      Parameters:
      outputDirectory - File for output directory.
    • autoImports

      public FluentLauncher autoImports(boolean autoImports)
      Tell to the Java printer to automatically generate imports and use simple names instead of fully-qualified name.
      Parameters:
      autoImports - toggles autoImports on or off.
      Returns:
      the launcher after setting the option.
    • disableConsistencyChecks

      public FluentLauncher disableConsistencyChecks()
      Disable all consistency checks on the AST. Dangerous! The only valid usage of this is to keep full backward-compatibility.
      Returns:
      the launcher after setting the option.
    • complianceLevel

      public FluentLauncher complianceLevel(int level)
      Sets the Java version compliance level.
      Parameters:
      level - of java version
      Returns:
      the launcher after setting the option.
    • sourceClassPath

      public FluentLauncher sourceClassPath(String[] sourceClasspath)
      Sets the source class path of the Spoon model. Only .jar files or directories with *.class files are accepted. The *.jar or *.java files contained in given directories are ignored.
      Parameters:
      sourceClasspath - path to sources.
      Returns:
      the launcher after setting the option.
      Throws:
      InvalidClassPathException - if a given classpath does not exists or does not have the right format (.jar file or directory)
    • noClasspath

      public FluentLauncher noClasspath(boolean option)
      Sets the option "noclasspath", use with caution (see explanation below). With this option, Spoon does not require the full classpath to build the model. In this case, all references to classes that are not in the classpath are handled with the reference mechanism. The "simplename" of the reference object refers to the unbound identifier. This option facilitates the use of Spoon when is is hard to have the complete and correct classpath, for example for mining software repositories. For writing analyses, this option works well if you don't cross the reference by a call to getDeclaration() (if you really want to do so, then check for nullness of the result before). In normal mode, compilation errors are signaled as exception, with this option enabled they are signaled as message only. The reason is that in most cases, there are necessarily errors related to the missing classpath elements.
      Returns:
      the launcher after setting the option.
    • encoding

      public FluentLauncher encoding(Charset encoding)
      Set the encoding to use for parsing source code
      Parameters:
      encoding - used for parsing.
      Returns:
      the launcher after setting the option.