io.gitlab.arturbosch.detekt.rules.ThrowExtensions.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.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtContainerNodeForControlStructureBody
import org.jetbrains.kotlin.psi.KtThrowExpression
import org.jetbrains.kotlin.psi.KtValueArgument
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
fun KtThrowExpression.isIllegalStateException() =
isExceptionOfType()
fun KtThrowExpression.isIllegalArgumentException() =
isExceptionOfType()
inline fun KtThrowExpression.isExceptionOfType(): Boolean {
return findDescendantOfType()?.firstChild?.text == T::class.java.simpleName
}
val KtThrowExpression.arguments: List
get() = findDescendantOfType()?.valueArguments.orEmpty()
fun KtThrowExpression.isEnclosedByConditionalStatement(): Boolean {
return when (parent) {
is KtContainerNodeForControlStructureBody -> true
is KtBlockExpression -> parent.parent is KtContainerNodeForControlStructureBody
else -> false
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy