Replace deprecated symbol usage: do not add 'this' receiver for imported object function
#KT-26361 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
9d27ba5b59
commit
bcefee0105
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.codeInliner
|
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.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.core.asExpression
|
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.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.renderer.render
|
import org.jetbrains.kotlin.renderer.render
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
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.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||||
@@ -185,18 +189,19 @@ class CodeToInlineBuilder(
|
|||||||
} else if (target is TypeParameterDescriptor && target.containingDeclaration == targetCallable) {
|
} else if (target is TypeParameterDescriptor && target.containingDeclaration == targetCallable) {
|
||||||
expression.putCopyableUserData(CodeToInline.TYPE_PARAMETER_USAGE_KEY, target.name)
|
expression.putCopyableUserData(CodeToInline.TYPE_PARAMETER_USAGE_KEY, target.name)
|
||||||
}
|
}
|
||||||
|
if (targetCallable !is ImportedFromObjectCallableDescriptor<*>) {
|
||||||
val resolvedCall = expression.getResolvedCall(bindingContext)
|
val resolvedCall = expression.getResolvedCall(bindingContext)
|
||||||
if (resolvedCall != null && resolvedCall.isReallySuccess()) {
|
if (resolvedCall != null && resolvedCall.isReallySuccess()) {
|
||||||
val receiver = if (resolvedCall.resultingDescriptor.isExtension)
|
val receiver = if (resolvedCall.resultingDescriptor.isExtension)
|
||||||
resolvedCall.extensionReceiver
|
resolvedCall.extensionReceiver
|
||||||
else
|
else
|
||||||
resolvedCall.dispatchReceiver
|
resolvedCall.dispatchReceiver
|
||||||
if (receiver is ImplicitReceiver) {
|
if (receiver is ImplicitReceiver) {
|
||||||
val resolutionScope = expression.getResolutionScope(bindingContext, resolutionFacade)
|
val resolutionScope = expression.getResolutionScope(bindingContext, resolutionFacade)
|
||||||
val receiverExpression = receiver.asExpression(resolutionScope, psiFactory)
|
val receiverExpression = receiver.asExpression(resolutionScope, psiFactory)
|
||||||
if (receiverExpression != null) {
|
if (receiverExpression != null) {
|
||||||
receiversToAdd.add(Triple(expression, receiverExpression, receiver.type))
|
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");
|
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")
|
@TestMetadata("incorrectArgs.kt")
|
||||||
public void testIncorrectArgs() throws Exception {
|
public void testIncorrectArgs() throws Exception {
|
||||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/incorrectArgs.kt");
|
runTest("idea/testData/quickfix/deprecatedSymbolUsage/incorrectArgs.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user