<@U4UGS5FC7> Re metaprogramming: I'm working on an...
# compiler
t
@raulraja Re metaprogramming: I'm working on an annotation processing library for Kotlin but that is probably not powerful enough for you. In any case, kotlinx-metadata is a lot more stable than the compiler itself.
r
I’d love to look at it if its public
thanks
t
Unfortunately there's not much to look at right now since the library is very much work-in-progress and I'm in the middle of a major refactoring right now, but you can look at this branch to get an idea how it will look: https://github.com/tschuchortdev/kotlin-elements/blob/joint_language_model/lib/src/main/kotlin/com/tschuchort/kotlinelements/KJElements.kt Basically it's going to be like a more sane version of the Javax Element & TypeMirror API but for Kotlin with more type safety and discoverability. Also, instead of modeling the Kotlin syntax verbatim the AST will be somewhat of a union of the Kotlin and Java syntax so a single code base can work for both Java and Kotlin code while still understanding Kotlin's additional syntactic features (like null-safety, properties, etc.). Java code will appear to you like it does when you call it from Kotlin code (i.e.
get
and
set
functions are "converted" to properties, Java types become platform types and so on). It will be possible to start with an existing Java annotation processor and migrate only those functions where you are actually interested in Kotlin features (and you can always go back from KJ-AST to regular Javax Elements/TypeMirrors). Of course it will never be as powerful as compiler plugin or manually parsing Kotlin code but it has the huge advantage of compatibility with existing annotation processor code.
You may also be interested in this compile testing library for Kotlin which is production ready: https://github.com/tschuchortdev/kotlin-compile-testing
r
that is awesome, kotlin-compile-testing will be awesome in our processors because we have to test codegen of the compiler plugin
t
I'd be honored if you use the library in such a popular open source project. Let me know if you find any bugs.
r
I’ll ping you when we come to that point testing our first plugin codegen