Class TestConfigurationBuilder

java.lang.Object
org.checkerframework.framework.test.TestConfigurationBuilder

public class TestConfigurationBuilder extends Object
Used to create an instance of TestConfiguration. TestConfigurationBuilder is fluent: it returns itself after every call so you can string together configuration methods as follows:

new TestConfigurationBuilder() .addOption("-Awarns") .addSourceFile("src1.java") .addDiagnosticFile("src1.out")

See Also:
  • Field Details

  • Constructor Details

    • TestConfigurationBuilder

      public TestConfigurationBuilder()
      Note: There are static helper methods named buildConfiguration and buildConfigurationBuilder that can be used to create the most common types of configurations
    • TestConfigurationBuilder

      public TestConfigurationBuilder(TestConfiguration initialConfig)
      Create a builder that has all of the options in initialConfig.
      Parameters:
      initialConfig - initial configuration for the newly-created builder
  • Method Details

    • getDefaultConfigurationBuilder

      public static TestConfigurationBuilder getDefaultConfigurationBuilder(String testSourcePath, File outputClassDirectory, String classPath, Iterable<File> testSourceFiles, Iterable<@BinaryName String> processors, List<String> options, boolean shouldEmitDebugInfo)
      This creates a builder for the default configuration used by Checker Framework JUnit tests.
      Parameters:
      testSourcePath - the path to the Checker test file sources, usually this is the directory of Checker's tests
      outputClassDirectory - the directory to place classes compiled for testing
      classPath - the classpath to use for compilation
      testSourceFiles - the Java files that compose the test
      processors - the checkers or other annotation processors to run over the testSourceFiles
      options - the options to the compiler/processors
      shouldEmitDebugInfo - whether or not debug information should be emitted
      Returns:
      the builder that will create an immutable test configuration
    • buildDefaultConfiguration

      public static TestConfiguration buildDefaultConfiguration(String testSourcePath, File testFile, Class<?> processor, List<String> options, boolean shouldEmitDebugInfo)
      This is the default configuration used by Checker Framework JUnit tests.
      Parameters:
      testSourcePath - the path to the Checker test file sources, usually this is the directory of Checker's tests
      testFile - a single test Java file to compile
      processor - a single checker to include in the processors field
      options - the options to the compiler/processors
      shouldEmitDebugInfo - whether or not debug information should be emitted
      Returns:
      a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
    • buildDefaultConfiguration

      public static TestConfiguration buildDefaultConfiguration(String testSourcePath, Iterable<File> testSourceFiles, Iterable<@BinaryName String> processors, List<String> options, boolean shouldEmitDebugInfo)
      This is the default configuration used by Checker Framework JUnit tests.
      Parameters:
      testSourcePath - the path to the Checker test file sources, usually this is the directory of Checker's tests
      testSourceFiles - the Java files that compose the test
      processors - the checkers or other annotation processors to run over the testSourceFiles
      options - the options to the compiler/processors
      shouldEmitDebugInfo - whether or not debug information should be emitted
      Returns:
      a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
    • buildDefaultConfiguration

      public static TestConfiguration buildDefaultConfiguration(String testSourcePath, Iterable<File> testSourceFiles, Collection<String> classpathExtra, Iterable<@BinaryName String> processors, List<String> options, boolean shouldEmitDebugInfo)
      This is the default configuration used by Checker Framework JUnit tests.
      Parameters:
      testSourcePath - the path to the Checker test file sources, usually this is the directory of Checker's tests
      testSourceFiles - the Java files that compose the test
      classpathExtra - extra entries for the classpath, needed to compile the source files
      processors - the checkers or other annotation processors to run over the testSourceFiles
      options - the options to the compiler/processors
      shouldEmitDebugInfo - whether or not debug information should be emitted
      Returns:
      a TestConfiguration with input parameters added plus the normal default options, compiler, and file manager used by Checker Framework tests
    • validate

      public List<String> validate(boolean requireProcessors)
      Ensures that the minimum requirements for running a test are met. These requirements are:
      • There is at least one source file
      • There is at least one processor (if requireProcessors has been set to true)
      • There is an output directory specified for class files
      • There is no -processor option in the optionMap (it should be added by addProcessor instead)
      Parameters:
      requireProcessors - whether or not to require that there is at least one processor
      Returns:
      a list of errors found while validating this configuration
    • adddToPathOption

      public TestConfigurationBuilder adddToPathOption(String key, String toAppend)
    • addDiagnosticFile

      public TestConfigurationBuilder addDiagnosticFile(File diagnostics)
    • addDiagnosticFiles

      public TestConfigurationBuilder addDiagnosticFiles(Iterable<File> diagnostics)
    • setDiagnosticFiles

      public TestConfigurationBuilder setDiagnosticFiles(List<File> diagnosticFiles)
    • addSourceFile

      public TestConfigurationBuilder addSourceFile(File sourceFile)
    • addSourceFiles

      public TestConfigurationBuilder addSourceFiles(Iterable<File> sourceFiles)
    • setSourceFiles

      public TestConfigurationBuilder setSourceFiles(List<File> sourceFiles)
    • setOptions

      public TestConfigurationBuilder setOptions(Map<String,@Nullable String> options)
    • addOption

      public TestConfigurationBuilder addOption(String option)
    • addOption

      public TestConfigurationBuilder addOption(String option, String value)
    • addOptionIfValueNonEmpty

      public TestConfigurationBuilder addOptionIfValueNonEmpty(String option, String value)
    • addOptions

      @RequiresNonNull("this.options") public TestConfigurationBuilder addOptions(@UnknownInitialization(TestConfigurationBuilder.class) TestConfigurationBuilder this, Map<String,@Nullable String> options)
      Adds the given options to this.
      Parameters:
      options - options to add to this
      Returns:
      this
    • addOptions

      public TestConfigurationBuilder addOptions(Iterable<String> newOptions)
    • setProcessors

      public TestConfigurationBuilder setProcessors(Iterable<@BinaryName String> processors)
      Set the processors.
      Parameters:
      processors - the processors to run
      Returns:
      this
    • addProcessor

      public TestConfigurationBuilder addProcessor(@BinaryName String processor)
      Add a processor.
      Parameters:
      processor - a processor to run
      Returns:
      this
    • addProcessors

      public TestConfigurationBuilder addProcessors(Iterable<@BinaryName String> processors)
      Add processors.
      Parameters:
      processors - processors to run
      Returns:
      this
    • emitDebugInfo

      public TestConfigurationBuilder emitDebugInfo()
    • dontEmitDebugInfo

      public TestConfigurationBuilder dontEmitDebugInfo()
    • setShouldEmitDebugInfo

      public TestConfigurationBuilder setShouldEmitDebugInfo(boolean shouldEmitDebugInfo)
    • build

      public TestConfiguration build()
      Creates a TestConfiguration using the settings in this builder. The settings are NOT validated first.
      Returns:
      a TestConfiguration using the settings in this builder
    • validateThenBuild

      public TestConfiguration validateThenBuild(boolean requireProcessors)
      Creates a TestConfiguration using the settings in this builder. The settings are first validated and a runtime exception is thrown if any errors are found
      Parameters:
      requireProcessors - whether or not there should be at least 1 processor specified, see method validate
      Returns:
      a TestConfiguration using the settings in this builder
    • flatOptions

      public List<String> flatOptions()
      Returns the set of Javac options as a flat list.
      Returns:
      the set of Javac options as a flat list
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getOutputDirFromProperty

      public static File getOutputDirFromProperty()
    • getDefaultClassPath

      public static String getDefaultClassPath()