diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/AbstractHLInspection.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/AbstractHLInspection.kt index 8523de2ce30..bd820d5c685 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/AbstractHLInspection.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/AbstractHLInspection.kt @@ -54,7 +54,7 @@ abstract class AbstractHLInspection( val highlightType = presentation.getHighlightType(element) if (!isOnTheFly && highlightType == ProblemHighlightType.INFORMATION) return - val description = presentation.getMessage(element) + val description = applicator.getActionName(element, input) val fix = applicator.asLocalQuickFix(input, actionName = applicator.getActionName(element, input)) ranges.forEach { range -> diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLApplicator.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLApplicator.kt index 66b62a51a9d..a89468bf2b5 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLApplicator.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLApplicator.kt @@ -138,6 +138,10 @@ class HLApplicatorBuilder internal this.getActionName = getActionName } + fun actionName(getActionName: () -> String) { + this.getActionName = { _, _ -> getActionName() } + } + @OptIn(PrivateForInline::class) fun applyTo(doApply: (PSI, INPUT, Project?, Editor?) -> Unit) { applyTo = doApply diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLPresentation.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLPresentation.kt index 970298d56d3..4c7047f11fb 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLPresentation.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/applicator/HLPresentation.kt @@ -11,36 +11,25 @@ import org.jetbrains.kotlin.idea.frontend.api.ForbidKtResolve /** * Provides a presentation to display an message in the editor which may be latter fixed by [HLApplicator] - * Used by [org.jetbrains.kotlin.idea.fir.api.AbstractHLInspection] to provide higlighting message and type */ sealed class HLPresentation { fun getHighlightType(element: PSI): ProblemHighlightType = ForbidKtResolve.forbidResolveIn("HLPresentation.getHighlightType") { getHighlightTypeImpl(element) } - fun getMessage(element: PSI): String = ForbidKtResolve.forbidResolveIn("HLPresentation.getMessage") { - getMessageImpl(element) - } - - abstract fun getMessageImpl(element: PSI): String abstract fun getHighlightTypeImpl(element: PSI): ProblemHighlightType } private class HLPresentationImpl( private val getHighlightType: (element: PSI) -> ProblemHighlightType, - private val getMessage: (element: PSI) -> String, ) : HLPresentation() { override fun getHighlightTypeImpl(element: PSI): ProblemHighlightType = getHighlightType.invoke(element) - - override fun getMessageImpl(element: PSI): String = - getMessage.invoke(element) } class HLInspectionPresentationProviderBuilder internal constructor() { private var getHighlightType: ((element: PSI) -> ProblemHighlightType)? = null - private var getMessage: ((element: PSI) -> String)? = null fun highlightType(getType: (element: PSI) -> ProblemHighlightType) { getHighlightType = getType @@ -50,20 +39,10 @@ class HLInspectionPresentationProviderBuilder internal constru getHighlightType = { type } } - fun inspectionText(getText: (element: PSI) -> String) { - getMessage = getText - } - - fun inspectionText(text: String) { - getMessage = { text } - } - internal fun build(): HLPresentation { val getHighlightType = getHighlightType ?: error("Please, provide highlightType") - val getMessage = getMessage - ?: error("Please, provide getMessage") - return HLPresentationImpl(getHighlightType, getMessage) + return HLPresentationImpl(getHighlightType) } } diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt index 3981b5f3b08..0611d9c890c 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/inspections/declarations/HLRedundantUnitReturnTypeInspection.kt @@ -29,7 +29,8 @@ internal class HLRedundantUnitReturnTypeInspection : val function = callable as? KtNamedFunction ?: return@isApplicableByPsi false function.hasBlockBody() && function.typeReference != null } - familyAndActionName(KotlinBundle.lazyMessage("remove.explicit.type.specification")) + familyName(KotlinBundle.lazyMessage("remove.explicit.type.specification")) + actionName(KotlinBundle.lazyMessage("redundant.unit.return.type")) } override val inputProvider = inputProvider { function -> @@ -40,7 +41,6 @@ internal class HLRedundantUnitReturnTypeInspection : } override val presentation = presentation { - inspectionText(KotlinBundle.message("redundant.unit.return.type")) highlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL) } }