Make ReplaceWith work for objects (KT-16211, KT-14929)
#KT-16211 Fixed
This commit is contained in:
@@ -19,6 +19,9 @@ package org.jetbrains.kotlin.idea.codeInliner
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
|
||||
|
||||
@@ -55,13 +58,25 @@ class ClassUsageReplacementStrategy(
|
||||
is KtCallExpression -> {
|
||||
if (usage != parent.calleeExpression) return null
|
||||
when {
|
||||
// constructorReplacementStrategy != null -> return constructorReplacementStrategy.createReplacer(usage)
|
||||
constructorReplacementStrategy == null && typeReplacement != null -> return { replaceConstructorCallWithOtherTypeConstruction(parent) }
|
||||
constructorReplacementStrategy == null && typeReplacement != null -> return {
|
||||
replaceConstructorCallWithOtherTypeConstruction(parent)
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
}
|
||||
|
||||
else -> return null //TODO
|
||||
else -> {
|
||||
if (typeReplacement != null) {
|
||||
val fqNameStr = typeReplacement.text
|
||||
val fqName = FqName(fqNameStr)
|
||||
|
||||
return {
|
||||
usage.mainReference.bindToFqName(fqName, KtSimpleNameReference.ShorteningMode.FORCED_SHORTENING) as? KtElement
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package some
|
||||
|
||||
object New {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
@Deprecated("Use New", replaceWith = ReplaceWith("New"))
|
||||
object Old {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
val test = <caret>Old.foo()
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package some
|
||||
|
||||
object New {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
@Deprecated("Use New", replaceWith = ReplaceWith("New"))
|
||||
object Old {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
val test = <caret>New.foo()
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package some
|
||||
|
||||
object New {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
@Deprecated("Use New", replaceWith = ReplaceWith("New"))
|
||||
object Old {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
val test = some.<caret>Old
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package some
|
||||
|
||||
object New {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
@Deprecated("Use New", replaceWith = ReplaceWith("New"))
|
||||
object Old {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
val test = New
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package ppp
|
||||
|
||||
object New
|
||||
|
||||
@Deprecated(message = "Deprecated, use New", replaceWith = ReplaceWith("New"))
|
||||
typealias Old = New
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val o = <caret>Old
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with 'New'" "true"
|
||||
package ppp
|
||||
|
||||
object New
|
||||
|
||||
@Deprecated(message = "Deprecated, use New", replaceWith = ReplaceWith("New"))
|
||||
typealias Old = New
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val o = <caret>New
|
||||
}
|
||||
@@ -5261,6 +5261,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/noReplacement.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objects.kt")
|
||||
public void testObjects() throws Exception {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/objects.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectsInQualified.kt")
|
||||
public void testObjectsInQualified() throws Exception {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/objectsInQualified.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("operatorCall.kt")
|
||||
public void testOperatorCall() throws Exception {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/operatorCall.kt");
|
||||
@@ -6024,6 +6034,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/constructorUsageWithConflict1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectAliased.kt")
|
||||
public void testObjectAliased() throws Exception {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/objectAliased.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("onlyAliasDeprecated.kt")
|
||||
public void testOnlyAliasDeprecated() throws Exception {
|
||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/onlyAliasDeprecated.kt");
|
||||
|
||||
Reference in New Issue
Block a user