What is
Kores Framework (named as CodeAPI earlier) is a library that provides AST (Abstract Syntax Tree) for Java and JVM classes and modules. With Kores AST Definitions you can produce Java Source Code using Kores-SourceWriter transpiler and JVM Bytecode using Kores-BytecodeWriter compiler.
Why?
Initially, Kores was a toy project to learn JVM Bytecode and create a common structure for compile-time and runtime code generation, focused on Annotation Processors. Later, Kores evolved to more likely a JVM Bytecode compiler ecosystem, more focused on JVM Bytecode Generation than in Java Source Generation.
Kores bytecode generation module tries to generate bytecode as close as possible to javac, with some exceptions, like not generating inner class definition for every used inner class as specified in second paragraph of JVMS 4.7.6. There is likely no popular JVM Implementation that does check for this (or no one of them check at all) or use this kind of information for something in fact, this is only a specification that is followed by javac.
Projects that uses Kores
-
- A dynamic property base event system written on top of Kores
-
- A Proxy generator written on top of Kores, the key difference between Java proxies is that CodeProxies can extend classes.
-
- A set of utilities to help with creation, registration and management of Adapters, some features requires Kores, such as deep instance adapting.
-
- A proof-of-concept language that implements type-reification, traits, rules, and so on.
Applications
Kores could be used in compilers, runtime code generators, compile-time code generators (and mixed generators through the common AST). However, Kores is not focused on providing instrumentation of already compiled classes. There was an attempt to provide this functionality through Kores-BytecodeReader but maintenance and implementation stopped to focus on code generation.
Also, Kores AST could be serialized and deserialized using Kotlinx Serialization Library, providing easy way to compilers store and retrieve metadata about classes, including method inlining and Type Reification without Bytecode Manipulation.