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

io.gitlab.arturbosch.detekt.rules.ThrowExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
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