Reformat: simplifiable call chain inspection
This commit is contained in:
+8
-7
@@ -20,8 +20,6 @@ import org.jetbrains.kotlin.types.typeUtil.builtIns
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||||
|
|
||||||
class SimplifiableCallChainInspection : AbstractKotlinInspection() {
|
class SimplifiableCallChainInspection : AbstractKotlinInspection() {
|
||||||
|
|
||||||
|
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
||||||
qualifiedExpressionVisitor(fun(expression) {
|
qualifiedExpressionVisitor(fun(expression) {
|
||||||
val firstExpression = expression.receiverExpression
|
val firstExpression = expression.receiverExpression
|
||||||
@@ -48,7 +46,8 @@ class SimplifiableCallChainInspection : AbstractKotlinInspection() {
|
|||||||
val firstReceiverRawType = firstReceiverType?.constructor?.declarationDescriptor?.defaultType
|
val firstReceiverRawType = firstReceiverType?.constructor?.declarationDescriptor?.defaultType
|
||||||
if (firstReceiverRawType != null) {
|
if (firstReceiverRawType != null) {
|
||||||
if (firstReceiverRawType.isSubtypeOf(builtIns.map.defaultType) ||
|
if (firstReceiverRawType.isSubtypeOf(builtIns.map.defaultType) ||
|
||||||
firstReceiverRawType.isSubtypeOf(builtIns.mutableMap.defaultType)) return
|
firstReceiverRawType.isSubtypeOf(builtIns.mutableMap.defaultType)
|
||||||
|
) return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not apply for lambdas with return inside
|
// Do not apply for lambdas with return inside
|
||||||
@@ -61,13 +60,15 @@ class SimplifiableCallChainInspection : AbstractKotlinInspection() {
|
|||||||
if (secondResolvedCall.valueArguments.any { (parameter, resolvedArgument) ->
|
if (secondResolvedCall.valueArguments.any { (parameter, resolvedArgument) ->
|
||||||
parameter.type.isFunctionOfAnyKind() &&
|
parameter.type.isFunctionOfAnyKind() &&
|
||||||
resolvedArgument !is DefaultValueArgument
|
resolvedArgument !is DefaultValueArgument
|
||||||
}) return
|
}
|
||||||
|
) return
|
||||||
|
|
||||||
if (conversion.replacement.startsWith("joinTo")) {
|
if (conversion.replacement.startsWith("joinTo")) {
|
||||||
// Function parameter in map must have String result type
|
// Function parameter in map must have String result type
|
||||||
if (!firstResolvedCall.hasLastFunctionalParameterWithResult(context) {
|
if (!firstResolvedCall.hasLastFunctionalParameterWithResult(context) {
|
||||||
it.isSubtypeOf(builtIns.charSequence.defaultType)
|
it.isSubtypeOf(builtIns.charSequence.defaultType)
|
||||||
}) return
|
}
|
||||||
|
) return
|
||||||
}
|
}
|
||||||
|
|
||||||
val descriptor = holder.manager.createProblemDescriptor(
|
val descriptor = holder.manager.createProblemDescriptor(
|
||||||
@@ -120,8 +121,8 @@ class SimplifiableCallChainInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCallExpression(firstExpression: KtExpression) =
|
fun getCallExpression(firstExpression: KtExpression) =
|
||||||
((firstExpression as? KtQualifiedExpression)?.selectorExpression as? KtCallExpression
|
(firstExpression as? KtQualifiedExpression)?.selectorExpression as? KtCallExpression
|
||||||
?: firstExpression as? KtCallExpression)
|
?: firstExpression as? KtCallExpression
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user