DeprecatedSymbolUsageFix: fixed nested calls with implicit receivers in the pattern

This commit is contained in:
Valentin Kipyatkov
2015-05-22 21:47:19 +03:00
parent 4407523b65
commit e767cdef83
4 changed files with 38 additions and 1 deletions
@@ -130,7 +130,8 @@ object ReplaceWithAnnotationAnalyzer {
}
}
for ((expr, receiverExpression) in receiversToAdd) {
// add receivers in reverse order because arguments of a call were processed after the callee's name
for ((expr, receiverExpression) in receiversToAdd.reverse()) {
val expressionToReplace = expr.getParent() as? JetCallExpression ?: expr
val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace))
if (expressionToReplace == expression) {
@@ -0,0 +1,15 @@
// "Replace with 'newFun1(newFun2())'" "true"
class X {
@deprecated("", ReplaceWith("newFun1(newFun2())"))
fun oldFun() {
newFun1(newFun2())
}
fun newFun1(p: Int): Int = p
fun newFun2(): Int = 1
}
fun foo(x: X) {
x.<caret>oldFun()
}
@@ -0,0 +1,15 @@
// "Replace with 'newFun1(newFun2())'" "true"
class X {
@deprecated("", ReplaceWith("newFun1(newFun2())"))
fun oldFun() {
newFun1(newFun2())
}
fun newFun1(p: Int): Int = p
fun newFun2(): Int = 1
}
fun foo(x: X) {
x.<caret>newFun1(x.newFun2())
}
@@ -2862,6 +2862,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DeprecatedSymbolUsage extends AbstractQuickFixTest {
@TestMetadata("addImplicitReceiverNested.kt")
public void testAddImplicitReceiverNested() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/addImplicitReceiverNested.kt");
doTest(fileName);
}
public void testAllFilesPresentInDeprecatedSymbolUsage() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage"), Pattern.compile("^(\\w+)\\.kt$"), true);
}