diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/HLDiagnosticFixFactory.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/HLDiagnosticFixFactory.kt index d9a1d71defd..ef36a337c85 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/HLDiagnosticFixFactory.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/HLDiagnosticFixFactory.kt @@ -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.diagnostics.KtDiagnosticWithPsi -sealed class HLDiagnosticFixFactory> { +sealed class HLDiagnosticFixFactory> { abstract fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List> } -private class HLDiagnosticFixFactoryWithFixedApplicator, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput>( +private class HLDiagnosticFixFactoryWithFixedApplicator, TARGET_PSI : PsiElement, INPUT : HLApplicatorInput>( private val applicator: HLApplicator, private val createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List> -) : HLDiagnosticFixFactory() { +) : HLDiagnosticFixFactory() { override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List> = createTargets.invoke(this, diagnostic).map { (target, input) -> HLQuickFix(target, input, applicator) } } -private class HLDiagnosticFixFactoryWithVariableApplicator>( +private class HLDiagnosticFixFactoryWithVariableApplicator>( private val createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List> -) : HLDiagnosticFixFactory() { +) : HLDiagnosticFixFactory() { override fun KtAnalysisSession.createQuickFixes(diagnostic: DIAGNOSTIC): List> = createQuickFixes.invoke(this, diagnostic) } internal fun > KtAnalysisSession.createPlatformQuickFixes( diagnostic: DIAGNOSTIC, - factory: HLDiagnosticFixFactory + factory: HLDiagnosticFixFactory ): List = with(factory) { createQuickFixes(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. */ -fun , TARGET_PSI : PsiElement, INPUT : HLApplicatorInput> diagnosticFixFactory( +fun , TARGET_PSI : PsiElement, INPUT : HLApplicatorInput> diagnosticFixFactory( applicator: HLApplicator, createTargets: KtAnalysisSession.(DIAGNOSTIC) -> List> -): HLDiagnosticFixFactory = +): HLDiagnosticFixFactory = HLDiagnosticFixFactoryWithFixedApplicator(applicator, createTargets) /** * Returns a [HLDiagnosticFixFactory] that creates [HLQuickFix]es from a diagnostic. */ -fun > diagnosticFixFactory( +fun > diagnosticFixFactory( createQuickFixes: KtAnalysisSession.(DIAGNOSTIC) -> List> -): HLDiagnosticFixFactory = +): HLDiagnosticFixFactory = HLDiagnosticFixFactoryWithVariableApplicator(createQuickFixes) diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/KtQuickFixesList.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/KtQuickFixesList.kt index 54e6f0eca77..315513438e1 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/KtQuickFixesList.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/api/fixes/KtQuickFixesList.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.fir.api.fixes import com.intellij.codeInsight.intention.IntentionAction 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.frontend.api.KtAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi @@ -30,7 +29,7 @@ class KtQuickFixesList @ForKtQuickFixesListBuilder @OptIn(PrivateForInline::clas is HLQuickFixFactory.HLApplicatorBasedFactory -> { @Suppress("UNCHECKED_CAST") val factory = quickFixFactory.applicatorFactory - as HLDiagnosticFixFactory> + as HLDiagnosticFixFactory> createPlatformQuickFixes(diagnostic, factory) } is HLQuickFixFactory.HLQuickFixesPsiBasedFactory -> quickFixFactory.psiFactory.createQuickFix(diagnostic.psi) @@ -66,8 +65,8 @@ class KtQuickFixesListBuilder private constructor() { } @OptIn(PrivateForInline::class) - inline fun > registerApplicator( - quickFixFactory: HLDiagnosticFixFactory + inline fun > registerApplicator( + quickFixFactory: HLDiagnosticFixFactory ) { registerApplicator(DIAGNOSTIC::class, quickFixFactory) } @@ -82,9 +81,9 @@ class KtQuickFixesListBuilder private constructor() { @PrivateForInline - fun > registerApplicator( + fun > registerApplicator( diagnosticClass: KClass, - quickFixFactory: HLDiagnosticFixFactory + quickFixFactory: HLDiagnosticFixFactory ) { quickFixes.getOrPut(diagnosticClass) { mutableListOf() } .add(HLQuickFixFactory.HLApplicatorBasedFactory(quickFixFactory)) @@ -105,7 +104,7 @@ sealed class HLQuickFixFactory { ) : HLQuickFixFactory() class HLApplicatorBasedFactory( - val applicatorFactory: HLDiagnosticFixFactory<*, *> + val applicatorFactory: HLDiagnosticFixFactory<*> ) : HLQuickFixFactory() } diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt index b7e081c2621..abdffb60005 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ChangeReturnTypeOnOverrideQuickFix.kt @@ -86,7 +86,7 @@ object ChangeTypeQuickFix { private inline fun > changeReturnTypeOnOverride( crossinline getCallableSymbol: (DIAGNOSTIC) -> KtCallableSymbol? - ) = diagnosticFixFactory(applicator) { diagnostic -> + ) = diagnosticFixFactory(applicator) { diagnostic -> val declaration = diagnostic.psi as? KtCallableDeclaration ?: return@diagnosticFixFactory emptyList() val callable = getCallableSymbol(diagnostic) ?: return@diagnosticFixFactory emptyList() listOfNotNull( diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ReplaceCallFixFactories.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ReplaceCallFixFactories.kt index 1614a0ab76f..c714354c609 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ReplaceCallFixFactories.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/quickfix/fixes/ReplaceCallFixFactories.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.idea.quickfix.fixes -import com.intellij.psi.PsiElement import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInput import org.jetbrains.kotlin.idea.fir.api.applicator.applicatorByQuickFix @@ -40,7 +39,7 @@ object ReplaceCallFixFactories { class Input(val notNullNeeded: Boolean) : HLApplicatorInput val unsafeCallFactory = - diagnosticFixFactory { diagnostic -> + diagnosticFixFactory { diagnostic -> 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 // `s.length` in `val x: Int = s.length` with a safe call, it should be replaced with `s.length ?: `.