Class ScalaCompiler
java.lang.Object
io.micronaut.scala.processing.test.ScalaCompiler
Scala compiler helper for inline test sources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe diagnostics a compilation produced.static final recordA single source to compile. -
Method Summary
Modifier and TypeMethodDescriptionstatic ScalaCompiler.DiagnosticsbuildAndGetDiagnostics(String className, String source) Compiles the source and returns every diagnostic the compiler produced, without failing on errors.buildAndGetWarnings(String className, String source) Compiles the given source and returns the compiler warnings it produced.static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String className, String source) Builds a bean definition for the given source.static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String packageName, String generatedClassName, String source) Builds a bean definition whose generated class name does not follow the$<Class>$Definitionconvention, such as an intercepted or factory-produced definition.static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String className, String source, List<String> compilerOptions) Builds a bean definition for the given source.static @Nullable io.micronaut.inject.BeanDefinitionReference<?> buildBeanDefinitionReference(String className, String source) Builds a bean definition reference for the given source.static @Nullable io.micronaut.core.beans.BeanIntrospection<?> buildBeanIntrospection(String className, String source) Builds a bean introspection for the given source.static @Nullable io.micronaut.core.beans.BeanIntrospection<?> buildBeanIntrospection(String className, String source, List<String> compilerOptions) Builds a bean introspection for the given source.static @Nullable io.micronaut.inject.ast.ClassElementbuildClassElement(String className, String source) Builds a class element for the given source.static @Nullable io.micronaut.inject.ast.ClassElementbuildClassElement(String className, String source, List<String> compilerOptions) Builds a class element for the given source.static URLClassLoaderbuildClassLoader(String className, String source) Builds a classloader for a Scala source.static io.micronaut.context.ApplicationContextbuildContext(String source, boolean includeAllBeans) Builds an application context for the given source.static io.micronaut.context.ApplicationContextbuildContext(String source, boolean includeAllBeans, Map<String, Object> config) Builds an application context for the given source.static io.micronaut.context.ApplicationContextbuildContext(String source, boolean includeAllBeans, Map<String, Object> config, List<String> compilerOptions) Builds an application context for the given source.static io.micronaut.context.ApplicationContextbuildContext(List<Path> precompiled, String source, boolean includeAllBeans, Map<String, Object> config, List<String> compilerOptions) Compiles the source against the output of earlier compilations and starts a context whose beans are the ones generated by every one of those compilations together.
-
Method Details
-
buildClassLoader
Builds a classloader for a Scala source.- Parameters:
className- The primary class namesource- The source- Returns:
- The classloader
-
buildClassElement
-
buildClassElement
public static @Nullable io.micronaut.inject.ast.ClassElement buildClassElement(String className, String source, List<String> compilerOptions) Builds a class element for the given source.- Parameters:
className- The class namesource- The sourcecompilerOptions- The additional compiler options- Returns:
- The class element
-
buildBeanIntrospection
-
buildBeanIntrospection
public static @Nullable io.micronaut.core.beans.BeanIntrospection<?> buildBeanIntrospection(String className, String source, List<String> compilerOptions) Builds a bean introspection for the given source.- Parameters:
className- The class namesource- The sourcecompilerOptions- The additional compiler options- Returns:
- The introspection
-
buildBeanDefinition
-
buildBeanDefinition
public static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String className, String source, List<String> compilerOptions) Builds a bean definition for the given source.- Parameters:
className- The class namesource- The sourcecompilerOptions- The additional compiler options- Returns:
- The bean definition
-
buildBeanDefinition
public static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String packageName, String generatedClassName, String source) Builds a bean definition whose generated class name does not follow the$<Class>$Definitionconvention, such as an intercepted or factory-produced definition.- Parameters:
packageName- The package of the generated definitiongeneratedClassName- The simple name of the generated definition classsource- The source- Returns:
- The bean definition
-
buildBeanDefinitionReference
-
buildAndGetWarnings
Compiles the given source and returns the compiler warnings it produced. Warnings are the channelVisitorContext.warn(...)writes to, so without this a visitor warning cannot be asserted at all.- Parameters:
className- The class namesource- The source- Returns:
- The formatted warnings, as
file:line:column: messagewhere a position exists
-
buildContext
public static io.micronaut.context.ApplicationContext buildContext(String source, boolean includeAllBeans) Builds an application context for the given source.- Parameters:
source- The sourceincludeAllBeans- Whether to include all default beans- Returns:
- The started context
-
buildContext
public static io.micronaut.context.ApplicationContext buildContext(String source, boolean includeAllBeans, Map<String, Object> config) Builds an application context for the given source.- Parameters:
source- The sourceincludeAllBeans- Whether to include all default beansconfig- The context configuration- Returns:
- The started context
-
buildContext
public static io.micronaut.context.ApplicationContext buildContext(String source, boolean includeAllBeans, Map<String, Object> config, List<String> compilerOptions) Builds an application context for the given source.- Parameters:
source- The sourceincludeAllBeans- Whether to include all default beansconfig- The context configurationcompilerOptions- The additional compiler options- Returns:
- The started context
-
buildContext
public static io.micronaut.context.ApplicationContext buildContext(List<Path> precompiled, String source, boolean includeAllBeans, Map<String, Object> config, List<String> compilerOptions) Compiles the source against the output of earlier compilations and starts a context whose beans are the ones generated by every one of those compilations together.This is the incremental build at runtime: a bean compiled now extends, implements or is advised by a type compiled earlier, and the definitions generated on both sides have to agree -- an interceptor compiled earlier must intercept a method compiled now.
- Parameters:
precompiled- Output directories of earlier compilationssource- The sourceincludeAllBeans- Whether to add every bean on the classpathconfig- The configurationcompilerOptions- The additional compiler options- Returns:
- The started context
-
buildAndGetDiagnostics
Compiles the source and returns every diagnostic the compiler produced, without failing on errors. A diagnostic's position is the point of this: an error reported against an element the visitor named should carry that element's file, line and column, notNoSourcePosition.- Parameters:
className- The class namesource- The source- Returns:
- The warnings and errors, as
file:line:column: messagewhere a position exists
-