[kotlin] Make CreateCallableMemberFromUsageFactories as UnresolvedReferenceQuickFixFactory

When reported diagnostic element is a reference

#KTIJ-25219

GitOrigin-RevId: 63b6b68b3ed4479ed2d8c0c6175eeca982c7eec3
This commit is contained in:
Vladimir Dolzhenko
2023-04-20 12:08:13 +00:00
committed by intellij-monorepo-bot
parent 010979f3ef
commit fd6512651c
5 changed files with 11 additions and 4 deletions
@@ -33,7 +33,11 @@ class Fe10QuickFixProviderImpl : Fe10QuickFixProvider {
val first = diagnostics.first()
for (intentionActionsFactory in intentionActionsFactories) {
if ((unresolvedReferenceQuickFixOnly || replaceUnresolvedReferenceQuickFix) && intentionActionsFactory is UnresolvedReferenceQuickFixFactory) {
if (unresolvedReferenceQuickFixOnly || intentionActionsFactory.areActionsAvailable(first)) {
if (
// UnresolvedReferenceQuickFixUpdater works only when reference is available
first.psiElement.reference != null &&
(unresolvedReferenceQuickFixOnly || intentionActionsFactory.areActionsAvailable(first))
) {
actions.putValue(first, RegisterQuickFixesLaterIntentionAction)
if (unresolvedReferenceQuickFixOnly) break
continue
@@ -76,7 +76,7 @@ abstract class AbstractKotlinHighlightVisitor : HighlightVisitor {
// annotate diagnostics on fly: show diagnostics as soon as front-end reports them
// don't create quick fixes as it could require some resolve
val highlightInfoByDiagnostic = mutableMapOf<Diagnostic, HighlightInfo>()
val highlightInfoByDiagnostic = HashMap<Diagnostic, HighlightInfo>()
// render of on-fly diagnostics with descriptors could lead to recursion
fun checkIfDescriptor(candidate: Any?): Boolean =
@@ -140,7 +140,7 @@ internal abstract class ImportFixBase<T : KtExpression> protected constructor(
@IntentionName
private fun calculateText(suggestionDescriptors: Collection<DeclarationDescriptor>): String {
val descriptors =
suggestionDescriptors.mapTo(hashSetOf()) { it.original }
suggestionDescriptors.mapTo(hashSetOf()) { it.original }.takeIf { it.isNotEmpty() } ?: return ""
val ktFile = element?.containingKtFile ?: return KotlinBundle.message("fix.import")
val languageVersionSettings = ktFile.languageVersionSettings
@@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.UnresolvedReferenceQuickFixFactory
import org.jetbrains.kotlin.idea.quickfix.IntentionActionPriority
import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate
import org.jetbrains.kotlin.idea.quickfix.QuickFixWithDelegateFactory
@@ -14,7 +15,7 @@ import org.jetbrains.kotlin.psi.KtElement
abstract class CreateCallableMemberFromUsageFactory<E : KtElement>(
private val extensionsSupported: Boolean = true
) : KotlinIntentionActionFactoryWithDelegate<E, List<CallableInfo>>() {
) : KotlinIntentionActionFactoryWithDelegate<E, List<CallableInfo>>(), UnresolvedReferenceQuickFixFactory {
private fun newCallableQuickFix(
originalElementPointer: SmartPsiElementPointer<E>,
@@ -1,4 +1,6 @@
// "Import" "false"
// ACTION: Create extension function 'Some.get'
// ACTION: Create member function 'Some.get'
// ERROR: Unresolved reference: some[12]
// ERROR: No get method providing array access