Is Kotlin code interoperable to Java? Reason I am ...
# getting-started
n
Is Kotlin code interoperable to Java? Reason I am asking is that java has a framework called checkerframework. This only work for Java source compilation. Is there a similar tool for Kotlin ? (in terms of a framework that can perform checks on Kotlin source compilation) Is a tool like checkerframework able to work on Kotlin compilation? From what I know checkerframework uses Java AST libraries. Hence the reason why it doesn't work with Kotlin source compilation. However, I was thinking if it is possible to have Kotlin source compile to JVM bytecode, and then decompile to Java classes for checkerframework to run against these classes. But then again, decompiling JVM bytecode will produce classes and classes are not the type of data Java AST library is expecting.
s
the approach of compiling Kotlin to bytecode and then decompiling it to Java code is what Kapt did. So it's possible, but someone would have to do the work. (And it would be a lot of work, not something to put together in 5min) Nowadays it would probably make more sense to build on KSP to work with the Kotlin AST directly, instead of taking the slower, less precise route via compilation/decompilation (Disclaimer: I don't know what checkerframework does, so KSP might not be powerfull enough to suport it).
n
from what i understand checkerframework is a tool that allows 'checkers' to be plugged to the Java source compile time. Checkerframework relies on Java AST package to allow checker to perform checks on the Java source code. I did explore Kapt and KSP as a solution to perform certain checks on Kotlin source compilation. However there are limitations faced during that. One of the biggest challenge faced was that KSP does have its limitation such as not being able to examine expression-level information of source code. Also KSP and KAPT APIs & support are differs across multiple Kotlin versions. Can I ask how stable is Kotlin PSI? (in terms of it being more or less the same throughout Kotlin versions).
d
PSI is more or less stable, but K2 compiler doesn't use it
l
Would a #detekt rule do what you need?
n
I will take a look at detekt