Convert RemoveReturnLabelFix from LocalQuickFix to KotlinQuickFixAction
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeInspection.IntentionWrapper
|
||||
import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
@@ -25,7 +26,7 @@ class RedundantReturnLabelInspection : AbstractKotlinInspection() {
|
||||
label,
|
||||
"Redundant '@$labelName'",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
RemoveReturnLabelFix(labelName),
|
||||
IntentionWrapper(RemoveReturnLabelFix(returnExpression), returnExpression.containingKtFile),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -5,16 +5,25 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix
|
||||
import com.intellij.codeInspection.ProblemDescriptor
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
|
||||
class RemoveReturnLabelFix(private val labelName: String) : LocalQuickFix {
|
||||
override fun getName() = "Remove redundant '@$labelName'"
|
||||
class RemoveReturnLabelFix(element: KtReturnExpression) : KotlinQuickFixAction<KtReturnExpression>(element) {
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
element?.labeledExpression?.delete()
|
||||
}
|
||||
|
||||
override fun getFamilyName() = name
|
||||
override fun getFamilyName(): String = "Remove redundant label"
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
descriptor.psiElement?.delete()
|
||||
override fun getText(): String = "Remove redundant ${element?.getLabelName()?.let { "'@$it'" } ?: "label"}"
|
||||
|
||||
companion object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtReturnExpression>? {
|
||||
val returnExpression = diagnostic.psiElement as? KtReturnExpression ?: return null
|
||||
return RemoveReturnLabelFix(returnExpression)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user