ReplaceJavaStaticMethodWithKotlinAnalogInspection: rename isApplicable(call, context) to isApplicableInContext

This commit is contained in:
Dmitry Gridin
2019-07-10 11:14:14 +03:00
parent 71c0b3caa0
commit 82bf21f195
2 changed files with 10 additions and 4 deletions
@@ -31,7 +31,12 @@ class ReplaceJavaStaticMethodWithKotlinAnalogInspection : AbstractKotlinInspecti
?.let { list ->
val context = call.analyze(BodyResolveMode.PARTIAL)
val callDescriptor = call.getResolvedCall(context) ?: return
list.filter { callDescriptor.isCalling(FqName(it.javaMethodFqName)) && it.transformation.isApplicable(call, context) }
list.filter {
callDescriptor.isCalling(FqName(it.javaMethodFqName)) && it.transformation.isApplicableInContext(
call,
context
)
}
}
?.takeIf { it.isNotEmpty() }
?.map(::ReplaceWithKotlinAnalogFunction)
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.types.isNullable
interface Transformation {
operator fun invoke(callExpression: KtCallExpression, replacement: Replacement)
fun isApplicable(callExpression: KtCallExpression): Boolean = true
fun isApplicable(callExpression: KtCallExpression, context: BindingContext): Boolean = true
fun isApplicableInContext(callExpression: KtCallExpression, context: BindingContext): Boolean = true
}
object WithoutAdditionalTransformation : Transformation {
@@ -55,7 +55,7 @@ object ToExtensionFunctionWithNonNullableReceiver : Transformation {
override fun isApplicable(callExpression: KtCallExpression): Boolean = callExpression.valueArguments.isNotEmpty()
override fun isApplicable(callExpression: KtCallExpression, context: BindingContext): Boolean = callExpression
override fun isApplicableInContext(callExpression: KtCallExpression, context: BindingContext): Boolean = callExpression
.valueArguments.firstOrNull()
?.getArgumentExpression()
?.getType(context)
@@ -72,7 +72,8 @@ object ToExtensionFunctionWithNonNullableArguments : Transformation {
callExpression
)
override fun isApplicable(callExpression: KtCallExpression, context: BindingContext): Boolean = callExpression.valueArguments.all {
override fun isApplicableInContext(callExpression: KtCallExpression, context: BindingContext): Boolean = callExpression
.valueArguments.all {
it.getArgumentExpression()?.getType(context)?.isNullable() == false
}
}