ConvertCallChainIntoSequence: support functions added in Kotlin 1.4

#KT-40448 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-07-20 17:07:33 +09:00
committed by igoriakovlev
parent 5e91ffb156
commit 4901cdb11f
50 changed files with 371 additions and 3 deletions
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getImplicitReceiverValue
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import java.awt.BorderLayout
import javax.swing.JPanel
@@ -223,6 +220,7 @@ private val transformations = listOf(
"minus",
"minusElement",
"onEach",
"onEachIndexed",
"plus",
"plusElement",
"requireNoNulls",
@@ -282,18 +280,41 @@ internal val collectionTerminationFunctionNames = listOf(
"max",
"maxBy",
"maxWith",
"maxOrNull",
"maxByOrNull",
"maxWithOrNull",
"maxOf",
"maxOfOrNull",
"maxOfWith",
"maxOfWithOrNull",
"min",
"minBy",
"minWith",
"minOrNull",
"minByOrNull",
"minWithOrNull",
"minOf",
"minOfOrNull",
"minOfWith",
"minOfWithOrNull",
"none",
"partition",
"reduce",
"reduceIndexed",
"reduceIndexedOrNull",
"reduceOrNull",
"runningFold",
"runningFoldIndexed",
"runningReduce",
"runningReduceIndexed",
"scan",
"scanIndexed",
"single",
"singleOrNull",
"sum",
"sumBy",
"sumByDouble",
"sumOf",
"toCollection",
"toHashSet",
"toList",
@@ -19,6 +19,7 @@ fun test(list: List<Int>): List<Pair<IndexedValue<List<Int>>, IndexedValue<List<
.minus(1)
.minusElement(1)
.onEach {}
.onEachIndexed { index, i -> }
.plus(1)
.plusElement(1)
.requireNoNulls()
@@ -20,6 +20,7 @@ fun test(list: List<Int>): List<Pair<IndexedValue<List<Int>>, IndexedValue<List<
.minus(1)
.minusElement(1)
.onEach {}
.onEachIndexed { index, i -> }
.plus(1)
.plusElement(1)
.requireNoNulls()
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxByOrNull { true }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxByOrNull { true }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxOf { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxOf { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxOfOrNull { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxOfOrNull { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxOfWith({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxOfWith({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxOfWithOrNull({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxOfWithOrNull({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxOrNull()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxOrNull()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.maxWithOrNull { _, _ -> 0 }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.maxWithOrNull { _, _ -> 0 }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minByOrNull { true }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minByOrNull { true }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minOf { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minOf { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minOfOrNull { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minOfOrNull { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minOfWith({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minOfWith({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minOfWithOrNull({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minOfWithOrNull({ _, _ -> 0 }) { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minOrNull()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minOrNull()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.minWithOrNull { _, _ -> 0 }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.minWithOrNull { _, _ -> 0 }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.reduceIndexedOrNull { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.reduceIndexedOrNull { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.reduceOrNull { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.reduceOrNull { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.runningFold(0) { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.runningFold(0) { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.runningFoldIndexed(0) { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.runningFoldIndexed(0) { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.runningReduce { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.runningReduce { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.runningReduceIndexed { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.runningReduceIndexed { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.scan(0) { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.scan(0) { acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.scanIndexed(0) { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.scanIndexed(0) { _, acc, i -> acc + i }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.<caret>filter { it > 1 }.sumOf { it }
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun test(list: List<Int>) {
list.asSequence().filter { it > 1 }.sumOf { it }
}
@@ -1372,11 +1372,46 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxBy.kt");
}
@TestMetadata("maxByOrNull.kt")
public void testMaxByOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxByOrNull.kt");
}
@TestMetadata("maxOf.kt")
public void testMaxOf() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxOf.kt");
}
@TestMetadata("maxOfOrNull.kt")
public void testMaxOfOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxOfOrNull.kt");
}
@TestMetadata("maxOfWith.kt")
public void testMaxOfWith() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxOfWith.kt");
}
@TestMetadata("maxOfWithOrNull.kt")
public void testMaxOfWithOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxOfWithOrNull.kt");
}
@TestMetadata("maxOrNull.kt")
public void testMaxOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxOrNull.kt");
}
@TestMetadata("maxWith.kt")
public void testMaxWith() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxWith.kt");
}
@TestMetadata("maxWithOrNull.kt")
public void testMaxWithOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/maxWithOrNull.kt");
}
@TestMetadata("min.kt")
public void testMin() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/min.kt");
@@ -1387,11 +1422,46 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minBy.kt");
}
@TestMetadata("minByOrNull.kt")
public void testMinByOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minByOrNull.kt");
}
@TestMetadata("minOf.kt")
public void testMinOf() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minOf.kt");
}
@TestMetadata("minOfOrNull.kt")
public void testMinOfOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minOfOrNull.kt");
}
@TestMetadata("minOfWith.kt")
public void testMinOfWith() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minOfWith.kt");
}
@TestMetadata("minOfWithOrNull.kt")
public void testMinOfWithOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minOfWithOrNull.kt");
}
@TestMetadata("minOrNull.kt")
public void testMinOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minOrNull.kt");
}
@TestMetadata("minWith.kt")
public void testMinWith() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minWith.kt");
}
@TestMetadata("minWithOrNull.kt")
public void testMinWithOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/minWithOrNull.kt");
}
@TestMetadata("none.kt")
public void testNone() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/none.kt");
@@ -1412,6 +1482,46 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/reduceIndexed.kt");
}
@TestMetadata("reduceIndexedOrNull.kt")
public void testReduceIndexedOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/reduceIndexedOrNull.kt");
}
@TestMetadata("reduceOrNull.kt")
public void testReduceOrNull() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/reduceOrNull.kt");
}
@TestMetadata("runningFold.kt")
public void testRunningFold() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/runningFold.kt");
}
@TestMetadata("runningFoldIndexed.kt")
public void testRunningFoldIndexed() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/runningFoldIndexed.kt");
}
@TestMetadata("runningReduce.kt")
public void testRunningReduce() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/runningReduce.kt");
}
@TestMetadata("runningReduceIndexed.kt")
public void testRunningReduceIndexed() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/runningReduceIndexed.kt");
}
@TestMetadata("scan.kt")
public void testScan() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/scan.kt");
}
@TestMetadata("scanIndexed.kt")
public void testScanIndexed() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/scanIndexed.kt");
}
@TestMetadata("single.kt")
public void testSingle() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/single.kt");
@@ -1437,6 +1547,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/sumByDouble.kt");
}
@TestMetadata("sumOf.kt")
public void testSumOf() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/sumOf.kt");
}
@TestMetadata("toCollection.kt")
public void testToCollection() throws Exception {
runTest("idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/toCollection.kt");