More refactoring
This commit is contained in:
@@ -75,11 +75,7 @@ class ChangeFunctionLiteralSignatureFix(
|
||||
return Data(element, descriptor, parameterTypes)
|
||||
}
|
||||
|
||||
override fun createQuickFix(diagnostic: Diagnostic, quickFixDataFactory: () -> Data?): QuickFixWithDelegateFactory? {
|
||||
return QuickFixWithDelegateFactory {
|
||||
val (functionLiteral, descriptor, parameterTypes) = quickFixDataFactory() ?: return@QuickFixWithDelegateFactory null
|
||||
ChangeFunctionLiteralSignatureFix(functionLiteral, descriptor, parameterTypes)
|
||||
}
|
||||
}
|
||||
override fun createQuickFix(data: Data)
|
||||
= ChangeFunctionLiteralSignatureFix(data.functionLiteral, data.descriptor, data.parameterTypes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,12 +88,7 @@ abstract class ChangeFunctionSignatureFix(
|
||||
return Data(element, descriptor)
|
||||
}
|
||||
|
||||
override fun createQuickFix(diagnostic: Diagnostic, quickFixDataFactory: () -> Data?): QuickFixWithDelegateFactory {
|
||||
return QuickFixWithDelegateFactory {
|
||||
val (callElement, descriptor) = quickFixDataFactory() ?: return@QuickFixWithDelegateFactory null
|
||||
createFix(callElement, callElement, descriptor)
|
||||
}
|
||||
}
|
||||
override fun createQuickFix(data: Data) = createFix(data.callElement, data.callElement, data.descriptor)
|
||||
|
||||
private fun createFix(callElement: JetCallElement, context: PsiElement, descriptor: CallableDescriptor): ChangeFunctionSignatureFix? {
|
||||
val functionDescriptor = when (descriptor) {
|
||||
|
||||
+19
-7
@@ -25,16 +25,29 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
|
||||
abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D : Any> : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
||||
protected open fun createQuickFix(diagnostic: Diagnostic, quickFixDataFactory: () -> D?): QuickFixWithDelegateFactory? = null
|
||||
abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D : Any>(
|
||||
private val isLowPriority: Boolean = false
|
||||
) : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
||||
|
||||
protected abstract fun createQuickFix(data: D): IntentionAction?
|
||||
|
||||
protected override final fun createQuickFixes(
|
||||
originalElementPointer: SmartPsiElementPointer<E>,
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> D?
|
||||
): List<QuickFixWithDelegateFactory> = createQuickFix(diagnostic, quickFixDataFactory).singletonOrEmptyList()
|
||||
): List<QuickFixWithDelegateFactory> {
|
||||
fun createAction(): IntentionAction? {
|
||||
val data = quickFixDataFactory() ?: return null
|
||||
return createQuickFix(data)
|
||||
}
|
||||
|
||||
val delegateFactory = if (isLowPriority)
|
||||
LowPriorityQuickFixWithDelegateFactory(::createAction)
|
||||
else
|
||||
QuickFixWithDelegateFactory(::createAction)
|
||||
return listOf(delegateFactory)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any> : JetIntentionActionsFactory() {
|
||||
@@ -60,9 +73,8 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any>
|
||||
// Cache data so that it can be shared between quick fixes bound to the same element & diagnostic
|
||||
// Cache null values
|
||||
var cachedData: Ref<D>? = null
|
||||
val actions: List<QuickFixWithDelegateFactory>
|
||||
try {
|
||||
actions = createQuickFixes(originalElementPointer, diagnostic) factory@ {
|
||||
val actions: List<QuickFixWithDelegateFactory> = try {
|
||||
createQuickFixes(originalElementPointer, diagnostic) factory@ {
|
||||
val element = originalElementPointer.element ?: return@factory null
|
||||
val diagnosticElement = diagnosticElementPointer.element ?: return@factory null
|
||||
if (!diagnosticElement.isValid || !element.isValid) return@factory null
|
||||
|
||||
+6
-14
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactoryWithDelegate
|
||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixWithDelegateFactory
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -31,17 +30,10 @@ data class CreateParameterData<E : JetElement>(
|
||||
)
|
||||
|
||||
abstract class CreateParameterFromUsageFactory<E : JetElement>: KotlinSingleIntentionActionFactoryWithDelegate<E, CreateParameterData<E>>() {
|
||||
override fun createQuickFix(
|
||||
diagnostic: Diagnostic,
|
||||
quickFixDataFactory: () -> CreateParameterData<E>?
|
||||
): QuickFixWithDelegateFactory? {
|
||||
return QuickFixWithDelegateFactory {
|
||||
quickFixDataFactory()?.let { data ->
|
||||
CreateParameterFromUsageFix(
|
||||
data.parameterInfo.callableDescriptor as FunctionDescriptor,
|
||||
data.parameterInfo,
|
||||
data.originalExpression)
|
||||
}
|
||||
}
|
||||
override fun createQuickFix(data: CreateParameterData<E>): IntentionAction? {
|
||||
return CreateParameterFromUsageFix(
|
||||
data.parameterInfo.callableDescriptor as FunctionDescriptor,
|
||||
data.parameterInfo,
|
||||
data.originalExpression)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user