From 60fdc95ca15864c936cd4e4685d2459d6f8fcd3d Mon Sep 17 00:00:00 2001 From: Andrew Kozlov Date: Sat, 16 Mar 2024 23:33:02 +0100 Subject: [PATCH] [kotlin] KTIJ-29133 explicit platform entity used GitOrigin-RevId: 4c8e6090fd0e3e8ccab292258ac93ddc8561add0 --- .../AbstractKotlinApplicableInspectionBase.kt | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt index 465d32336166..e198eed92d7e 100644 --- a/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt +++ b/plugins/kotlin/code-insight/api/src/org/jetbrains/kotlin/idea/codeinsight/api/applicable/inspections/AbstractKotlinApplicableInspectionBase.kt @@ -3,7 +3,6 @@ package org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections import com.intellij.codeInspection.* import com.intellij.codeInspection.util.InspectionMessage -import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElementVisitor import org.jetbrains.kotlin.idea.codeinsight.api.applicable.KotlinApplicableToolBase import org.jetbrains.kotlin.psi.KtElement @@ -16,12 +15,6 @@ import org.jetbrains.kotlin.psi.KtVisitor abstract class AbstractKotlinApplicableInspectionBase : LocalInspectionTool(), KotlinApplicableToolBase { - /** - * By default, a problem is registered for every [TextRange] produced by [getApplicabilityRange]. [getProblemRanges] can be overridden - * to customize this behavior, e.g. to register a problem only for the first [TextRange]. - */ - open fun getProblemRanges(ranges: List): List = ranges - internal class ProblemInfo( val description: @InspectionMessage String, val highlightType: ProblemHighlightType, @@ -43,15 +36,18 @@ abstract class AbstractKotlinApplicableInspectionBase : Loc if (!isOnTheFly && problemInfo.highlightType == ProblemHighlightType.INFORMATION) { return } - getProblemRanges(ranges).forEach { range -> - holder.registerProblem( - element, - problemInfo.description, - problemInfo.highlightType, - range, - problemInfo.quickFix, - ) - } + + ranges.asSequence() + .map { rangeInElement -> + holder.manager.createProblemDescriptor( + /* psiElement = */ element, + /* rangeInElement = */ rangeInElement, + /* descriptionTemplate = */ problemInfo.description, + /* highlightType = */ problemInfo.highlightType, + /* onTheFly = */ isOnTheFly, + /* ...fixes = */ problemInfo.quickFix, + ) + }.forEach(holder::registerProblem) } abstract override fun buildVisitor(