Package 

Interface TestSources


  • 
    public interface TestSources
    
                        

    Runtime compilation of test cases.

    val sources = TestSources.create()
    val X: Class<*> by sources.add("X", "class X {}")
    val A: Class<Annotation> by sources.add("A", "@interface A {}")
    val types = sources.types {
        +"? extends X"
        block("T") {
            +"T"
        }
    }
    sources.compile()
    
    types["? extends X"]
    types["T"]
    • Method Detail

      • add

         abstract TestSources.ClassDelegate<?> add(String name, String code, Boolean trimIndent)

        Adds the passed class to this compiler. This method automatically prepends the necessary package declaration to the passed string and adds a wildcard import for the "root" package, gen, if needed.

        This method will perform these expansions in the source code:

        • Any occurrences of @rt(targets) in the text will be replaced with the annotations for runtime annotation retention and the passed element targets. e.g. @rt(TYPE_USE)

        • Any occurrences of NOP; in the text will be replaced with a throw statement

        • Annotation: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType...) @interface A { int value(); }

        • ElementTypes: TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE, TYPE_PARAMETER, TYPE_USE

        val A by sources.add("A", "@rt(TYPE_USE) @interface A {}")
        val X by sources.add("X", "class X {}")
        val G by sources.add("G", "class G<T> {}")
        Parameters:
        name - The qualified name relative to the "root" package (gen)
        code - The code to compile into that class
      • getClass

         abstract Class<?> getClass(String name)

        Get a class based on its fully-qualified name

      • getCompilerOptions

         abstract List<String> getCompilerOptions()

        Additional command-line arguments for the Java compiler. Includes -parameters by default

      • getGlobalImports

         abstract List<String> getGlobalImports()

        Imports to insert at the top of every file. This must be set beforeadd is called for it to have any effect.