Hi guys, Is there a way of parsing Kolin code? A l...
# announcements
d
Hi guys, Is there a way of parsing Kolin code? A library or something like that in order to obtain the function names, parameters, parameters types and outputs?
i
Reflection API doesn't suit you?
d
I would like to have something like that: https://github.com/Kotlin/grammar-tools but it doesn't work for me
Now it is working for me but not in the expected manner, it doesn't return the types for example
w
You can use embeddable Kotlin compiler, but I don’t see any documentation for it. You could read Detekt source code, they use it afaik: https://github.com/arturbosch/detekt/blob/master/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtCompiler.kt https://github.com/arturbosch/detekt/blob/master/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/internal/KotlinEnvironmentUtils.kt Another thing that rings the bell for me is scripting engine https://github.com/JetBrains/kotlin/tree/master/libraries/examples/kotlin-jsr223-local-example I’d love to hear someone more familiar with the topic chime in
Also Android Lint’s source code should be useful, I believe they parse Kotlin internally as well
m
You could also try using one of the ANTLR grammars for Kotlin, if just parsing the code is enough for you
g