Is there an official jetbrains library to get an A...
# announcements
r
Is there an official jetbrains library to get an AST out of a Kotlin file?
c
The compiler itself should be able to be used as a library to get an AST. I’m pretty sure that’s how ktlint works https://github.com/pinterest/ktlint#ast
Dokka does the same, too, at least with the previous version, when i was digging into it. It was completely rewritten in Dokka 1.4, but it’s probably still doing the same thing: embedding the Kotlin compiler and using it like a library to get an AST
r
Thanks, do you know if the resulting AST is considered to be stable? Or might it change with every patch release?
And is there some documentation for the API? I find a lot about compiler plugins but couldn't find the docs for the compiler itself
in case someone else is looking for how ktlint does it, I guess the following is a good starting point https://github.com/pinterest/ktlint/blob/6c997771ff8eb518cb967674974ef17b3fdaa786/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt#L125