FIR IDE: Enable add accessors quickfix for MUST_BE_INITIALIZED.
Also added diagnosticFixFactoriesFromIntentionActions() to share quickfix-creation across multiple diagnostics with the same PSI.
This commit is contained in:
committed by
TeamCityServer
parent
cd6dbd2515
commit
9b5f754e75
@@ -89,6 +89,16 @@ fun <DIAGNOSTIC : KtDiagnosticWithPsi<*>> diagnosticFixFactoryFromIntentionActio
|
||||
return HLDiagnosticFixFactoryUsingQuickFixActionBase(diagnosticClass, createQuickFixes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Collection] of [HLDiagnosticFixFactory] that creates [IntentionAction]s from diagnostics that have the same type of
|
||||
* [PsiElement].
|
||||
*/
|
||||
fun <DIAGNOSTIC_PSI : PsiElement, DIAGNOSTIC : KtDiagnosticWithPsi<DIAGNOSTIC_PSI>> diagnosticFixFactoriesFromIntentionActions(
|
||||
vararg diagnosticClasses: KClass<out DIAGNOSTIC>,
|
||||
createIntentionActions: KtAnalysisSession.(DIAGNOSTIC) -> List<IntentionAction>
|
||||
): Collection<HLDiagnosticFixFactory<out DIAGNOSTIC>> =
|
||||
diagnosticClasses.map { diagnosticFixFactoryFromIntentionActions(it, createIntentionActions) }
|
||||
|
||||
private class IntentionActionAsQuickFixWrapper<T : PsiElement>(val intentionAction: IntentionAction, element: T) :
|
||||
QuickFixActionBase<T>(element) {
|
||||
override fun getText(): String = intentionAction.text
|
||||
|
||||
@@ -79,7 +79,7 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
|
||||
)
|
||||
registerApplicators(InitializePropertyQuickFixFactories.initializePropertyFactory)
|
||||
registerApplicator(AddLateInitFactory.addLateInitFactory)
|
||||
registerApplicator(AddAccessorsFactories.addAccessorsToUninitializedProperty)
|
||||
registerApplicators(AddAccessorsFactories.addAccessorsToUninitializedProperty)
|
||||
}
|
||||
|
||||
private val overrides = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix.fixes
|
||||
|
||||
import org.jetbrains.kotlin.idea.fir.api.fixes.diagnosticFixFactoryFromIntentionActions
|
||||
import org.jetbrains.kotlin.idea.fir.api.fixes.diagnosticFixFactoriesFromIntentionActions
|
||||
import org.jetbrains.kotlin.idea.fir.intentions.HLAddGetterAndSetterIntention
|
||||
import org.jetbrains.kotlin.idea.fir.intentions.HLAddGetterIntention
|
||||
import org.jetbrains.kotlin.idea.fir.intentions.HLAddSetterIntention
|
||||
@@ -14,7 +14,10 @@ import org.jetbrains.kotlin.psi.KtProperty
|
||||
|
||||
object AddAccessorsFactories {
|
||||
val addAccessorsToUninitializedProperty =
|
||||
diagnosticFixFactoryFromIntentionActions(KtFirDiagnostic.MustBeInitializedOrBeAbstract::class) { diagnostic ->
|
||||
diagnosticFixFactoriesFromIntentionActions(
|
||||
KtFirDiagnostic.MustBeInitialized::class,
|
||||
KtFirDiagnostic.MustBeInitializedOrBeAbstract::class
|
||||
) { diagnostic ->
|
||||
val property: KtProperty = diagnostic.psi
|
||||
val addGetter = property.getter == null
|
||||
val addSetter = property.isVar && property.setter == null
|
||||
|
||||
@@ -4,5 +4,4 @@ class Test {
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -5,5 +5,4 @@ class Test {
|
||||
return 1
|
||||
}
|
||||
set(value) {<caret>}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -3,5 +3,4 @@
|
||||
class Test {
|
||||
var x: Int<caret>
|
||||
set(value) {}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
@@ -6,5 +6,4 @@ class Test {
|
||||
<caret>TODO()
|
||||
}
|
||||
set(value) {}
|
||||
}
|
||||
/* IGNORE_FIR */
|
||||
}
|
||||
Reference in New Issue
Block a user