Replace deprecated symbol usage: do not add 'this' receiver for imported object function

#KT-26361 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-10-13 13:28:19 +09:00
committed by Dmitry Gridin
parent 9d27ba5b59
commit bcefee0105
6 changed files with 114 additions and 13 deletions
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.idea.codeInliner
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.asExpression
@@ -33,6 +36,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
@@ -185,18 +189,19 @@ class CodeToInlineBuilder(
} else if (target is TypeParameterDescriptor && target.containingDeclaration == targetCallable) {
expression.putCopyableUserData(CodeToInline.TYPE_PARAMETER_USAGE_KEY, target.name)
}
val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall != null && resolvedCall.isReallySuccess()) {
val receiver = if (resolvedCall.resultingDescriptor.isExtension)
resolvedCall.extensionReceiver
else
resolvedCall.dispatchReceiver
if (receiver is ImplicitReceiver) {
val resolutionScope = expression.getResolutionScope(bindingContext, resolutionFacade)
val receiverExpression = receiver.asExpression(resolutionScope, psiFactory)
if (receiverExpression != null) {
receiversToAdd.add(Triple(expression, receiverExpression, receiver.type))
if (targetCallable !is ImportedFromObjectCallableDescriptor<*>) {
val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall != null && resolvedCall.isReallySuccess()) {
val receiver = if (resolvedCall.resultingDescriptor.isExtension)
resolvedCall.extensionReceiver
else
resolvedCall.dispatchReceiver
if (receiver is ImplicitReceiver) {
val resolutionScope = expression.getResolutionScope(bindingContext, resolutionFacade)
val receiverExpression = receiver.asExpression(resolutionScope, psiFactory)
if (receiverExpression != null) {
receiversToAdd.add(Triple(expression, receiverExpression, receiver.type))
}
}
}
}
@@ -0,0 +1,21 @@
// "Replace with 'stopKoin()'" "true"
// WITH_RUNTIME
package com.example.pkg
import com.example.pkg.StandAloneContext.closeKoin
object StandAloneContext {
@Deprecated(
"Renamed, use stopKoin() instead.",
ReplaceWith("stopKoin()", "com.example.pkg.StandAloneContext.stopKoin")
)
fun closeKoin() = stopKoin()
fun stopKoin() {}
}
fun koin() {
<caret>closeKoin()
}
@@ -0,0 +1,22 @@
// "Replace with 'stopKoin()'" "true"
// WITH_RUNTIME
package com.example.pkg
import com.example.pkg.StandAloneContext.closeKoin
import com.example.pkg.StandAloneContext.stopKoin
object StandAloneContext {
@Deprecated(
"Renamed, use stopKoin() instead.",
ReplaceWith("stopKoin()", "com.example.pkg.StandAloneContext.stopKoin")
)
fun closeKoin() = stopKoin()
fun stopKoin() {}
}
fun koin() {
stopKoin()
}
@@ -0,0 +1,21 @@
// "Replace with 'stopKoin'" "true"
// WITH_RUNTIME
package com.example.pkg
import com.example.pkg.StandAloneContext.closeKoin
object StandAloneContext {
@Deprecated(
"Renamed, use stopKoin() instead.",
ReplaceWith("stopKoin", "com.example.pkg.StandAloneContext.stopKoin")
)
val closeKoin = 1
val stopKoin = 2
}
fun koin() {
val i = <caret>closeKoin
}
@@ -0,0 +1,22 @@
// "Replace with 'stopKoin'" "true"
// WITH_RUNTIME
package com.example.pkg
import com.example.pkg.StandAloneContext.closeKoin
import com.example.pkg.StandAloneContext.stopKoin
object StandAloneContext {
@Deprecated(
"Renamed, use stopKoin() instead.",
ReplaceWith("stopKoin", "com.example.pkg.StandAloneContext.stopKoin")
)
val closeKoin = 1
val stopKoin = 2
}
fun koin() {
val i = stopKoin
}
@@ -6145,6 +6145,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/implicitQualifiedThisRuntime.kt");
}
@TestMetadata("importedObjectFunction.kt")
public void testImportedObjectFunction() throws Exception {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/importedObjectFunction.kt");
}
@TestMetadata("importedObjectProperty.kt")
public void testImportedObjectProperty() throws Exception {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/importedObjectProperty.kt");
}
@TestMetadata("incorrectArgs.kt")
public void testIncorrectArgs() throws Exception {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/incorrectArgs.kt");