Class ByteCodeWriter
Unlike a compiler, the writer synthesizes the bridge methods a class requires itself, derived
from the declared supertypes. That derivation needs the supertype's method and generic metadata, so
a supertype should be referenced through its definition — ClassTypeDef.of(ObjectDef) for
another generated type, ClassTypeDef.of(Class) for a compiled class, or
ClassTypeDef.of(ClassElement) for a source type. A generic supertype referenced only by its
name, via ClassTypeDef.of(String), carries no such metadata: no bridges can be derived from
it, and calls through its erased signatures may fail with an AbstractMethodError at runtime.
- Since:
- 1.5
- Author:
- Denis Stepanov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Writes the bytecode of generated class.byte[]write(ObjectDef objectDef, @Nullable ClassTypeDef outerType) Writes the bytecode of generated class.voidwriteClass(org.objectweb.asm.ClassVisitor classVisitor, ClassDef classDef) Write an interface.voidwriteClass(org.objectweb.asm.ClassVisitor classVisitor, ClassDef classDef, @Nullable ClassTypeDef outerType) Write an interface.voidwriteField(org.objectweb.asm.ClassVisitor classVisitor, ObjectDef objectDef, FieldDef fieldDef) Write an enum.voidwriteInterface(org.objectweb.asm.ClassVisitor classVisitor, InterfaceDef interfaceDef, @Nullable ClassTypeDef outerType) Write an interface.voidwriteObject(org.objectweb.asm.ClassVisitor classVisitor, ObjectDef objectDef) Write an object.voidwriteObject(org.objectweb.asm.ClassVisitor classVisitor, ObjectDef objectDef, @Nullable ClassTypeDef outerType) Write an object.voidwriteRecord(org.objectweb.asm.ClassVisitor classVisitor, RecordDef recordDef) Write a record.voidwriteRecord(org.objectweb.asm.ClassVisitor classVisitor, RecordDef recordDef, @Nullable ClassTypeDef outerType) Write a record.
-
Constructor Details
-
ByteCodeWriter
public ByteCodeWriter() -
ByteCodeWriter
public ByteCodeWriter(boolean checkClass, boolean visitMaxs)
-
-
Method Details
-
writeObject
Write an object.- Parameters:
classVisitor- The class visitorobjectDef- The object definition
-
writeObject
public void writeObject(org.objectweb.asm.ClassVisitor classVisitor, ObjectDef objectDef, @Nullable ClassTypeDef outerType) Write an object.- Parameters:
classVisitor- The class visitorobjectDef- The object definitionouterType- The outer type
-
writeField
-
writeInterface
public void writeInterface(org.objectweb.asm.ClassVisitor classVisitor, InterfaceDef interfaceDef, @Nullable ClassTypeDef outerType) Write an interface.- Parameters:
classVisitor- The class visitorinterfaceDef- The interface definitionouterType- The outer type
-
writeRecord
Write a record.- Parameters:
classVisitor- The class visitorrecordDef- The record definition
-
writeRecord
public void writeRecord(org.objectweb.asm.ClassVisitor classVisitor, RecordDef recordDef, @Nullable ClassTypeDef outerType) Write a record.The components of the record are expanded the way a compiler expands them: a record component, a private final field, the canonical constructor, an accessor per component, and
equals,hashCodeandtoStringlinked throughjava.lang.runtime.ObjectMethods#bootstrap. A member the definition declares itself is kept, replacing the one that would have been generated.- Parameters:
classVisitor- The class visitorrecordDef- The record definitionouterType- The outer type
-
writeClass
Write an interface.- Parameters:
classVisitor- The class visitorclassDef- The class definition
-
writeClass
public void writeClass(org.objectweb.asm.ClassVisitor classVisitor, ClassDef classDef, @Nullable ClassTypeDef outerType) Write an interface.- Parameters:
classVisitor- The class visitorclassDef- The class definitionouterType- The outer type
-
write
Writes the bytecode of generated class.- Parameters:
objectDef- The object definition.- Returns:
- The bytes
-
write
Writes the bytecode of generated class.- Parameters:
objectDef- The object definition.outerType- The outer type.- Returns:
- The bytes
-