Everybody knows tasks, which could be easily solved if you can generate and execute code instantly inside JVM runtime. However, sometimes you have to create separate library, so code isn’t known during its compile time.

Here we observe an approach to generate code and execute it after the application start. We will use jsr233 standard for this.

As task we use popular approach - we create AOP system to parse SQL query response, to parse the result table. So developer is able to add annotations into the code and then our application will generate and execute the parser code in the runtime. However, this approach is much wider. You can create programmable configuration (like TeamCity Build DSL), you can optimize the existing code (the generated code can be constructed after settings reading, so it will be branch-free). And of course we can use this approach to avoid copy-paste in case when the language expressive power isn’t enough to extract the generalized block.

#spring #kotlin #jdbc #dsl #compiler #runtime

Compiling Kotlin in Runtime
16.70 GEEK