From 3f252b15e1604516e2e665758ad32315a0a15438 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 11 Oct 2018 12:34:37 +0900 Subject: [PATCH] Call chain into sequence: add 'flatten' to conversion targets #KT-26969 Fixed --- .../ConvertCallChainIntoSequenceInspection.kt | 1 + .../convertCallChainIntoSequence/flatten.kt | 4 ++++ .../convertCallChainIntoSequence/flatten.kt.after | 4 ++++ .../convertCallChainIntoSequence/flatten2.kt | 4 ++++ .../convertCallChainIntoSequence/flatten2.kt.after | 4 ++++ .../idea/inspections/LocalInspectionTestGenerated.java | 10 ++++++++++ 6 files changed, 27 insertions(+) create mode 100644 idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt create mode 100644 idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt.after create mode 100644 idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt create mode 100644 idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt.after 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 a6b45cf906a..d062809500a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/ConvertCallChainIntoSequenceInspection.kt @@ -219,6 +219,7 @@ private val transformations = listOf( "filterIsInstance", "filterNot", "filterNotNull", + "flatten", "map", "mapIndexed", "mapIndexedNotNull", diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt new file mode 100644 index 00000000000..08c99218577 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test() { + listOf(listOf(1), listOf(2)).flatten().filter { it > 1 } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt.after b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt.after new file mode 100644 index 00000000000..660f19c7fac --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test() { + listOf(listOf(1), listOf(2)).asSequence().flatten().filter { it > 1 }.toList() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt new file mode 100644 index 00000000000..e87bdc32d61 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test() { + listOf(listOf(1), listOf(2, 3)).filter { it.size > 1 }.flatten() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt.after b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt.after new file mode 100644 index 00000000000..501ddc310b5 --- /dev/null +++ b/idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun test() { + listOf(listOf(1), listOf(2, 3)).asSequence().filter { it.size > 1 }.flatten().toList() +} \ 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 44d45b817cc..0cff48d51e3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -569,6 +569,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/endsWithGroupingBy.kt"); } + @TestMetadata("flatten.kt") + public void testFlatten() throws Exception { + runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten.kt"); + } + + @TestMetadata("flatten2.kt") + public void testFlatten2() throws Exception { + runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/flatten2.kt"); + } + @TestMetadata("implicitReceiver.kt") public void testImplicitReceiver() throws Exception { runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/implicitReceiver.kt");