diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CallableUsageReplacementStrategy.kt b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CallableUsageReplacementStrategy.kt index 721d77cd38a..97cd3e2e2d0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CallableUsageReplacementStrategy.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CallableUsageReplacementStrategy.kt @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.codeInliner import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention -import org.jetbrains.kotlin.idea.intentions.isInvokeOperator import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall @@ -35,14 +34,7 @@ class CallableUsageReplacementStrategy( if (!resolvedCall.status.isSuccess) return null val callElement = when (resolvedCall) { - is VariableAsFunctionResolvedCall -> { - val callElement = resolvedCall.variableCall.call.callElement - if (resolvedCall.resultingDescriptor.isInvokeOperator) { - callElement.parent as? KtCallExpression ?: callElement - } else { - callElement - } - } + is VariableAsFunctionResolvedCall -> resolvedCall.variableCall.call.callElement else -> resolvedCall.call.callElement } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt index 36505ff5598..7e48db187b3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.idea.core.* import org.jetbrains.kotlin.idea.inspections.RedundantUnitExpressionInspection import org.jetbrains.kotlin.idea.intentions.InsertExplicitTypeArgumentsIntention import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention -import org.jetbrains.kotlin.idea.intentions.isInvokeOperator import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ImportInsertHelper @@ -36,7 +35,6 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.isError -import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -137,23 +135,7 @@ class CodeInliner( .forEach { ImportInsertHelper.getInstance(project).importDescriptor(file, it) } val replacementPerformer = when (elementToBeReplaced) { - is KtExpression -> { - if (descriptor.isInvokeOperator) { - val call = elementToBeReplaced as? KtCallExpression - ?: (elementToBeReplaced as? KtDotQualifiedExpression)?.selectorExpression as? KtCallExpression - val callee = call?.calleeExpression - if (callee != null && callee.text != OperatorNameConventions.INVOKE.asString()) { - val receiverExpression = (codeToInline.mainExpression as? KtQualifiedExpression)?.receiverExpression - when { - elementToBeReplaced is KtCallExpression && receiverExpression is KtThisExpression -> - receiverExpression.replace(callee) - elementToBeReplaced is KtDotQualifiedExpression -> - receiverExpression?.replace(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, callee)) - } - } - } - ExpressionReplacementPerformer(codeToInline, elementToBeReplaced) - } + is KtExpression -> ExpressionReplacementPerformer(codeToInline, elementToBeReplaced) is KtAnnotationEntry -> AnnotationEntryReplacementPerformer(codeToInline, elementToBeReplaced) is KtSuperTypeCallEntry -> SuperTypeCallEntryReplacementPerformer(codeToInline, elementToBeReplaced) else -> { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt index 3b27a34683b..1d2cbb8af6b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt @@ -39,7 +39,6 @@ import org.jetbrains.kotlin.types.isFlexible import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.util.OperatorChecks -import org.jetbrains.kotlin.util.OperatorNameConventions fun KtContainerNode.description(): String? { when (node.elementType) { @@ -365,6 +364,3 @@ fun KotlinType.reflectToRegularFunctionType(): KotlinType { if (isKSuspendFunctionType) builtIns.getSuspendFunction(parameterCount) else builtIns.getFunction(parameterCount) return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments) } - -val CallableDescriptor.isInvokeOperator: Boolean - get() = this is FunctionDescriptor && isOperator && name == OperatorNameConventions.INVOKE diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt index eb5fa8ea585..a9d6f0f42d4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.idea.codeInliner.CallableUsageReplacementStrategy import org.jetbrains.kotlin.idea.codeInliner.ClassUsageReplacementStrategy import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy import org.jetbrains.kotlin.idea.core.OptionalParametersHelper -import org.jetbrains.kotlin.idea.intentions.isInvokeOperator import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.resolveMainReferenceToDescriptors @@ -194,10 +193,7 @@ abstract class DeprecatedSymbolUsageFixBase( ): UsageReplacementStrategy? { val resolutionFacade = element.getResolutionFacade() val bindingContext = resolutionFacade.analyze(element, BodyResolveMode.PARTIAL) - val resolvedCall = element.getResolvedCall(bindingContext) - var target = resolvedCall?.resultingDescriptor?.takeIf { it.isInvokeOperator } - ?: element.mainReference.resolveToDescriptors(bindingContext).singleOrNull() - ?: return null + var target = element.mainReference.resolveToDescriptors(bindingContext).singleOrNull() ?: return null var replacePatternFromSymbol = fetchReplaceWithPattern(target, resolutionFacade.project, element, replaceWith.replaceInWholeProject) @@ -212,7 +208,7 @@ abstract class DeprecatedSymbolUsageFixBase( when (target) { is CallableDescriptor -> { - if (resolvedCall == null) return null + val resolvedCall = element.getResolvedCall(bindingContext) ?: return null if (!resolvedCall.isReallySuccess()) return null val replacement = ReplaceWithAnnotationAnalyzer.analyzeCallableReplacement( replaceWith, target, resolutionFacade, reformat diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt deleted file mode 100644 index a5ee2d1a1de..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt +++ /dev/null @@ -1,14 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - executor { - // do something - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt.after deleted file mode 100644 index ae44f31f98a..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt.after +++ /dev/null @@ -1,14 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - executor.execute { - // do something - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt deleted file mode 100644 index 2fe9ec0054b..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt +++ /dev/null @@ -1,18 +0,0 @@ -// "Replace with 'Foo.execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("Foo.execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -object Foo { - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - executor { - // do something - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt.after deleted file mode 100644 index 3f11fbfcec6..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt.after +++ /dev/null @@ -1,18 +0,0 @@ -// "Replace with 'Foo.execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("Foo.execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -object Foo { - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - Foo.execute { - // do something - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt deleted file mode 100644 index b38ae6f000f..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt +++ /dev/null @@ -1,14 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} - - fun usage(executor: Executor) { - invoke { - // do something - } - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt.after deleted file mode 100644 index c11583b68ee..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt.after +++ /dev/null @@ -1,14 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} - - fun usage(executor: Executor) { - execute { - // do something - } - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt deleted file mode 100644 index 053c046481d..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt +++ /dev/null @@ -1,17 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - val self: Executor - get() = this - - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - executor.self { - // do something - } -} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt.after deleted file mode 100644 index d5fc9ac93ec..00000000000 --- a/idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt.after +++ /dev/null @@ -1,17 +0,0 @@ -// "Replace with 'execute(action)'" "true" - -class Executor { - val self: Executor - get() = this - - @Deprecated("Use Executor.execute(Runnable) instead.", ReplaceWith("execute(action)")) - operator fun invoke(action: () -> Unit) {} - - fun execute(action: () -> Unit) {} -} - -fun usage(executor: Executor) { - executor.self.execute { - // do something - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 622ef461ac0..b9fa6d427b2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -7061,26 +7061,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/in.kt"); } - @TestMetadata("invoke.kt") - public void testInvoke() throws Exception { - runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke.kt"); - } - - @TestMetadata("invoke2.kt") - public void testInvoke2() throws Exception { - runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke2.kt"); - } - - @TestMetadata("invoke3.kt") - public void testInvoke3() throws Exception { - runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke3.kt"); - } - - @TestMetadata("invoke4.kt") - public void testInvoke4() throws Exception { - runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/invoke4.kt"); - } - @TestMetadata("plusAssign.kt") public void testPlusAssign() throws Exception { runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/plusAssign.kt");