[英]How can I modify PSI of Kotlin?
I'm trying to create a plugin for IntelliJ IDEA that functions similarly to lombok.我正在尝试为 IntelliJ IDEA 创建一个功能类似于 lombok 的插件。
This is what I'm trying to do, with an existing interface:这是我正在尝试使用现有界面执行的操作:
interface TestInterface {
var testProperty: Int
}
I want to modify the PSI so that the IntelliJ IDEA can recognize it as:我想修改 PSI 以便 IntelliJ IDEA 可以将其识别为:
interface TestInterface {
var testProperty: Int
companion object: TestInterface {
override var testProperty: Int
get() {
TODO("Do something")
}
set(value) {
TODO("Do something")
}
}
}
With kapt, I can achieve the functions I want, and here is my code: Github , but it dosen't work.使用kapt,我可以实现我想要的功能,这是我的代码: Github ,但它不起作用。
Could you help me to solve this problem?你能帮我解决这个问题吗? Thank you!
谢谢!
After communicating with the IDEA team, I got the following information:与IDEA团队沟通后,得到如下信息:
Hi, Unfortunately.
嗨,不幸的是。 generating the Kotlin PSI on the fly for use by the Kotlin resolve is impossible, Java resolution in the IDE uses PSI to resolve things.
即时生成 Kotlin PSI 供 Kotlin 解析使用是不可能的,IDE 中的 Java 解析使用 PSI 来解析事物。 and that's why it works for Java, Kotlin resolution in the IDE uses the Kotlin compiler.
这就是为什么它适用于 Java,IDE 中的 Kotlin 分辨率使用 Kotlin 编译器。 so creating PSI on the fly and using PsiAugmentProvider will not work.
因此即时创建 PSI 和使用 PsiAugmentProvider 将不起作用。
To sum up, if you want to achieve a function similar to Lombok plugin, you cannot use the method of editing PSI.综上所述,如果想实现一个类似Lombok插件的function,不能使用编辑PSI的方法。 Then I found a feasible method based on the above information, that is KSP: https://kotlinlang.org/docs/ksp-overview.html
然后根据以上信息找到了一个可行的方法,就是KSP: https://kotlinlang.org/docs/ksp-overview.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.