FIR IDE: remove type parameter DIAGNOSTIC_PSI
This information is already determined by `DIAGNOSTIC` so there is no need to repeat it.
This commit is contained in:
committed by
Ilya Kirillov
parent
6c52d95342
commit
f795a9c4ff
+10
-10
@@ -12,44 +12,44 @@ import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInput
|
|||||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
|
import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
|
||||||
|
|
||||||
sealed class HLDiagnosticFixFactory<DIAGNOSTIC_PSI : PsiElement, in DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>> {
|
sealed class HLDiagnosticFixFactory<in DIAGNOSTIC : KtDiagnosticWithPsi<*>> {
|
||||||
abstract fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<*, *>>
|
abstract fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<*, *>>
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HLDiagnosticFixFactoryWithFixedApplicator<DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput>(
|
private class HLDiagnosticFixFactoryWithFixedApplicator<DIAGNOSTIC : KtDiagnosticWithPsi<*>, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput>(
|
||||||
private val applicator: HLApplicator<TARGET_PSI, INPUT>,
|
private val applicator: HLApplicator<TARGET_PSI, INPUT>,
|
||||||
private val createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List<HLApplicatorTargetWithInput<TARGET_PSI, INPUT>>
|
private val createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List<HLApplicatorTargetWithInput<TARGET_PSI, INPUT>>
|
||||||
) : HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC>() {
|
) : HLDiagnosticFixFactory<DIAGNOSTIC>() {
|
||||||
override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<TARGET_PSI, INPUT>> =
|
override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<TARGET_PSI, INPUT>> =
|
||||||
createTargets.invoke(this, diagnostic).map { (target, input) -> HLQuickFix(target, input, applicator) }
|
createTargets.invoke(this, diagnostic).map { (target, input) -> HLQuickFix(target, input, applicator) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HLDiagnosticFixFactoryWithVariableApplicator<DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>>(
|
private class HLDiagnosticFixFactoryWithVariableApplicator<DIAGNOSTIC : KtDiagnosticWithPsi<*>>(
|
||||||
private val createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List<HLQuickFix<*, *>>
|
private val createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List<HLQuickFix<*, *>>
|
||||||
) : HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC>() {
|
) : HLDiagnosticFixFactory<DIAGNOSTIC>() {
|
||||||
override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<*, *>> =
|
override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List<HLQuickFix<*, *>> =
|
||||||
createQuickFixes.invoke(this, diagnostic)
|
createQuickFixes.invoke(this, diagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun <DIAGNOSTIC : KtDiagnosticWithPsi<PsiElement>> KtAnalysisSession.createPlatformQuickFixes(
|
internal fun <DIAGNOSTIC : KtDiagnosticWithPsi<PsiElement>> KtAnalysisSession.createPlatformQuickFixes(
|
||||||
diagnostic: DIAGNOSTIC,
|
diagnostic: DIAGNOSTIC,
|
||||||
factory: HLDiagnosticFixFactory<PsiElement, DIAGNOSTIC>
|
factory: HLDiagnosticFixFactory<DIAGNOSTIC>
|
||||||
): List<IntentionAction> = with(factory) { createQuickFixes(diagnostic) }
|
): List<IntentionAction> = with(factory) { createQuickFixes(diagnostic) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a [HLDiagnosticFixFactory] that creates targets and inputs ([HLApplicatorTargetWithInput]) from a diagnostic.
|
* Returns a [HLDiagnosticFixFactory] that creates targets and inputs ([HLApplicatorTargetWithInput]) from a diagnostic.
|
||||||
* The targets and inputs are consumed by the given applicator to apply fixes.
|
* The targets and inputs are consumed by the given applicator to apply fixes.
|
||||||
*/
|
*/
|
||||||
fun <DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput> diagnosticFixFactory(
|
fun <DIAGNOSTIC : KtDiagnosticWithPsi<*>, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput> diagnosticFixFactory(
|
||||||
applicator: HLApplicator<TARGET_PSI, INPUT>,
|
applicator: HLApplicator<TARGET_PSI, INPUT>,
|
||||||
createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List<HLApplicatorTargetWithInput<TARGET_PSI, INPUT>>
|
createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List<HLApplicatorTargetWithInput<TARGET_PSI, INPUT>>
|
||||||
): HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC> =
|
): HLDiagnosticFixFactory<DIAGNOSTIC> =
|
||||||
HLDiagnosticFixFactoryWithFixedApplicator(applicator, createTargets)
|
HLDiagnosticFixFactoryWithFixedApplicator(applicator, createTargets)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a [HLDiagnosticFixFactory] that creates [HLQuickFix]es from a diagnostic.
|
* Returns a [HLDiagnosticFixFactory] that creates [HLQuickFix]es from a diagnostic.
|
||||||
*/
|
*/
|
||||||
fun <DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>> diagnosticFixFactory(
|
fun <DIAGNOSTIC : KtDiagnosticWithPsi<*>> diagnosticFixFactory(
|
||||||
createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List<HLQuickFix<*, *>>
|
createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List<HLQuickFix<*, *>>
|
||||||
): HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC> =
|
): HLDiagnosticFixFactory<DIAGNOSTIC> =
|
||||||
HLDiagnosticFixFactoryWithVariableApplicator(createQuickFixes)
|
HLDiagnosticFixFactoryWithVariableApplicator(createQuickFixes)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.fir.api.fixes
|
|||||||
|
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInput
|
|
||||||
import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.PrivateForInline
|
import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.PrivateForInline
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
|
import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi
|
||||||
@@ -30,7 +29,7 @@ class KtQuickFixesList @ForKtQuickFixesListBuilder @OptIn(PrivateForInline::clas
|
|||||||
is HLQuickFixFactory.HLApplicatorBasedFactory -> {
|
is HLQuickFixFactory.HLApplicatorBasedFactory -> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val factory = quickFixFactory.applicatorFactory
|
val factory = quickFixFactory.applicatorFactory
|
||||||
as HLDiagnosticFixFactory<PsiElement, KtDiagnosticWithPsi<PsiElement>>
|
as HLDiagnosticFixFactory<KtDiagnosticWithPsi<PsiElement>>
|
||||||
createPlatformQuickFixes(diagnostic, factory)
|
createPlatformQuickFixes(diagnostic, factory)
|
||||||
}
|
}
|
||||||
is HLQuickFixFactory.HLQuickFixesPsiBasedFactory -> quickFixFactory.psiFactory.createQuickFix(diagnostic.psi)
|
is HLQuickFixFactory.HLQuickFixesPsiBasedFactory -> quickFixFactory.psiFactory.createQuickFix(diagnostic.psi)
|
||||||
@@ -66,8 +65,8 @@ class KtQuickFixesListBuilder private constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <DIAGNOSTIC_PSI : PsiElement, reified DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>> registerApplicator(
|
inline fun <reified DIAGNOSTIC : KtDiagnosticWithPsi<*>> registerApplicator(
|
||||||
quickFixFactory: HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC>
|
quickFixFactory: HLDiagnosticFixFactory<DIAGNOSTIC>
|
||||||
) {
|
) {
|
||||||
registerApplicator(DIAGNOSTIC::class, quickFixFactory)
|
registerApplicator(DIAGNOSTIC::class, quickFixFactory)
|
||||||
}
|
}
|
||||||
@@ -82,9 +81,9 @@ class KtQuickFixesListBuilder private constructor() {
|
|||||||
|
|
||||||
|
|
||||||
@PrivateForInline
|
@PrivateForInline
|
||||||
fun <DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>> registerApplicator(
|
fun <DIAGNOSTIC : KtDiagnosticWithPsi<*>> registerApplicator(
|
||||||
diagnosticClass: KClass<DIAGNOSTIC>,
|
diagnosticClass: KClass<DIAGNOSTIC>,
|
||||||
quickFixFactory: HLDiagnosticFixFactory<DIAGNOSTIC_PSI, DIAGNOSTIC>
|
quickFixFactory: HLDiagnosticFixFactory<DIAGNOSTIC>
|
||||||
) {
|
) {
|
||||||
quickFixes.getOrPut(diagnosticClass) { mutableListOf() }
|
quickFixes.getOrPut(diagnosticClass) { mutableListOf() }
|
||||||
.add(HLQuickFixFactory.HLApplicatorBasedFactory(quickFixFactory))
|
.add(HLQuickFixFactory.HLApplicatorBasedFactory(quickFixFactory))
|
||||||
@@ -105,7 +104,7 @@ sealed class HLQuickFixFactory {
|
|||||||
) : HLQuickFixFactory()
|
) : HLQuickFixFactory()
|
||||||
|
|
||||||
class HLApplicatorBasedFactory(
|
class HLApplicatorBasedFactory(
|
||||||
val applicatorFactory: HLDiagnosticFixFactory<*, *>
|
val applicatorFactory: HLDiagnosticFixFactory<*>
|
||||||
) : HLQuickFixFactory()
|
) : HLQuickFixFactory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ object ChangeTypeQuickFix {
|
|||||||
|
|
||||||
private inline fun <DIAGNOSTIC : KtDiagnosticWithPsi<KtNamedDeclaration>> changeReturnTypeOnOverride(
|
private inline fun <DIAGNOSTIC : KtDiagnosticWithPsi<KtNamedDeclaration>> changeReturnTypeOnOverride(
|
||||||
crossinline getCallableSymbol: (DIAGNOSTIC) -> KtCallableSymbol?
|
crossinline getCallableSymbol: (DIAGNOSTIC) -> KtCallableSymbol?
|
||||||
) = diagnosticFixFactory<KtNamedDeclaration, DIAGNOSTIC, KtCallableDeclaration, Input>(applicator) { diagnostic ->
|
) = diagnosticFixFactory<DIAGNOSTIC, KtCallableDeclaration, Input>(applicator) { diagnostic ->
|
||||||
val declaration = diagnostic.psi as? KtCallableDeclaration ?: return@diagnosticFixFactory emptyList()
|
val declaration = diagnostic.psi as? KtCallableDeclaration ?: return@diagnosticFixFactory emptyList()
|
||||||
val callable = getCallableSymbol(diagnostic) ?: return@diagnosticFixFactory emptyList()
|
val callable = getCallableSymbol(diagnostic) ?: return@diagnosticFixFactory emptyList()
|
||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
|
|||||||
+1
-2
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.fixes
|
package org.jetbrains.kotlin.idea.quickfix.fixes
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInput
|
import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInput
|
||||||
import org.jetbrains.kotlin.idea.fir.api.applicator.applicatorByQuickFix
|
import org.jetbrains.kotlin.idea.fir.api.applicator.applicatorByQuickFix
|
||||||
@@ -40,7 +39,7 @@ object ReplaceCallFixFactories {
|
|||||||
class Input(val notNullNeeded: Boolean) : HLApplicatorInput
|
class Input(val notNullNeeded: Boolean) : HLApplicatorInput
|
||||||
|
|
||||||
val unsafeCallFactory =
|
val unsafeCallFactory =
|
||||||
diagnosticFixFactory<PsiElement, KtFirDiagnostic.UnsafeCall> { diagnostic ->
|
diagnosticFixFactory<KtFirDiagnostic.UnsafeCall> { diagnostic ->
|
||||||
fun KtExpression.shouldHaveNotNullType(): Boolean {
|
fun KtExpression.shouldHaveNotNullType(): Boolean {
|
||||||
// This function is used to determine if we may need to add an elvis operator after the safe call. For example, to replace
|
// This function is used to determine if we may need to add an elvis operator after the safe call. For example, to replace
|
||||||
// `s.length` in `val x: Int = s.length` with a safe call, it should be replaced with `s.length ?: <caret>`.
|
// `s.length` in `val x: Int = s.length` with a safe call, it should be replaced with `s.length ?: <caret>`.
|
||||||
|
|||||||
Reference in New Issue
Block a user