Minor refactoring
This commit is contained in:
@@ -97,26 +97,21 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction<Jet
|
|||||||
|
|
||||||
private fun createAction(project: Project, editor: Editor) = KotlinAddImportAction(project, editor, element, suggestions)
|
private fun createAction(project: Project, editor: Editor) = KotlinAddImportAction(project, editor, element, suggestions)
|
||||||
|
|
||||||
companion object {
|
companion object : JetSingleIntentionActionFactory() {
|
||||||
private val ERRORS = setOf(Errors.UNRESOLVED_REFERENCE, Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER)
|
override fun createAction(diagnostic: Diagnostic): JetIntentionAction<JetSimpleNameExpression>? {
|
||||||
|
// There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case
|
||||||
public fun createFactory(): JetSingleIntentionActionFactory {
|
val psiElement = diagnostic.getPsiElement()
|
||||||
return object : JetSingleIntentionActionFactory() {
|
if (psiElement is JetSimpleNameExpression) {
|
||||||
override fun createAction(diagnostic: Diagnostic): JetIntentionAction<JetSimpleNameExpression>? {
|
return AutoImportFix(psiElement)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isApplicableForCodeFragment() = true
|
||||||
|
|
||||||
|
private val ERRORS = setOf(Errors.UNRESOLVED_REFERENCE, Errors.UNRESOLVED_REFERENCE_WRONG_RECEIVER)
|
||||||
|
|
||||||
public fun computeSuggestions(element: JetSimpleNameExpression): Collection<DeclarationDescriptor> {
|
public fun computeSuggestions(element: JetSimpleNameExpression): Collection<DeclarationDescriptor> {
|
||||||
if (!element.isValid()) return listOf()
|
if (!element.isValid()) return listOf()
|
||||||
|
|
||||||
|
|||||||
@@ -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.CreateLocalVariableActionFactory
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByRefActionFactory
|
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.DeprecatedSymbolUsageFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
|
import org.jetbrains.kotlin.idea.quickfix.replaceWith.DeprecatedSymbolUsageInWholeProjectFix
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens.*
|
import org.jetbrains.kotlin.lexer.JetTokens.*
|
||||||
@@ -131,9 +130,8 @@ public class QuickFixRegistrar : QuickFixContributor {
|
|||||||
NO_BACKING_FIELD_CUSTOM_ACCESSORS.registerFactory(changeToPropertyNameFactory)
|
NO_BACKING_FIELD_CUSTOM_ACCESSORS.registerFactory(changeToPropertyNameFactory)
|
||||||
INACCESSIBLE_BACKING_FIELD.registerFactory(changeToPropertyNameFactory)
|
INACCESSIBLE_BACKING_FIELD.registerFactory(changeToPropertyNameFactory)
|
||||||
|
|
||||||
val unresolvedReferenceFactory = AutoImportFix.createFactory()
|
UNRESOLVED_REFERENCE.registerFactory(AutoImportFix)
|
||||||
UNRESOLVED_REFERENCE.registerFactory(unresolvedReferenceFactory)
|
UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(AutoImportFix)
|
||||||
UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(unresolvedReferenceFactory)
|
|
||||||
|
|
||||||
val removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory()
|
val removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory()
|
||||||
CONFLICTING_IMPORT.registerFactory(removeImportFixFactory)
|
CONFLICTING_IMPORT.registerFactory(removeImportFixFactory)
|
||||||
|
|||||||
Reference in New Issue
Block a user