提交 09ae1f1a 编写于 作者: M Mikhail Glukhikh

False positive removed in replace single line let intention #KT-14791 Fixed

上级 61da8be2
......@@ -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
......
// IS_APPLICABLE: false
// WITH_RUNTIME
fun withAssign(arg: String?): String {
var result: String = ""
arg?.let<caret> { result = it }
return result
}
\ No newline at end of file
// IS_APPLICABLE: false
// WITH_RUNTIME
fun isAlphaOrBeta(str: String) = str.let<caret> { it == "Alpha" || it == "Beta" }
// IS_APPLICABLE: false
// WITH_RUNTIME
fun plusNullable(arg: String?) = arg?.let<caret> { it + "#" } ?: ""
\ No newline at end of file
// 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 }
}
\ No newline at end of file
// 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 }
\ No newline at end of file
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册