Inline refactoring: should support set/get operator
#KT-17378 Fixed
This commit is contained in:
+4
-4
@@ -70,15 +70,15 @@ class KotlinInlineCallableProcessor(
|
||||
}
|
||||
|
||||
override fun performRefactoring(usages: Array<out UsageInfo>) {
|
||||
val simpleNameUsages = usages.mapNotNull { it.element as? KtSimpleNameExpression }
|
||||
val referenceUsages = usages.mapNotNull { it.element as? KtReferenceExpression }
|
||||
replacementStrategy.replaceUsages(
|
||||
simpleNameUsages,
|
||||
referenceUsages,
|
||||
declaration,
|
||||
myProject,
|
||||
commandName,
|
||||
postAction = {
|
||||
if (deleteAfter) {
|
||||
if (usages.size == simpleNameUsages.size) {
|
||||
if (usages.size == referenceUsages.size) {
|
||||
declaration.deleteWithCompanion()
|
||||
statementToDelete?.delete()
|
||||
} else {
|
||||
@@ -87,7 +87,7 @@ class KotlinInlineCallableProcessor(
|
||||
null,
|
||||
KotlinBundle.message(
|
||||
"text.cannot.inline.0.1.usages",
|
||||
usages.size - simpleNameUsages.size,
|
||||
usages.size - referenceUsages.size,
|
||||
usages.size
|
||||
),
|
||||
KotlinBundle.message("text.inline.0", kind),
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Declaration {
|
||||
operator fun <caret>get(p: Int) = p
|
||||
}
|
||||
|
||||
fun call() {
|
||||
val declaration = Declaration()
|
||||
val vg1 = declaration.get(4)
|
||||
val vg2 = declaration[42].let { it + 1 }
|
||||
val vg3 = Declaration()[42].let { it + 1 }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Declaration {
|
||||
}
|
||||
|
||||
fun call() {
|
||||
val declaration = Declaration()
|
||||
val vg1 = 4
|
||||
val vg2 = 42.let { it + 1 }
|
||||
Declaration()
|
||||
val vg3 = 42.let { it + 1 }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Declaration {
|
||||
operator fun <T> <caret>set(i: Int, e: T) {
|
||||
println(i)
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun call() {
|
||||
val declaration = Declaration()
|
||||
declaration.set(4, "")
|
||||
declaration[42] = declaration
|
||||
Declaration()[{ 42 }()] = { 4 }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Declaration {
|
||||
}
|
||||
|
||||
fun call() {
|
||||
val declaration = Declaration()
|
||||
println(4)
|
||||
println("")
|
||||
println(42)
|
||||
println(declaration)
|
||||
Declaration()
|
||||
println({ 42 }())
|
||||
println({ 4 })
|
||||
}
|
||||
+10
@@ -50,6 +50,11 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
runTest("idea/testData/refactoring/inline/function/ExtensionAndDispatchReceivers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("getOperator.kt")
|
||||
public void testGetOperator() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/getOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InStringTemplates.kt")
|
||||
public void testInStringTemplates() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/InStringTemplates.kt");
|
||||
@@ -145,6 +150,11 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
runTest("idea/testData/refactoring/inline/function/Sequence.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setOperator.kt")
|
||||
public void testSetOperator() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/setOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TypeArguments.kt")
|
||||
public void testTypeArguments() throws Exception {
|
||||
runTest("idea/testData/refactoring/inline/function/TypeArguments.kt");
|
||||
|
||||
Reference in New Issue
Block a user