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

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

package io.gitlab.arturbosch.detekt.rules

import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
import org.jetbrains.kotlin.psi.KtValueArgument
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall

fun KtValueArgument.isString(bindingContext: BindingContext): Boolean {
    val argumentExpression = getArgumentExpression()
    return if (bindingContext != BindingContext.EMPTY) {
        val type = argumentExpression?.getResolvedCall(bindingContext)?.resultingDescriptor?.returnType
        argumentExpression is KtStringTemplateExpression || type != null && KotlinBuiltIns.isString(type)
    } else {
        argumentExpression is KtStringTemplateExpression
    }
}

fun List.isEmptyOrSingleStringArgument(bindingContext: BindingContext): Boolean =
    isEmpty() || singleOrNull()?.isString(bindingContext) == true




© 2015 - 2025 Weber Informatics LLC | Privacy Policy