io.gitlab.arturbosch.detekt.rules.Traversing.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-psi-utils Show documentation
Show all versions of detekt-psi-utils Show documentation
Static code analysis for Kotlin
package io.gitlab.arturbosch.detekt.rules
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.isPublic
/**
* Returns a list of all parents of type [T] before first occurrence of [S].
*/
inline fun KtElement.parentsOfTypeUntil(strict: Boolean = true) =
sequence {
var current: PsiElement? = if (strict) [email protected] else this@parentsOfTypeUntil
while (current != null && current !is S) {
if (current is T) {
yield(current)
}
current = current.parent
}
}
fun KtNamedDeclaration.isPublicInherited(): Boolean = isPublicInherited(false)
fun KtNamedDeclaration.isPublicInherited(considerProtectedAsPublic: Boolean): Boolean {
var classOrObject = containingClassOrObject
while (classOrObject != null) {
if (!classOrObject.isPublic && !(considerProtectedAsPublic && classOrObject.isProtected())) {
return false
}
classOrObject = classOrObject.containingClassOrObject
}
return true
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy