All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitlab.arturbosch.detekt.test.Nodes.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
package io.gitlab.arturbosch.detekt.test

import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtNamed
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs

inline fun  KtElement.getNodeByName(name: String): T {
    val node = getChildOfType() ?: error("Expected node of type ${T::class}")
    val identifier = node.safeAs()?.nameAsName?.identifier

    require(identifier == name) {
        "Node should be $name, but was $identifier"
    }

    return node
}

fun KtElement.getFunctionByName(name: String): KtNamedFunction = getNodeByName(name)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy