Problem with different versions of KtFile

I am developing a plugin for Intellij IDEA that is looking up all (Kotlin) classes of a certain type in a project and then connect to a database to make mock-data instances of these classes by adding a new Kotlin help class to be used by unit tests of the project. I am coding in Kotlin. I am using the PSI to look up these classes. Preferably I would like to work with KtFile, KtClass etc rather than raw PSI elements.

The plugin project is a gradle project. I added implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.31" (assuming I should use the same version as the plugin) to get hold of the Kotlin PSI classes. It works in the sense that I have acces to KtFile etc. However they seem to be a different version than the ones I get from the PSI. Even though inspection gives the same class name, the classes differ. They seem to have different plugin class loaders. Is there a way for me to fix this? If not, will I still be able to add a new kotlin file to the project through the PSI?

Here's the contents of my build.gradle file:

plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.11'
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
}

group 'se.winassist'
version '1.0'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.31"
testCompile group: 'junit', name: 'junit', version: '4.12'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.2.3'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}

The exception I get is the following:

java.lang.ClassCastException: class org.jetbrains.kotlin.psi.KtFile cannot be cast to class org.jetbrains.kotlin.psi.KtFile (org.jetbrains.kotlin.psi.KtFile is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @27a45ef0; org.jetbrains.kotlin.psi.KtFile is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @6c1657d1)
2

Absolutely same problem here: How did you fix this?

0

请先登录再写评论。