-
public interface TestSourcesRuntime 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"]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classTestSources.Companionpublic interfaceTestSources.ClassDelegateA lazy delegate to refer to a runtime-compiled class
-
Method Summary
Modifier and Type Method Description abstract TestSources.ClassDelegate<?>add(String name, String code, Boolean trimIndent)Adds the passed class to this compiler. abstract TypeSettypes(String packageName, Function1<TypeSetBuilder, Unit> block)Create an TypeSet using the provided builder abstract Unitcompile()Compile the classes abstract Class<?>getClass(String name)Get a class based on its fully-qualified name abstract <T extends Any> TestSources.ClassDelegate<T>getDelegate(String name)Create a delegate for a class based on its fully-qualified name abstract List<String>getCompilerOptions()Additional command-line arguments for the Java compiler. abstract List<String>getGlobalImports()Imports to insert at the top of every file. -
-
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
packagedeclaration 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
-
types
abstract TypeSet types(String packageName, Function1<TypeSetBuilder, Unit> block)
Create an TypeSet using the provided builder
-
getDelegate
abstract <T extends Any> TestSources.ClassDelegate<T> getDelegate(String name)
Create a delegate for a class based on its fully-qualified name
-
getCompilerOptions
abstract List<String> getCompilerOptions()
Additional command-line arguments for the Java compiler. Includes
-parametersby 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.
-
-
-
-