Hey folks, TL;DR: I want to modify kotlin source ...
# compiler
s
Hey folks, TL;DR: I want to modify kotlin source in-place but it's proving difficult using kotlin compiler tools. -- I'm trying to create a mutation of a
kt
file/code, such that the rest of the content remains the same, and only specific mutations that I want to add get processed. I want to update the code in-place, as a form of auto-correction, I would like this to happen using the Psi visitor. I have tried using compiler embeddable & a PsiFactory to create an expression, and then call
expression.replace()
. in my
visit*()
function. The code breaks in runtime with:
Copy code
Missing extension point: org.jetbrains.kotlin.com.intellij.treeCopyHandler in container {}
I've seen comments about that error, and the seem to imply that the PSI tree is immutable, so I can't modify it (perhaps because I'm not in the IDE context). My ideal case would be to run this piece of code, define the mutation I want to apply, and a target kotlin file, and it modifies the file in-place. -- Is there any advise on how to approach this?
I was able to achieve this using ANTLR & the Kotlin grammar. I guess there was a fundamental flaw in my initial approach. Compilation stage is too late to modify the source being compiled, so the lexing/parsing stage makes more sense, and it works very smoothly with ANTLR
K 1