ComplexRedundantLetInspection: fix highlight for multiple line receiver

#KT-31278 Fixed
This commit is contained in:
Dmitry Gridin
2019-06-24 19:17:43 +07:00
parent b97aaf0f71
commit 7e0db3d612
4 changed files with 23 additions and 2 deletions
@@ -224,12 +224,12 @@ private fun KtFunctionLiteral.valueParameterReferences(callExpression: KtCallExp
private fun isSingleLine(element: KtCallExpression): Boolean {
val qualifiedExpression = element.getQualifiedExpressionForSelector() ?: return true
var receiver = qualifiedExpression.receiverExpression as? KtQualifiedExpression ?: return true
var receiver = qualifiedExpression.receiverExpression
if (receiver.lineCount() > 1) return false
var count = 1
while (true) {
if (count > 2) return false
receiver = receiver.receiverExpression as? KtQualifiedExpression ?: break
receiver = (receiver as? KtQualifiedExpression)?.receiverExpression ?: break
count++
}
return true
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// HIGHLIGHT: INFORMATION
fun test() {
runCatching {
/* lots of code*/
}.let<caret> { println(it) }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// HIGHLIGHT: INFORMATION
fun test() {
println(runCatching {
/* lots of code*/
})
}
@@ -2313,6 +2313,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/complexRedundantLet/longCallChain.kt");
}
@TestMetadata("multipleLines.kt")
public void testMultipleLines() throws Exception {
runTest("idea/testData/inspectionsLocal/complexRedundantLet/multipleLines.kt");
}
@TestMetadata("multipleReceiver.kt")
public void testMultipleReceiver() throws Exception {
runTest("idea/testData/inspectionsLocal/complexRedundantLet/multipleReceiver.kt");