Module io.github.sugarcubes.cloner
Interface BytecodeBackend
- All Known Implementing Classes:
AsmBytecodeBackend
public interface BytecodeBackend
Engine of class files: the ClassFile API of JDK 24+ or ASM. Generated copiers and copy constructors do not depend
on it: they describe fields and methods, and the code of methods is emitted by
CodeEmitter.
Code with branches needs stack map frames, which the engine computes; the code of methods added to a class must not branch, so the frames need no types of other classes.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]addMembers(byte[] bytes, List<FieldSpec> fields, List<MethodSpec> methods) Adds fields and methods to the class file, the rest of it stays as is.booleancanRead(byte[] bytes) Tells whether the engine reads the class file: a newer version than the engine knows cannot be read.read(byte[] bytes) Reads the structure of the class file.byte[]Writes a final synthetic class.
-
Method Details
-
write
byte[] write(int version, String name, String superName, List<FieldSpec> fields, List<MethodSpec> methods) Writes a final synthetic class.- Parameters:
version- class file versionname- internal name of the classsuperName- internal name of the super classfields- fieldsmethods- methods- Returns:
- class file
-
canRead
boolean canRead(byte[] bytes) Tells whether the engine reads the class file: a newer version than the engine knows cannot be read.- Parameters:
bytes- class file- Returns:
trueifread(byte[])andaddMembers(byte[], List, List)accept it
-
read
Reads the structure of the class file.- Parameters:
bytes- class file- Returns:
- structure
-
addMembers
Adds fields and methods to the class file, the rest of it stays as is.- Parameters:
bytes- class filefields- fields to addmethods- methods to add, their code does not branch- Returns:
- new class file
-