FIR IDE: remove getMessage from HLPresentation as it duplicates HLApplicator.getActionName
This commit is contained in:
@@ -54,7 +54,7 @@ abstract class AbstractHLInspection<PSI : KtElement, INPUT : HLApplicatorInput>(
|
||||
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 ->
|
||||
|
||||
@@ -138,6 +138,10 @@ class HLApplicatorBuilder<PSI : PsiElement, INPUT : HLApplicatorInput> internal
|
||||
this.getActionName = getActionName
|
||||
}
|
||||
|
||||
fun actionName(getActionName: () -> String) {
|
||||
this.getActionName = { _, _ -> getActionName() }
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
fun applyTo(doApply: (PSI, INPUT, Project?, Editor?) -> Unit) {
|
||||
applyTo = doApply
|
||||
|
||||
@@ -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<PSI : PsiElement> {
|
||||
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<PSI : PsiElement>(
|
||||
private val getHighlightType: (element: PSI) -> ProblemHighlightType,
|
||||
private val getMessage: (element: PSI) -> String,
|
||||
) : HLPresentation<PSI>() {
|
||||
override fun getHighlightTypeImpl(element: PSI): ProblemHighlightType =
|
||||
getHighlightType.invoke(element)
|
||||
|
||||
override fun getMessageImpl(element: PSI): String =
|
||||
getMessage.invoke(element)
|
||||
}
|
||||
|
||||
|
||||
class HLInspectionPresentationProviderBuilder<PSI : PsiElement> 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<PSI : PsiElement> internal constru
|
||||
getHighlightType = { type }
|
||||
}
|
||||
|
||||
fun inspectionText(getText: (element: PSI) -> String) {
|
||||
getMessage = getText
|
||||
}
|
||||
|
||||
fun inspectionText(text: String) {
|
||||
getMessage = { text }
|
||||
}
|
||||
|
||||
internal fun build(): HLPresentation<PSI> {
|
||||
val getHighlightType = getHighlightType
|
||||
?: error("Please, provide highlightType")
|
||||
val getMessage = getMessage
|
||||
?: error("Please, provide getMessage")
|
||||
return HLPresentationImpl(getHighlightType, getMessage)
|
||||
return HLPresentationImpl(getHighlightType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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<KtNamedFunction, CallableReturnTypeUpdaterApplicator.Type> { function ->
|
||||
@@ -40,7 +41,6 @@ internal class HLRedundantUnitReturnTypeInspection :
|
||||
}
|
||||
|
||||
override val presentation = presentation<KtNamedFunction> {
|
||||
inspectionText(KotlinBundle.message("redundant.unit.return.type"))
|
||||
highlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user