Class ScalaCompiler

java.lang.Object
io.micronaut.scala.processing.test.ScalaCompiler

public final class ScalaCompiler extends Object
Scala compiler helper for inline test sources.
  • Method Details

    • buildClassLoader

      public static URLClassLoader buildClassLoader(String className, String source)
      Builds a classloader for a Scala source.
      Parameters:
      className - The primary class name
      source - The source
      Returns:
      The classloader
    • buildClassElement

      public static @Nullable io.micronaut.inject.ast.ClassElement buildClassElement(String className, String source)
      Builds a class element for the given source.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The class element
    • 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 name
      source - The source
      compilerOptions - The additional compiler options
      Returns:
      The class element
    • buildBeanIntrospection

      public static @Nullable io.micronaut.core.beans.BeanIntrospection<?> buildBeanIntrospection(String className, String source)
      Builds a bean introspection for the given source.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The introspection
    • 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 name
      source - The source
      compilerOptions - The additional compiler options
      Returns:
      The introspection
    • buildBeanDefinition

      public static @Nullable io.micronaut.inject.BeanDefinition<?> buildBeanDefinition(String className, String source)
      Builds a bean definition for the given source.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The bean definition
    • 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 name
      source - The source
      compilerOptions - 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>$Definition convention, such as an intercepted or factory-produced definition.
      Parameters:
      packageName - The package of the generated definition
      generatedClassName - The simple name of the generated definition class
      source - The source
      Returns:
      The bean definition
    • buildBeanDefinitionReference

      public static @Nullable io.micronaut.inject.BeanDefinitionReference<?> buildBeanDefinitionReference(String className, String source)
      Builds a bean definition reference for the given source.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The bean definition reference
    • buildAndGetWarnings

      public static List<String> buildAndGetWarnings(String className, String source)
      Compiles the given source and returns the compiler warnings it produced. Warnings are the channel VisitorContext.warn(...) writes to, so without this a visitor warning cannot be asserted at all.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The formatted warnings, as file:line:column: message where 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 source
      includeAllBeans - 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 source
      includeAllBeans - Whether to include all default beans
      config - 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 source
      includeAllBeans - Whether to include all default beans
      config - The context configuration
      compilerOptions - 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 compilations
      source - The source
      includeAllBeans - Whether to add every bean on the classpath
      config - The configuration
      compilerOptions - The additional compiler options
      Returns:
      The started context
    • buildAndGetDiagnostics

      public static ScalaCompiler.Diagnostics buildAndGetDiagnostics(String className, String source)
      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, not NoSourcePosition.
      Parameters:
      className - The class name
      source - The source
      Returns:
      The warnings and errors, as file:line:column: message where a position exists