Class KotlinCompiler
java.lang.Object
io.micronaut.annotation.processing.test.KotlinCompiler
Compiler for kotlin code (for tests).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TbuildAndLoad(String className, String beanFullName, String cls) static BeanDefinition<?> buildBeanDefinition(String name, String clazz) static BeanDefinition<?> buildBeanDefinition(String packageName, String simpleName, String clazz) static BeanDefinition<?> buildBeanDefinition(String packageName, String simpleName, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) static BeanDefinition<?> buildBeanDefinition(String name, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) static BeanDefinitionReference<?> buildBeanDefinitionReference(String name, String clazz) static BeanIntrospection<?> buildBeanIntrospection(String name, String clazz) static URLClassLoaderbuildClassLoader(String name, String clazz) static URLClassLoaderbuildClassLoader(String name, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) static ApplicationContextbuildContext(String clazz) static ApplicationContextbuildContext(String clazz, boolean includeAllBeans) static ApplicationContextbuildContext(String clazz, boolean includeAllBeans, Map<String, Object> config) static BeanDefinition<?> buildInterceptedBeanDefinition(String className, String cls) static BeanDefinitionReference<?> buildInterceptedBeanDefinitionReference(String className, String cls) static BeanDefinition<?> buildIntroducedBeanDefinition(String className, String cls) static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(String name, String clazz, Consumer<ClassElement> classElements) static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(String name, String clazz, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(List<com.tschuchort.compiletesting.SourceFile> sources, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) Compile Kotlin source files through KSP.static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compileJava(String name, String clazz, Consumer<ClassElement> classElements) static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compileJava(String name, String clazz, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) static ObjectgetBean(BeanContext beanContext, String className) static BeanDefinition<?> getBeanDefinition(BeanContext beanContext, String className) static byte[]getClassBytes(String name, String clazz) static com.tschuchort.compiletesting.SourceFilekotlinSource(String name, String source) Creates a Kotlin source file for use withcompile(List, Consumer, List).static voidsetJvmDefaultMode(String mode) Sets the-jvm-defaultmode the compilations run with.
-
Constructor Details
-
KotlinCompiler
public KotlinCompiler()
-
-
Method Details
-
setJvmDefaultMode
Sets the-jvm-defaultmode the compilations run with. The mode decides whether the synthetic$defaultmethod of an interface method with default arguments is emitted on the interface, on itsDefaultImplsclass, or on both.The mode does not reach KSP, which always reports the
disableit defaults to, so only the modes emittingDefaultImplscan be told apart here.- Parameters:
mode- The mode, one ofdisable,enableorno-compatibility
-
buildClassLoader
-
buildClassLoader
public static URLClassLoader buildClassLoader(String name, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) -
kotlinSource
Creates a Kotlin source file for use withcompile(List, Consumer, List).- Parameters:
name- source file namesource- Kotlin source content- Returns:
- Kotlin source file
-
compile
public static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(String name, String clazz, Consumer<ClassElement> classElements) -
compile
public static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(String name, String clazz, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) -
compile
public static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compile(List<com.tschuchort.compiletesting.SourceFile> sources, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) Compile Kotlin source files through KSP.The KSP compilation compiles the sources together with what the processors generate, so the sources are compiled once and both elements of the returned pair hold that compilation.
- Parameters:
sources- Kotlin sources to compileclassElements- consumer for compiled class elementsextraSymbolProcessorProviders- additional KSP processors- Returns:
- the KSP compilation result, twice
-
compileJava
public static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compileJava(String name, String clazz, Consumer<ClassElement> classElements) -
compileJava
public static kotlin.Pair<kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>, kotlin.Pair<com.tschuchort.compiletesting.KotlinCompilation, com.tschuchort.compiletesting.JvmCompilationResult>> compileJava(String name, String clazz, Consumer<ClassElement> classElements, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) -
buildBeanIntrospection
-
buildBeanDefinition
public static BeanDefinition<?> buildBeanDefinition(String name, String clazz) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildBeanDefinition
public static BeanDefinition<?> buildBeanDefinition(String name, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildBeanDefinition
public static BeanDefinition<?> buildBeanDefinition(String packageName, String simpleName, String clazz) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildBeanDefinition
public static BeanDefinition<?> buildBeanDefinition(String packageName, String simpleName, String clazz, List<com.google.devtools.ksp.processing.SymbolProcessorProvider> extraSymbolProcessorProviders) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildBeanDefinitionReference
public static BeanDefinitionReference<?> buildBeanDefinitionReference(String name, String clazz) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildIntroducedBeanDefinition
public static BeanDefinition<?> buildIntroducedBeanDefinition(String className, String cls) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildInterceptedBeanDefinition
public static BeanDefinition<?> buildInterceptedBeanDefinition(String className, String cls) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildInterceptedBeanDefinitionReference
public static BeanDefinitionReference<?> buildInterceptedBeanDefinitionReference(String className, String cls) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
buildAndLoad
public static <T> T buildAndLoad(String className, String beanFullName, String cls) throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException -
getClassBytes
public static byte[] getClassBytes(String name, String clazz) throws FileNotFoundException, IOException - Throws:
FileNotFoundExceptionIOException
-
buildContext
-
buildContext
-
buildContext
public static ApplicationContext buildContext(String clazz, boolean includeAllBeans, Map<String, Object> config) -
getBean
public static Object getBean(BeanContext beanContext, String className) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
getBeanDefinition
public static BeanDefinition<?> getBeanDefinition(BeanContext beanContext, String className) throws ClassNotFoundException - Throws:
ClassNotFoundException
-