diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceRangeToWithUntilInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceRangeToWithUntilInspection.kt index a91c86d4ac6..729718118e5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceRangeToWithUntilInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceRangeToWithUntilInspection.kt @@ -29,20 +29,18 @@ import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.createExpressionByPattern class ReplaceRangeToWithUntilInspection : AbstractPrimitiveRangeToInspection() { - override fun visitRangeToExpression(expression: KtExpression, holder: ProblemsHolder) { if (expression.getArguments()?.second?.isMinusOne() != true) return holder.registerProblem( - expression, - "'rangeTo' or the '..' call should be replaced with 'until'", - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - ReplaceWithUntilQuickFix() + expression, + "'rangeTo' or the '..' call should be replaced with 'until'", + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + ReplaceWithUntilQuickFix() ) } class ReplaceWithUntilQuickFix : LocalQuickFix { - override fun getName() = "Replace with until" override fun getFamilyName() = name @@ -50,13 +48,14 @@ class ReplaceRangeToWithUntilInspection : AbstractPrimitiveRangeToInspection() { override fun applyFix(project: Project, descriptor: ProblemDescriptor) { val element = descriptor.psiElement as KtExpression val args = element.getArguments() ?: return - element.replace(KtPsiFactory(element).createExpressionByPattern( + element.replace( + KtPsiFactory(element).createExpressionByPattern( "$0 until $1", args.first ?: return, - (args.second as? KtBinaryExpression)?.left ?: return) + (args.second as? KtBinaryExpression)?.left ?: return + ) ) } - } private fun KtExpression.isMinusOne(): Boolean {