False positive removed in replace single line let intention #KT-14791 Fixed
This commit is contained in:
@@ -94,7 +94,7 @@ class ReplaceSingleLineLetIntention : SelfTargetingOffsetIndependentIntention<Kt
|
||||
val bodyExpression = lambdaExpression.bodyExpression?.children?.singleOrNull() ?: return false
|
||||
|
||||
return when (bodyExpression) {
|
||||
is KtBinaryExpression -> bodyExpression.isApplicable(parameterName)
|
||||
is KtBinaryExpression -> element.parent !is KtSafeQualifiedExpression && bodyExpression.isApplicable(parameterName)
|
||||
is KtDotQualifiedExpression -> bodyExpression.isApplicable(parameterName)
|
||||
else -> false
|
||||
}
|
||||
@@ -105,6 +105,7 @@ class ReplaceSingleLineLetIntention : SelfTargetingOffsetIndependentIntention<Kt
|
||||
when (left) {
|
||||
is KtNameReferenceExpression -> if (left.text != parameterName) return false
|
||||
is KtDotQualifiedExpression -> if (!left.isApplicable(parameterName)) return false
|
||||
else -> return false
|
||||
}
|
||||
|
||||
val right = right ?: return false
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun withAssign(arg: String?): String {
|
||||
var result: String = ""
|
||||
arg?.let<caret> { result = it }
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun isAlphaOrBeta(str: String) = str.let<caret> { it == "Alpha" || it == "Beta" }
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun plusNullable(arg: String?) = arg?.let<caret> { it + "#" } ?: ""
|
||||
@@ -0,0 +1,15 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface A
|
||||
|
||||
interface B : A {
|
||||
val bar: Any?
|
||||
}
|
||||
|
||||
class Foo {
|
||||
private val a: A = object : A {}
|
||||
|
||||
val isB: Boolean
|
||||
get() = a.let<caret> { it is B && it.bar != null }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface Base
|
||||
|
||||
class A : Base
|
||||
class B : Base
|
||||
|
||||
fun isAB(arg: Base) = arg.let<caret> { it is A || it is B }
|
||||
@@ -11799,6 +11799,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceSingleLineLetIntention"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("assignment.kt")
|
||||
public void testAssignment() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/assignment.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("comparisons.kt")
|
||||
public void testComparisons() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/comparisons.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithBinaryExpression.kt")
|
||||
public void testLambdaWithBinaryExpression() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/lambdaWithBinaryExpression.kt");
|
||||
@@ -11949,6 +11961,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("plusNullable.kt")
|
||||
public void testPlusNullable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/plusNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("receiverWithLambda.kt")
|
||||
public void testReceiverWithLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/receiverWithLambda.kt");
|
||||
@@ -11967,6 +11985,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastInBody.kt")
|
||||
public void testSmartCastInBody() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/smartCastInBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("this.kt")
|
||||
public void testThis() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/this.kt");
|
||||
@@ -11978,6 +12002,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/thisShort.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeChecks.kt")
|
||||
public void testTypeChecks() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceSingleLineLetIntention/typeChecks.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/replaceSizeCheckWithIsNotEmpty")
|
||||
|
||||
Reference in New Issue
Block a user