Replace deprecated symbol usage: replace imported object function correctly

#KT-33951 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-10-12 13:33:34 +09:00
committed by Dmitry Gridin
parent b2be1a53cf
commit 02c17378b1
4 changed files with 38 additions and 4 deletions
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.kotlin.utils.sure
import java.util.*
@@ -175,10 +176,12 @@ class CodeToInlineBuilder(
}
if (expression.getReceiverExpression() == null) {
if (target is ValueParameterDescriptor && target.containingDeclaration == targetCallable) {
expression.putCopyableUserData(CodeToInline.PARAMETER_USAGE_KEY, target.name)
} else if (target is TypeParameterDescriptor && target.containingDeclaration == targetCallable) {
expression.putCopyableUserData(CodeToInline.TYPE_PARAMETER_USAGE_KEY, target.name)
(targetCallable.safeAs<ImportedFromObjectCallableDescriptor<*>>()?.callableFromObject ?: targetCallable).let {
if (target is ValueParameterDescriptor && target.containingDeclaration == it) {
expression.putCopyableUserData(CodeToInline.PARAMETER_USAGE_KEY, target.name)
} else if (target is TypeParameterDescriptor && target.containingDeclaration == it) {
expression.putCopyableUserData(CodeToInline.TYPE_PARAMETER_USAGE_KEY, target.name)
}
}
if (targetCallable !is ImportedFromObjectCallableDescriptor<*>) {
@@ -0,0 +1,13 @@
// "Replace with 'str.isEmpty()'" "true"
// WITH_RUNTIME
import Bar.bar
fun foo(s: String) {
<caret>bar(s)
}
object Bar {
@Deprecated(message = "", replaceWith = ReplaceWith("str.isEmpty()"))
fun bar(str: String): Boolean = str.isEmpty()
}
@@ -0,0 +1,13 @@
// "Replace with 'str.isEmpty()'" "true"
// WITH_RUNTIME
import Bar.bar
fun foo(s: String) {
s.isEmpty()
}
object Bar {
@Deprecated(message = "", replaceWith = ReplaceWith("str.isEmpty()"))
fun bar(str: String): Boolean = str.isEmpty()
}
@@ -6150,6 +6150,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/importedObjectFunction.kt");
}
@TestMetadata("importedObjectFunctionAddReceiver.kt")
public void testImportedObjectFunctionAddReceiver() throws Exception {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/importedObjectFunctionAddReceiver.kt");
}
@TestMetadata("importedObjectProperty.kt")
public void testImportedObjectProperty() throws Exception {
runTest("idea/testData/quickfix/deprecatedSymbolUsage/importedObjectProperty.kt");