Join Slack
Powered by
Hi guys, Is there a way of parsing Kolin code? A l...
# announcements
d
David Cuesta
07/19/2019, 6:40 AM
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
ignus
07/19/2019, 6:45 AM
Reflection API doesn't suit you?
d
David Cuesta
07/19/2019, 6:59 AM
I would like to have something like that:
https://github.com/Kotlin/grammar-tools
but it doesn't work for me
David Cuesta
07/19/2019, 7:14 AM
Now it is working for me but not in the expected manner, it doesn't return the types for example
w
wasyl
07/19/2019, 8:08 AM
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
wasyl
07/19/2019, 8:09 AM
Also Android Lint’s source code should be useful, I believe they parse Kotlin internally as well
m
Marat Akhin
07/19/2019, 9:19 AM
You could also try using one of the ANTLR grammars for Kotlin, if just parsing the code is enough for you
g
gildor
07/19/2019, 2:06 PM
Android Lint (and IDEA) uses UAST
https://github.com/JetBrains/kotlin/tree/master/plugins/uast-kotlin
Open in Slack
Previous
Next