https://kotlinlang.org logo
#compiler
Title
# compiler
a

Andre T

11/30/2023, 8:42 AM
I have a compiler plugin with a frontend part and a backend part. Somewhere in the frontend I'd like to get the KDoc strings of functions. With KSP this is trivial using
KSDeclaration.docString
. However, I feel it might be beneficial to avoid dragging KSP into this as well, as I probably need to then create a Gradle wrapper plugin to combine the KSP module and the regular compiler plugin module. After all, one of the benefits of going the K2 route is not having to deal with Gradle plugins. So I tried this:
Copy code
fun FirDeclaration.findKDocString(): String? = source?.let {
        val kidsRef = Ref<Array<LighterASTNode?>>()
        it.treeStructure.getChildren(it.lighterASTNode, kidsRef)
        kidsRef.get().singleOrNull { it?.tokenType == KtTokens.DOC_COMMENT }?.toString()
    }
This gave me
Copy code
Caused by: java.lang.NoClassDefFoundError: com/intellij/openapi/util/Ref
I then added various
com.jetbrains.intellij.platform
dependencies (core, util, etc.). This gets me to:
Copy code
Caused by: java.lang.NoSuchMethodError: 'com.intellij.util.diff.FlyweightCapableTreeStructure org.jetbrains.kotlin.KtSourceElement.getTreeStructure()'
Not sure how to resolve this. Seems to be a missing dependency or a version mismatch. All examples I found are basically forks of the whole compiler (with dependency graphs that are hard to figure out) but I'm trying to create a standalone plugin. I'm using
232.10227.8
as IntelliJ platform version and I'm using K2 (language version set accordingly).
2 Views