[BUG] org.jetbrains.uast.UastUtils.findContaining() Unable to recognize Kotlin class in Kotlin multiplatform


Steps to reproduce

1. I have a project which has the following structure

It can be accessed from here https://github.com/user-attachments/files/15753275/kt-multiplatform-example.zip

2. Use the following code to access these two class elements.

String fileText = psiFile.getText();
int offset = fileText.contains("class") ? fileText.indexOf("class") : fileText.indexOf("record");
if (offset < 0) {
    Notifier.notifyWarn("Can't find class scope.", project);
PsiElement elementAt = psiFile.findElementAt(offset);
UElement uElement = UastUtils.findContaining(elementAt, UClass.class);

3. For all `.kt` files in folder `jvmMain`, function `org.jetbrains.uast.UastUtils.findContaining()` can find UElement. But for all `.kt` files in folder `commonMain`, this function will only return NULL.

They are all `.kt` files, have the same structure, and have a complete Kotlin environment, but why this the case?




This is expected behavior. UAST works only for JVM languages. In the case of Kotlin, it will work only for JVM targets.


Thank you for reply. But I still don't quite understand.

The Kotlin files in the `commonMain` folder are not considered JVM languages?



I've got information that it should work for common code too, when JVM platform is present. If this is the case, please create an issue at https://youtrack.jetbrains.com/issues/IDEA.