diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt index 14b327c8813..00ead970b02 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt @@ -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 diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt new file mode 100644 index 00000000000..c506129bc37 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME + +fun test(list: List) { + list.map { it * 2 }.map { it * 3 }.map { it * 4 }.groupingBy { it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt.after b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt.after new file mode 100644 index 00000000000..7ddd770a771 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt.after @@ -0,0 +1,5 @@ +// WITH_RUNTIME + +fun test(list: List) { + list.asSequence().map { it * 2 }.map { it * 3 }.map { it * 4 }.groupingBy { it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/startsWithGroupingBy.kt b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/startsWithGroupingBy.kt new file mode 100644 index 00000000000..f3421d2116e --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/startsWithGroupingBy.kt @@ -0,0 +1,6 @@ +// PROBLEM: none +// WITH_RUNTIME + +fun test(list: List) { + list.groupingBy { it }.reduce { _, acc, _ -> acc } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 2ebcd1dbfd5..ee3358bc90a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -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)