DeprecatedSymbolUsageFix: fixed nested calls with implicit receivers in the pattern
This commit is contained in:
@@ -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 expressionToReplace = expr.getParent() as? JetCallExpression ?: expr
|
||||||
val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace))
|
val newExpr = expressionToReplace.replaced(psiFactory.createExpressionByPattern("$0.$1", receiverExpression, expressionToReplace))
|
||||||
if (expressionToReplace == expression) {
|
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")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class DeprecatedSymbolUsage extends AbstractQuickFixTest {
|
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 {
|
public void testAllFilesPresentInDeprecatedSymbolUsage() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage"), Pattern.compile("^(\\w+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage"), Pattern.compile("^(\\w+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user