io.gitlab.arturbosch.detekt.test.Nodes.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-test Show documentation
Show all versions of detekt-test Show documentation
Static code analysis for Kotlin
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