By Interestana AI Editorial — AI-drafted, human-overseen. How we report
JetBrains Open-Sources KotlinLLM for Runtime Code Generation
JetBrains Research has open-sourced KotlinLLM, an IntelliJ IDEA plugin designed for Kotlin/JVM projects that introduces a new language feature termed "Smart macros." These Smart macros are essentially standard Kotlin function calls whose implementation is dynamically generated Kotlin code. The public API for KotlinLLM is intentionally kept minimal, featuring two primary functions: `asLlm<F, T>(from, hint)` and `mockLlm<T>()`. The `asLlm` function facilitates the conversion of an input value of type `F` into a typed value of type `T`, supporting various Kotlin data structures such as data classes, enums, lists, and primitive types. The `mockLlm` function, on the other hand, generates a stateful implementation for an interface `T`, where its behavior is contingent on the methods invoked on it. An illustrative example provided shows how `asLlm` can be used to fetch a GitHub API URL based on repository input and a hint, and subsequently to parse an API response into a list of `Issue` objects, specifically filtering for beginner-friendly issues. The core functionality of KotlinLLM revolves around a runtime loop initiated when a project is launched using the KotlinLLM run configuration. During this process, the plugin identifies `asLlm` and `mockLlm` calls within the project. It then proceeds to update generated bootstrap, provider, parser, and mock files. The plugin launches the run configuration under the Java Debug Interface (JDI) and strategically places breakpoints on generated "regenerate hooks." If the generated code logic fails to align with a runtime scenario, execution halts at one of these hooks. At this point, the plugin captures runtime values and type information from the suspended execution frame. This captured data is then sent to an LLM agent, which generates an updated code snippet. The plugin compiles this new code and redefines the loaded class in memory before retrying the original call. KotlinLLM's specific targeting of Kotlin/JVM is attributed to its reliance on JVM class redefinition via JDI for its runtime evolution loop. The plugin's development process includes an explainer that details the Smart macro API, animates the nine-step runtime loop, and models how specific scenarios can reduce inference calls. Initial reported results on an adapted Spring Petclinic Kotlin project, which contained 18 `asLlm` call sites, demonstrated that all 24 application scenarios completed successfully after the Smart macro evolution process, indicating the effectiveness of the dynamic code generation and hot-reloading capabilities.
Original source — read the full reporting at the publisher:
Read on MarkTechPostGet the weekly AI digest
AI news + new model releases, weekly. Drafted by our agents, reviewed by humans.