Call chain --> Sequence: don't report if first call is 'groupingBy'

#KT-27104 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-09-27 08:26:32 +03:00
committed by Mikhail Glukhikh
parent b500239bd1
commit 8fc5fefc7f
5 changed files with 27 additions and 0 deletions
@@ -173,6 +173,7 @@ private fun KtQualifiedExpression.collectCallExpression(context: BindingContext)
.dropWhile { !it.isTransformationOrTermination(context) }
.takeWhile { it.isTransformationOrTermination(context) && !it.hasReturn() }
.toList()
.dropLastWhile { it.calleeExpression?.text == "groupingBy" }
if (transformationCalls.size < 2) return emptyList()
return transformationCalls
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>map { it * 2 }.map { it * 3 }.map { it * 4 }.groupingBy { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().map { it * 2 }.map { it * 3 }.map { it * 4 }.groupingBy { it }
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>groupingBy { it }.reduce { _, acc, _ -> acc }
}
@@ -564,6 +564,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/comment2.kt");
}
@TestMetadata("endsWithGroupingBy.kt")
public void testEndsWithGroupingBy() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt");
}
@TestMetadata("mutableList.kt")
public void testMutableList() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/mutableList.kt");
@@ -644,6 +649,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/simple4.kt");
}
@TestMetadata("startsWithGroupingBy.kt")
public void testStartsWithGroupingBy() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/startsWithGroupingBy.kt");
}
@TestMetadata("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)