Renames
This commit is contained in:
@@ -69,13 +69,13 @@ class ChangeFunctionLiteralSignatureFix(
|
|||||||
return diagnosticWithParameters.psiElement as? JetFunctionLiteral
|
return diagnosticWithParameters.psiElement as? JetFunctionLiteral
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetFunctionLiteral, diagnostic: Diagnostic): Data? {
|
override fun extractFixData(element: JetFunctionLiteral, diagnostic: Diagnostic): Data? {
|
||||||
val descriptor = element.resolveToDescriptor() as? FunctionDescriptor ?: return null
|
val descriptor = element.resolveToDescriptor() as? FunctionDescriptor ?: return null
|
||||||
val parameterTypes = Errors.EXPECTED_PARAMETERS_NUMBER_MISMATCH.cast(diagnostic).b
|
val parameterTypes = Errors.EXPECTED_PARAMETERS_NUMBER_MISMATCH.cast(diagnostic).b
|
||||||
return Data(element, descriptor, parameterTypes)
|
return Data(element, descriptor, parameterTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFix(data: Data)
|
override fun createFix(data: Data)
|
||||||
= ChangeFunctionLiteralSignatureFix(data.functionLiteral, data.descriptor, data.parameterTypes)
|
= ChangeFunctionLiteralSignatureFix(data.functionLiteral, data.descriptor, data.parameterTypes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ abstract class ChangeFunctionSignatureFix(
|
|||||||
return diagnostic.psiElement.getNonStrictParentOfType<JetCallElement>()
|
return diagnostic.psiElement.getNonStrictParentOfType<JetCallElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetCallElement, diagnostic: Diagnostic): Data? {
|
override fun extractFixData(element: JetCallElement, diagnostic: Diagnostic): Data? {
|
||||||
val descriptor = DiagnosticFactory.cast(diagnostic, Errors.TOO_MANY_ARGUMENTS, Errors.NO_VALUE_FOR_PARAMETER).a
|
val descriptor = DiagnosticFactory.cast(diagnostic, Errors.TOO_MANY_ARGUMENTS, Errors.NO_VALUE_FOR_PARAMETER).a
|
||||||
return Data(element, descriptor)
|
return Data(element, descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFix(data: Data) = createFix(data.callElement, data.callElement, data.descriptor)
|
override fun createFix(data: Data) = createFix(data.callElement, data.callElement, data.descriptor)
|
||||||
|
|
||||||
private fun createFix(callElement: JetCallElement, context: PsiElement, descriptor: CallableDescriptor): ChangeFunctionSignatureFix? {
|
private fun createFix(callElement: JetCallElement, context: PsiElement, descriptor: CallableDescriptor): ChangeFunctionSignatureFix? {
|
||||||
val functionDescriptor = when (descriptor) {
|
val functionDescriptor = when (descriptor) {
|
||||||
|
|||||||
+7
-7
@@ -30,16 +30,16 @@ abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D
|
|||||||
private val isLowPriority: Boolean = false
|
private val isLowPriority: Boolean = false
|
||||||
) : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
) : KotlinIntentionActionFactoryWithDelegate<E, D>() {
|
||||||
|
|
||||||
protected abstract fun createQuickFix(data: D): IntentionAction?
|
protected abstract fun createFix(data: D): IntentionAction?
|
||||||
|
|
||||||
protected override final fun createQuickFixes(
|
protected override final fun createFixes(
|
||||||
originalElementPointer: SmartPsiElementPointer<E>,
|
originalElementPointer: SmartPsiElementPointer<E>,
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
quickFixDataFactory: () -> D?
|
quickFixDataFactory: () -> D?
|
||||||
): List<QuickFixWithDelegateFactory> {
|
): List<QuickFixWithDelegateFactory> {
|
||||||
fun createAction(): IntentionAction? {
|
fun createAction(): IntentionAction? {
|
||||||
val data = quickFixDataFactory() ?: return null
|
val data = quickFixDataFactory() ?: return null
|
||||||
return createQuickFix(data)
|
return createFix(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
val delegateFactory = if (isLowPriority)
|
val delegateFactory = if (isLowPriority)
|
||||||
@@ -53,13 +53,13 @@ abstract class KotlinSingleIntentionActionFactoryWithDelegate<E : JetElement, D
|
|||||||
abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any> : JetIntentionActionsFactory() {
|
abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any> : JetIntentionActionsFactory() {
|
||||||
protected abstract fun getElementOfInterest(diagnostic: Diagnostic): E?
|
protected abstract fun getElementOfInterest(diagnostic: Diagnostic): E?
|
||||||
|
|
||||||
protected abstract fun createQuickFixes(
|
protected abstract fun createFixes(
|
||||||
originalElementPointer: SmartPsiElementPointer<E>,
|
originalElementPointer: SmartPsiElementPointer<E>,
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
quickFixDataFactory: () -> D?
|
quickFixDataFactory: () -> D?
|
||||||
): List<QuickFixWithDelegateFactory>
|
): List<QuickFixWithDelegateFactory>
|
||||||
|
|
||||||
protected abstract fun createQuickFixData(element: E, diagnostic: Diagnostic): D?
|
protected abstract fun extractFixData(element: E, diagnostic: Diagnostic): D?
|
||||||
|
|
||||||
override final fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
override final fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>? {
|
||||||
val diagnosticMessage = DefaultErrorMessages.render(diagnostic)
|
val diagnosticMessage = DefaultErrorMessages.render(diagnostic)
|
||||||
@@ -74,7 +74,7 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any>
|
|||||||
// Cache null values
|
// Cache null values
|
||||||
var cachedData: Ref<D>? = null
|
var cachedData: Ref<D>? = null
|
||||||
val actions: List<QuickFixWithDelegateFactory> = try {
|
val actions: List<QuickFixWithDelegateFactory> = try {
|
||||||
createQuickFixes(originalElementPointer, diagnostic) factory@ {
|
createFixes(originalElementPointer, diagnostic) factory@ {
|
||||||
val element = originalElementPointer.element ?: return@factory null
|
val element = originalElementPointer.element ?: return@factory null
|
||||||
val diagnosticElement = diagnosticElementPointer.element ?: return@factory null
|
val diagnosticElement = diagnosticElementPointer.element ?: return@factory null
|
||||||
if (!diagnosticElement.isValid || !element.isValid) return@factory null
|
if (!diagnosticElement.isValid || !element.isValid) return@factory null
|
||||||
@@ -85,7 +85,7 @@ abstract class KotlinIntentionActionFactoryWithDelegate<E : JetElement, D : Any>
|
|||||||
.forElement(diagnosticElement)
|
.forElement(diagnosticElement)
|
||||||
.firstOrNull { DefaultErrorMessages.render(it) == diagnosticMessage } ?: return@factory null
|
.firstOrNull { DefaultErrorMessages.render(it) == diagnosticMessage } ?: return@factory null
|
||||||
if (cachedData == null) {
|
if (cachedData == null) {
|
||||||
cachedData = Ref(createQuickFixData(element, currentDiagnostic))
|
cachedData = Ref(extractFixData(element, currentDiagnostic))
|
||||||
}
|
}
|
||||||
cachedData!!.get()
|
cachedData!!.get()
|
||||||
}.filter { it.isAvailable(project, null, file) }
|
}.filter { it.isAvailable(project, null, file) }
|
||||||
|
|||||||
+2
-2
@@ -44,10 +44,10 @@ public abstract class CreateCallableMemberFromUsageFactory<E : JetElement>(
|
|||||||
|
|
||||||
protected open fun createCallableInfo(element: E, diagnostic: Diagnostic): CallableInfo? = null
|
protected open fun createCallableInfo(element: E, diagnostic: Diagnostic): CallableInfo? = null
|
||||||
|
|
||||||
override fun createQuickFixData(element: E, diagnostic: Diagnostic): List<CallableInfo>
|
override fun extractFixData(element: E, diagnostic: Diagnostic): List<CallableInfo>
|
||||||
= createCallableInfo(element, diagnostic).singletonOrEmptyList()
|
= createCallableInfo(element, diagnostic).singletonOrEmptyList()
|
||||||
|
|
||||||
override fun createQuickFixes(
|
override fun createFixes(
|
||||||
originalElementPointer: SmartPsiElementPointer<E>,
|
originalElementPointer: SmartPsiElementPointer<E>,
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
quickFixDataFactory: () -> List<CallableInfo>?
|
quickFixDataFactory: () -> List<CallableInfo>?
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs
|
|||||||
return diagnostic.psiElement as? JetExpression
|
return diagnostic.psiElement as? JetExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetExpression, diagnostic: Diagnostic): List<CallableInfo> {
|
override fun extractFixData(element: JetExpression, diagnostic: Diagnostic): List<CallableInfo> {
|
||||||
val context = element.analyze()
|
val context = element.analyze()
|
||||||
|
|
||||||
fun isApplicableForAccessor(accessor: PropertyAccessorDescriptor?): Boolean =
|
fun isApplicableForAccessor(accessor: PropertyAccessorDescriptor?): Boolean =
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas
|
|||||||
return (if (element is JetAnnotationEntry) ClassKind.ANNOTATION_CLASS else ClassKind.PLAIN_CLASS).singletonList()
|
return (if (element is JetAnnotationEntry) ClassKind.ANNOTATION_CLASS else ClassKind.PLAIN_CLASS).singletonList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetCallElement, diagnostic: Diagnostic): ClassInfo? {
|
override fun extractFixData(element: JetCallElement, diagnostic: Diagnostic): ClassInfo? {
|
||||||
val isAnnotation = element is JetAnnotationEntry
|
val isAnnotation = element is JetAnnotationEntry
|
||||||
val callee = element.calleeExpression as? JetConstructorCalleeExpression ?: return null
|
val callee = element.calleeExpression as? JetConstructorCalleeExpression ?: return null
|
||||||
val calleeRef = callee.constructorReferenceExpression ?: return null
|
val calleeRef = callee.constructorReferenceExpression ?: return null
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ public object CreateClassFromConstructorCallActionFactory: CreateClassFromUsageF
|
|||||||
return classKind.singletonList()
|
return classKind.singletonList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetCallExpression, diagnostic: Diagnostic): ClassInfo? {
|
override fun extractFixData(element: JetCallExpression, diagnostic: Diagnostic): ClassInfo? {
|
||||||
val diagElement = diagnostic.psiElement
|
val diagElement = diagnostic.psiElement
|
||||||
if (diagElement.getNonStrictParentOfType<JetTypeReference>() != null) return null
|
if (diagElement.getNonStrictParentOfType<JetTypeReference>() != null) return null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ public object CreateClassFromReferenceExpressionActionFactory : CreateClassFromU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetSimpleNameExpression, diagnostic: Diagnostic): ClassInfo? {
|
override fun extractFixData(element: JetSimpleNameExpression, diagnostic: Diagnostic): ClassInfo? {
|
||||||
val file = element.containingFile as? JetFile ?: return null
|
val file = element.containingFile as? JetFile ?: return null
|
||||||
|
|
||||||
val name = element.getReferencedName()
|
val name = element.getReferencedName()
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ public object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetUserType, diagnostic: Diagnostic): ClassInfo? {
|
override fun extractFixData(element: JetUserType, diagnostic: Diagnostic): ClassInfo? {
|
||||||
val name = element.referenceExpression?.getReferencedName() ?: return null
|
val name = element.referenceExpression?.getReferencedName() ?: return null
|
||||||
if (element.parent?.parent is JetConstructorCalleeExpression) return null
|
if (element.parent?.parent is JetConstructorCalleeExpression) return null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.JetElement
|
|||||||
abstract class CreateClassFromUsageFactory<E : JetElement> : KotlinIntentionActionFactoryWithDelegate<E, ClassInfo>() {
|
abstract class CreateClassFromUsageFactory<E : JetElement> : KotlinIntentionActionFactoryWithDelegate<E, ClassInfo>() {
|
||||||
protected abstract fun getPossibleClassKinds(element: E, diagnostic: Diagnostic): List<ClassKind>
|
protected abstract fun getPossibleClassKinds(element: E, diagnostic: Diagnostic): List<ClassKind>
|
||||||
|
|
||||||
override fun createQuickFixes(
|
override fun createFixes(
|
||||||
originalElementPointer: SmartPsiElementPointer<E>,
|
originalElementPointer: SmartPsiElementPointer<E>,
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
quickFixDataFactory: () -> ClassInfo?
|
quickFixDataFactory: () -> ClassInfo?
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUs
|
|||||||
return if (argument.isNamed()) argument else null
|
return if (argument.isNamed()) argument else null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(element: JetValueArgument, diagnostic: Diagnostic): CreateParameterData<JetValueArgument>? {
|
override fun extractFixData(element: JetValueArgument, diagnostic: Diagnostic): CreateParameterData<JetValueArgument>? {
|
||||||
val result = (diagnostic.psiFile as? JetFile)?.analyzeFullyAndGetResult() ?: return null
|
val result = (diagnostic.psiFile as? JetFile)?.analyzeFullyAndGetResult() ?: return null
|
||||||
val context = result.bindingContext
|
val context = result.bindingContext
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<JetSi
|
|||||||
return refExpr
|
return refExpr
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createQuickFixData(
|
override fun extractFixData(
|
||||||
element: JetSimpleNameExpression,
|
element: JetSimpleNameExpression,
|
||||||
diagnostic: Diagnostic
|
diagnostic: Diagnostic
|
||||||
): CreateParameterData<JetSimpleNameExpression>? {
|
): CreateParameterData<JetSimpleNameExpression>? {
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ data class CreateParameterData<E : JetElement>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
abstract class CreateParameterFromUsageFactory<E : JetElement>: KotlinSingleIntentionActionFactoryWithDelegate<E, CreateParameterData<E>>() {
|
abstract class CreateParameterFromUsageFactory<E : JetElement>: KotlinSingleIntentionActionFactoryWithDelegate<E, CreateParameterData<E>>() {
|
||||||
override fun createQuickFix(data: CreateParameterData<E>): IntentionAction? {
|
override fun createFix(data: CreateParameterData<E>): IntentionAction? {
|
||||||
return CreateParameterFromUsageFix(
|
return CreateParameterFromUsageFix(
|
||||||
data.parameterInfo.callableDescriptor as FunctionDescriptor,
|
data.parameterInfo.callableDescriptor as FunctionDescriptor,
|
||||||
data.parameterInfo,
|
data.parameterInfo,
|
||||||
|
|||||||
Reference in New Issue
Block a user