Class ByteCodeWriter
java.lang.Object
io.micronaut.sourcegen.bytecode.jdk.ByteCodeWriter
Writes Sourcegen definitions using the JDK 25 classfile toolchain.
The JDK backend lowers supported definitions directly with the JDK 25 ClassFile API, including stack maps and invokedynamic call sites. Definitions that require a source-level compatibility lowering use an in-memory Java 17 compiler fallback. This is deliberately kept in this JDK-only artifact and introduces no ASM into its runtime graph.
The resulting class is normalized through the JDK ClassFile API, pinned to Java 17, and verified before it is returned.
- Since:
- 2.2
- Author:
- Graeme Rocher
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a writer using the current runtime class path.ByteCodeWriter(List<Path> sourcePath, List<Path> classPath) Creates a writer with the paths visible to an annotation-processing invocation.ByteCodeWriter(List<Path> sourcePath, List<Path> classPath, boolean verify) Creates a writer with explicit paths and verification policy.ByteCodeWriter(List<Path> sourcePath, List<Path> classPath, boolean verify, @Nullable CompilationTypes compilationTypes) Creates a writer that can resolve types of the compilation it is running in. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Writes a top-level definition.byte[]write(ObjectDef objectDef, @Nullable ClassTypeDef outerType) Writes a definition which is a member of the supplied outer type.Writes a definition and all member classes produced for it.writeAll(ObjectDef objectDef, @Nullable ClassTypeDef outerType) Writes a definition and all member classes produced for it.
-
Constructor Details
-
ByteCodeWriter
public ByteCodeWriter()Creates a writer using the current runtime class path. -
ByteCodeWriter
-
ByteCodeWriter
Creates a writer with explicit paths and verification policy.- Parameters:
sourcePath- Source roots containing types still being compiledclassPath- Classpath entries containing already compiled typesverify- Whether to run ClassFile verification
-
ByteCodeWriter
@Internal public ByteCodeWriter(List<Path> sourcePath, List<Path> classPath, boolean verify, @Nullable CompilationTypes compilationTypes) Creates a writer that can resolve types of the compilation it is running in.A generated class often references types that are still being compiled and so have no class file to read. Supplying the current compilation's type lookup, such as
visitorContext::getClassElement, lets the writer resolve their hierarchy when it computes stack maps.- Parameters:
sourcePath- Source roots containing types still being compiledclassPath- Classpath entries containing already compiled typesverify- Whether to run ClassFile verificationcompilationTypes- Looks up a type of the current compilation by binary name
-
-
Method Details
-
write
Writes a top-level definition.- Parameters:
objectDef- The object definition- Returns:
- Java 17 classfile bytes
-
write
Writes a definition which is a member of the supplied outer type.- Parameters:
objectDef- The object definitionouterType- The outer type, ornullfor a top-level definition- Returns:
- Java 17 classfile bytes
-
writeAll
-
writeAll
Writes a definition and all member classes produced for it.- Parameters:
objectDef- The object definitionouterType- The outer type, ornullfor a top-level definition- Returns:
- classfile bytes keyed by binary class name
- Since:
- 2.2
-