From c183f0285d69cc5bbfcd614d69b622b31fc31026 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sat, 2 Feb 2019 20:50:38 +0900 Subject: [PATCH] Reformat ReplaceRangeToWithUntilInspection --- .../ReplaceRangeToWithUntilInspection.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 {