From 8f78b27462eb68734dd31d562f2c99b6c18b036d Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 18 Sep 2015 13:23:43 +0300 Subject: [PATCH] Minor refactoring --- .../kotlin/idea/quickfix/AutoImportFix.kt | 29 ++++++++----------- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 6 ++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt index 92c814b48d0..83db61f0736 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt @@ -97,26 +97,21 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction? { - // There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case - val psiElement = diagnostic.getPsiElement() - if (psiElement is JetSimpleNameExpression) { - return AutoImportFix(psiElement) - } - - return null - } - - override fun isApplicableForCodeFragment() - = true + companion object : JetSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): JetIntentionAction? { + // There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case + val psiElement = diagnostic.getPsiElement() + if (psiElement is JetSimpleNameExpression) { + return AutoImportFix(psiElement) } + + return null } + override fun isApplicableForCodeFragment() = true + + private val ERRORS = setOf(Errors.UNRESOLVED_REFERENCE, Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER) + public fun computeSuggestions(element: JetSimpleNameExpression): Collection { if (!element.isValid()) return listOf() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 1901e5c8da5..ad317655f37 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -29,7 +29,6 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClas import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateLocalVariableActionFactory import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByRefActionFactory -import org.jetbrains.kotlin.idea.quickfix.migration.* import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageFix import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix import org.jetbrains.kotlin.lexer.JetTokens.* @@ -131,9 +130,8 @@ public class QuickFixRegistrar : QuickFixContributor { NO_BACKING_FIELD_CUSTOM_ACCESSORS.registerFactory(changeToPropertyNameFactory) INACCESSIBLE_BACKING_FIELD.registerFactory(changeToPropertyNameFactory) - val unresolvedReferenceFactory = AutoImportFix.createFactory() - UNRESOLVED_REFERENCE.registerFactory(unresolvedReferenceFactory) - UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(unresolvedReferenceFactory) + UNRESOLVED_REFERENCE.registerFactory(AutoImportFix) + UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(AutoImportFix) val removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory() CONFLICTING_IMPORT.registerFactory(removeImportFixFactory)