KT-14084 related : replaceFirstReceiver now replaces ALL calls to safe calls if necessary
Fixes relevant "replace let" and "if to elvis" cases
This commit is contained in:
@@ -271,14 +271,14 @@ fun KtDotQualifiedExpression.replaceFirstReceiver(
|
|||||||
safeAccess: Boolean = false
|
safeAccess: Boolean = false
|
||||||
): KtExpression {
|
): KtExpression {
|
||||||
val receiver = receiverExpression
|
val receiver = receiverExpression
|
||||||
|
if (safeAccess) {
|
||||||
|
operationTokenNode.psi.replace(factory.createSafeCallNode().psi)
|
||||||
|
}
|
||||||
when (receiver) {
|
when (receiver) {
|
||||||
is KtDotQualifiedExpression -> {
|
is KtDotQualifiedExpression -> {
|
||||||
receiver.replaceFirstReceiver(factory, newReceiver, safeAccess)
|
receiver.replaceFirstReceiver(factory, newReceiver, safeAccess)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
if (safeAccess) {
|
|
||||||
operationTokenNode.psi.replace(factory.createSafeCallNode().psi)
|
|
||||||
}
|
|
||||||
receiver.replace(newReceiver)
|
receiver.replace(newReceiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class My(val x: Int)
|
||||||
|
|
||||||
|
fun foo(arg: Any?): Int {
|
||||||
|
return if (<caret>arg is My) arg.x.hashCode() else 42
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class My(val x: Int)
|
||||||
|
|
||||||
|
fun foo(arg: Any?): Int {
|
||||||
|
return (arg as? My)?.x?.hashCode() ?: 42
|
||||||
|
}
|
||||||
+1
-1
@@ -4,6 +4,6 @@
|
|||||||
fun foo() {
|
fun foo() {
|
||||||
val foo: String? = null
|
val foo: String? = null
|
||||||
foo?.let {
|
foo?.let {
|
||||||
it.to("").to("")<caret>
|
it.hashCode().hashCode()<caret>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -3,5 +3,5 @@
|
|||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val foo: String? = null
|
val foo: String? = null
|
||||||
foo?.to("").to("")
|
foo?.hashCode()?.hashCode()
|
||||||
}
|
}
|
||||||
@@ -1308,6 +1308,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("isCheckWithSelectorChain.kt")
|
||||||
|
public void testIsCheckWithSelectorChain() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lhsEqualsNull.kt")
|
@TestMetadata("lhsEqualsNull.kt")
|
||||||
public void testLhsEqualsNull() throws Exception {
|
public void testLhsEqualsNull() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user