Class ByteCodeGenerator

java.lang.Object
io.micronaut.sourcegen.generator.AbstractByteCodeGenerator
io.micronaut.sourcegen.generator.bytecode.jdk.ByteCodeGenerator
All Implemented Interfaces:
SourceGenerator

public final class ByteCodeGenerator extends AbstractByteCodeGenerator
Sourcegen generator entry point for the JDK backend.

The writer uses the annotation-processing context to reconstruct the source and class paths visible to the current compilation. It emits normalized classfiles directly when all referenced types are resolvable and preserves annotation-processing round semantics with a Java source fallback when a peer generated type is not yet available.

Since:
2.2
  • Field Details

    • SOURCE_PATH_OPTION

      public static final String SOURCE_PATH_OPTION
      Annotation-processor option holding additional source roots, separated by File.pathSeparator, which javac may read when a generated class references a type that is still being compiled. Builds whose sources live outside src/main/java and src/test/java of the project directory, for example shared source sets, should pass those roots through this option.
      See Also:
    • CLASS_PATH_OPTION

      public static final String CLASS_PATH_OPTION
      Annotation-processor option holding the compilation's class path, separated by File.pathSeparator. An annotation processor cannot see the class path javac was started with, only its own processor path, so builds whose generated classes reference compile-scope dependencies should pass that class path here for the source fallback to resolve them.
      See Also:
  • Constructor Details

    • ByteCodeGenerator

      public ByteCodeGenerator()
  • Method Details

    • getLanguage

      public io.micronaut.inject.visitor.VisitorContext.Language getLanguage()
      Returns:
      The source language of the generator
    • writeClass

      protected boolean writeClass(ObjectDef objectDef, @Nullable ClassTypeDef outerType, io.micronaut.inject.visitor.VisitorContext context, io.micronaut.inject.ast.Element[] originatingElements) throws Exception
      Description copied from class: AbstractByteCodeGenerator
      Emit one definition.
      Specified by:
      writeClass in class AbstractByteCodeGenerator
      Parameters:
      objectDef - The definition
      outerType - The enclosing type, or null
      context - The visitor context
      originatingElements - Originating elements
      Returns:
      true when member definitions should be traversed
      Throws:
      Exception - If emission fails