diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt index 9cf45f0f7d5..0afc8807257 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/IntentionBasedInspection.kt @@ -17,10 +17,7 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.codeInspection.LocalInspectionToolSession -import com.intellij.codeInspection.LocalQuickFixOnPsiElement -import com.intellij.codeInspection.ProblemHighlightType -import com.intellij.codeInspection.ProblemsHolder +import com.intellij.codeInspection.* import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.EditorFactory import com.intellij.openapi.fileEditor.FileDocumentManager @@ -47,6 +44,10 @@ abstract class IntentionBasedInspection( val additionalChecker: (TElement) -> Boolean = { true } ) + open fun additionalFixes(element: TElement): List? = null + + open fun inspectionRange(element: TElement): TextRange? = null + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor { return object : PsiElementVisitor() { override fun visitElement(element: PsiElement) { @@ -56,7 +57,7 @@ abstract class IntentionBasedInspection( val targetElement = element as TElement var problemRange: TextRange? = null - var fixes: SmartList>? = null + var fixes: SmartList? = null for ((intention, additionalChecker) in intentions) { synchronized(intention) { @@ -69,15 +70,21 @@ abstract class IntentionBasedInspection( if (range != null && additionalChecker(targetElement)) { problemRange = problemRange?.union(range) ?: range if (fixes == null) { - fixes = SmartList>() + fixes = SmartList() } fixes!!.add(IntentionBasedQuickFix(intention, intention.text, additionalChecker, targetElement)) } } } - if (problemRange != null) { - holder.registerProblem(targetElement, problemText ?: fixes!!.first().name, problemHighlightType, problemRange, *fixes!!.toTypedArray()) + val range = inspectionRange(targetElement) ?: problemRange + if (range != null) { + val allFixes = fixes ?: SmartList() + additionalFixes(targetElement)?.let { allFixes.addAll(it) } + if (!allFixes.isEmpty()) { + holder.registerProblem(targetElement, problemText ?: allFixes.first().name, + problemHighlightType, range, *allFixes.toTypedArray()) + } } } }