Why does calling children of KtFile trigger NoSuchMethodError?

89 Views Asked by At

I have the following code that calls children of the KtFile. When I go inside the definition of this children, I can see that it is defined in package com.intellij.psi under the method called getChildren() which returns an array of PsiElement.

import org.jetbrains.kotlin.psi.*

fun KtFile.getFunctionList(): List<KtNamedFunction> {
    val functionList = mutableListOf<KtNamedFunction>()
    children.forEach {
        if (it is KtNamedFunction) functionList.add(it)
    }
    return functionList
}

However, I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError: 'com.intellij.psi.PsiElement[] org.jetbrains.kotlin.psi.KtFile.getChildren()'
    at docGenerator.KtParserKt.getFunctionList(KtParser.kt:36)
    ...

Why is this happening?

0

There are 0 best solutions below