From e9dc1e07b91c467aeb9d7b0232b97ab0de5f47ed Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Wed, 29 Jan 2020 14:34:23 +0700 Subject: [PATCH] Extract `RemoveReturnLabelFix` --- .../RedundantReturnLabelInspection.kt | 25 ++++++------------- .../idea/quickfix/RemoveReturnLabelFix.kt | 20 +++++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveReturnLabelFix.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantReturnLabelInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantReturnLabelInspection.kt index 927a9806d22..f1a3dd25be6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantReturnLabelInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantReturnLabelInspection.kt @@ -1,24 +1,22 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.inspections -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder -import com.intellij.openapi.project.Project import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.idea.quickfix.RemoveReturnLabelFix import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.returnExpressionVisitor class RedundantReturnLabelInspection : AbstractKotlinInspection() { - override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = - returnExpressionVisitor(fun(returnExpression) { + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = returnExpressionVisitor( + fun(returnExpression) { val label = returnExpression.getTargetLabel() ?: return val function = returnExpression.getParentOfType(true, KtLambdaExpression::class.java) ?: return if (function.name == null) return @@ -27,17 +25,8 @@ class RedundantReturnLabelInspection : AbstractKotlinInspection() { label, "Redundant '@$labelName'", ProblemHighlightType.LIKE_UNUSED_SYMBOL, - RemoveReturnLabelFix(labelName) + RemoveReturnLabelFix(labelName), ) - }) + }, + ) } - -private class RemoveReturnLabelFix(private val labelName: String) : LocalQuickFix { - override fun getName() = "Remove redundant '@$labelName'" - - override fun getFamilyName() = name - - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - descriptor.psiElement?.delete() - } -} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveReturnLabelFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveReturnLabelFix.kt new file mode 100644 index 00000000000..542e59dd76c --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveReturnLabelFix.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.quickfix + +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.openapi.project.Project + +class RemoveReturnLabelFix(private val labelName: String) : LocalQuickFix { + override fun getName() = "Remove redundant '@$labelName'" + + override fun getFamilyName() = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + descriptor.psiElement?.delete() + } +} \ No newline at end of file