Call chain --> Sequence: take termination into account
Related to KT-15476
This commit is contained in:
committed by
Mikhail Glukhikh
parent
108dea5b46
commit
7e28cb1fe3
+89
-13
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
class ConvertCallChainIntoSequenceInspection : AbstractKotlinInspection() {
|
class ConvertCallChainIntoSequenceInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) =
|
||||||
@@ -54,8 +55,7 @@ private class ConvertCallChainIntoSequenceFix : LocalQuickFix {
|
|||||||
val lastCall = calls.lastOrNull() ?: return
|
val lastCall = calls.lastOrNull() ?: return
|
||||||
val first = firstCall.parent as? KtQualifiedExpression ?: return
|
val first = firstCall.parent as? KtQualifiedExpression ?: return
|
||||||
val last = lastCall.parent as? KtQualifiedExpression ?: return
|
val last = lastCall.parent as? KtQualifiedExpression ?: return
|
||||||
val next = last.parent as? KtQualifiedExpression
|
val endWithTermination = lastCall.isTermination()
|
||||||
val nextType = next?.getCallableDescriptor()?.returnType
|
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(expression)
|
val psiFactory = KtPsiFactory(expression)
|
||||||
val dot = buildString {
|
val dot = buildString {
|
||||||
@@ -76,11 +76,7 @@ private class ConvertCallChainIntoSequenceFix : LocalQuickFix {
|
|||||||
)
|
)
|
||||||
firstCommentSaver.restore(firstReplaced)
|
firstCommentSaver.restore(firstReplaced)
|
||||||
|
|
||||||
val nextDescriptor = next?.getCallableDescriptor()
|
if (!endWithTermination) {
|
||||||
if (nextDescriptor == null
|
|
||||||
|| !nextDescriptor.fqNameSafe.asString().startsWith("kotlin.sequences.")
|
|
||||||
|| nextDescriptor.returnType != nextType
|
|
||||||
) {
|
|
||||||
val lastCommentSaver = CommentSaver(last)
|
val lastCommentSaver = CommentSaver(last)
|
||||||
val lastReplaced = last.replace(
|
val lastReplaced = last.replace(
|
||||||
psiFactory.buildExpression {
|
psiFactory.buildExpression {
|
||||||
@@ -100,9 +96,10 @@ private fun KtQualifiedExpression.findTarget(): Pair<KtQualifiedExpression, KtCa
|
|||||||
val calls = collectCallExpression()
|
val calls = collectCallExpression()
|
||||||
if (calls.isEmpty()) return null
|
if (calls.isEmpty()) return null
|
||||||
|
|
||||||
|
val receiverType = (calls.last().parent as? KtQualifiedExpression)?.receiverExpression?.getCallableDescriptor()?.returnType
|
||||||
|
if (receiverType?.isCollection() != true) return null
|
||||||
|
|
||||||
val qualified = calls.first().parent as? KtQualifiedExpression ?: return null
|
val qualified = calls.first().parent as? KtQualifiedExpression ?: return null
|
||||||
val fqName = qualified.getCallableDescriptor()?.returnType?.constructor?.declarationDescriptor?.fqNameSafe
|
|
||||||
if (fqName != KotlinBuiltIns.FQ_NAMES.list) return null
|
|
||||||
return qualified to calls.last()
|
return qualified to calls.last()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,20 +118,28 @@ private fun KtQualifiedExpression.collectCallExpression(): List<KtCallExpression
|
|||||||
|
|
||||||
val transformationCalls = calls
|
val transformationCalls = calls
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.dropWhile { !it.isTransformation() }
|
.dropWhile { !it.isTransformationOrTermination() }
|
||||||
.takeWhile { it.isTransformation() && !it.hasReturn() }
|
.takeWhile { it.isTransformationOrTermination() && !it.hasReturn() }
|
||||||
.toList()
|
.toList()
|
||||||
if (transformationCalls.size < 2) return emptyList()
|
if (transformationCalls.size < 2) return emptyList()
|
||||||
|
|
||||||
return transformationCalls
|
return transformationCalls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KotlinType.isCollection(): Boolean =
|
||||||
|
constructor.declarationDescriptor?.fqNameSafe == KotlinBuiltIns.FQ_NAMES.collection || constructor.supertypes.any { it.isCollection() }
|
||||||
|
|
||||||
private fun KtCallExpression.hasReturn(): Boolean = valueArguments.any { arg ->
|
private fun KtCallExpression.hasReturn(): Boolean = valueArguments.any { arg ->
|
||||||
arg.anyDescendantOfType<KtReturnExpression> { it.labelQualifier == null }
|
arg.anyDescendantOfType<KtReturnExpression> { it.labelQualifier == null }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtCallExpression.isTransformation(): Boolean {
|
private fun KtCallExpression.isTransformationOrTermination(): Boolean {
|
||||||
val fqName = transformations[calleeExpression?.text] ?: return false
|
val fqName = transformationAndTerminations[calleeExpression?.text] ?: return false
|
||||||
|
return fqName == getCallableDescriptor()?.fqNameSafe
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtCallExpression.isTermination(): Boolean {
|
||||||
|
val fqName = terminations[calleeExpression?.text] ?: return false
|
||||||
return fqName == getCallableDescriptor()?.fqNameSafe
|
return fqName == getCallableDescriptor()?.fqNameSafe
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,5 +172,76 @@ private val transformations = listOf(
|
|||||||
"take",
|
"take",
|
||||||
"takeWhile",
|
"takeWhile",
|
||||||
"windowed",
|
"windowed",
|
||||||
|
"withIndex",
|
||||||
"zipWithNext"
|
"zipWithNext"
|
||||||
).associate { it to FqName("kotlin.collections.$it") }
|
).associate { it to FqName("kotlin.collections.$it") }
|
||||||
|
|
||||||
|
private val terminations = listOf(
|
||||||
|
"all",
|
||||||
|
"any",
|
||||||
|
"asIterable",
|
||||||
|
"asSequence",
|
||||||
|
"associate",
|
||||||
|
"associateBy",
|
||||||
|
"associateByTo",
|
||||||
|
"associateTo",
|
||||||
|
"average",
|
||||||
|
"contains",
|
||||||
|
"count",
|
||||||
|
"elementAt",
|
||||||
|
"elementAtOrElse",
|
||||||
|
"elementAtOrNull",
|
||||||
|
"filterIndexedTo",
|
||||||
|
"filterIsInstanceTo",
|
||||||
|
"filterNotNullTo",
|
||||||
|
"filterNotTo",
|
||||||
|
"filterTo",
|
||||||
|
"find",
|
||||||
|
"findLast",
|
||||||
|
"first",
|
||||||
|
"firstOrNull",
|
||||||
|
"fold",
|
||||||
|
"foldIndexed",
|
||||||
|
"groupBy",
|
||||||
|
"groupByTo",
|
||||||
|
"groupingBy",
|
||||||
|
"indexOf",
|
||||||
|
"indexOfFirst",
|
||||||
|
"indexOfLast",
|
||||||
|
"joinTo",
|
||||||
|
"joinToString",
|
||||||
|
"last",
|
||||||
|
"lastIndexOf",
|
||||||
|
"lastOrNull",
|
||||||
|
"mapIndexedNotNullTo",
|
||||||
|
"mapIndexedTo",
|
||||||
|
"mapNotNullTo",
|
||||||
|
"mapTo",
|
||||||
|
"max",
|
||||||
|
"maxBy",
|
||||||
|
"maxWith",
|
||||||
|
"min",
|
||||||
|
"minBy",
|
||||||
|
"minWith",
|
||||||
|
"none",
|
||||||
|
"partition",
|
||||||
|
"reduce",
|
||||||
|
"reduceIndexed",
|
||||||
|
"single",
|
||||||
|
"singleOrNull",
|
||||||
|
"sum",
|
||||||
|
"sumBy",
|
||||||
|
"sumByDouble",
|
||||||
|
"toCollection",
|
||||||
|
"toHashSet",
|
||||||
|
"toList",
|
||||||
|
"toMutableList",
|
||||||
|
"toMutableSet",
|
||||||
|
"toSet",
|
||||||
|
"toSortedSet"
|
||||||
|
).associate {
|
||||||
|
val pkg = if (it in listOf("contains", "indexOf", "lastIndexOf")) "kotlin.collections.List" else "kotlin.collections"
|
||||||
|
it to FqName("$pkg.$it")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val transformationAndTerminations = transformations + terminations
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
fun test(list: List<Int>): List<Pair<IndexedValue<List<Int>>, IndexedValue<List<Int>>>> {
|
||||||
return list
|
return list
|
||||||
.<caret>chunked(1)
|
.<caret>chunked(1)
|
||||||
.distinct()
|
.distinct()
|
||||||
@@ -30,6 +30,7 @@ fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
|||||||
.take(1)
|
.take(1)
|
||||||
.takeWhile { true }
|
.takeWhile { true }
|
||||||
.windowed(1, 1, true)
|
.windowed(1, 1, true)
|
||||||
|
.withIndex()
|
||||||
.zipWithNext()
|
.zipWithNext()
|
||||||
.zipWithNext { a, b -> a }
|
.zipWithNext { a, b -> a }
|
||||||
}
|
}
|
||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
fun test(list: List<Int>): List<Pair<IndexedValue<List<Int>>, IndexedValue<List<Int>>>> {
|
||||||
return list
|
return list
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.chunked(1)
|
.chunked(1)
|
||||||
@@ -31,6 +31,7 @@ fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
|||||||
.take(1)
|
.take(1)
|
||||||
.takeWhile { true }
|
.takeWhile { true }
|
||||||
.windowed(1, 1, true)
|
.windowed(1, 1, true)
|
||||||
|
.withIndex()
|
||||||
.zipWithNext()
|
.zipWithNext()
|
||||||
.zipWithNext { a, b -> a }
|
.zipWithNext { a, b -> a }
|
||||||
.toList()
|
.toList()
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return mutableListOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return mutableListOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.toList()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return mutableSetOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return mutableSetOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.toList()
|
||||||
|
}
|
||||||
Vendored
+4
-1
@@ -2,5 +2,8 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
fun test(list: List<Int>): List<Int> {
|
fun test(list: List<Int>): List<Int> {
|
||||||
return list.filter { it > 2 }.dropLast(1).<caret>filter { it > 2 }
|
return list
|
||||||
|
.filter { it > 2 }
|
||||||
|
.dropLast(1)
|
||||||
|
.<caret>filter { it > 2 }
|
||||||
}
|
}
|
||||||
Vendored
-1
@@ -4,7 +4,6 @@
|
|||||||
fun test(list: List<Int>): List<Int> {
|
fun test(list: List<Int>): List<Int> {
|
||||||
return list
|
return list
|
||||||
.reversed()
|
.reversed()
|
||||||
.map { it + 1 }
|
|
||||||
.<caret>map { it + 1 }
|
.<caret>map { it + 1 }
|
||||||
.dropLast(1)
|
.dropLast(1)
|
||||||
.takeLast(2)
|
.takeLast(2)
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return setOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(): List<Int> {
|
||||||
|
return setOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.toList()
|
||||||
|
}
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
|
|
||||||
fun test(): Int {
|
|
||||||
return listOf(1, 2, 3)
|
|
||||||
.<caret>filter { it > 1 }
|
|
||||||
.map { it * 2 }
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
Vendored
-9
@@ -1,9 +0,0 @@
|
|||||||
// WITH_RUNTIME
|
|
||||||
|
|
||||||
fun test(): Int {
|
|
||||||
return listOf(1, 2, 3)
|
|
||||||
.asSequence()
|
|
||||||
.filter { it > 1 }
|
|
||||||
.map { it * 2 }
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val all: Boolean = list.<caret>filter { it > 1 }.all { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val all: Boolean = list.asSequence().filter { it > 1 }.all { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val any: Boolean = list.<caret>filter { it > 1 }.any()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val any: Boolean = list.asSequence().filter { it > 1 }.any()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val asIterable: Iterable<Int> = list.<caret>filter { it > 1 }.asIterable()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val asIterable: Iterable<Int> = list.asSequence().filter { it > 1 }.asIterable()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val asSequence: Sequence<Int> = list.<caret>filter { it > 1 }.asSequence()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val asSequence: Sequence<Int> = list.asSequence().filter { it > 1 }.asSequence()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associate: Map<Int, Int> = list.<caret>filter { it > 1 }.associate { it to it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associate: Map<Int, Int> = list.asSequence().filter { it > 1 }.associate { it to it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateBy: Map<Int, Int> = list.<caret>filter { it > 1 }.associateBy { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateBy: Map<Int, Int> = list.asSequence().filter { it > 1 }.associateBy { it }
|
||||||
|
}
|
||||||
idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/assosiateByTo.kt
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateByTo = list.<caret>filter { it > 1 }.associateByTo(mutableMapOf()) { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateByTo = list.asSequence().filter { it > 1 }.associateByTo(mutableMapOf()) { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateTo: MutableMap<Int, Int> = list.<caret>filter { it > 1 }.associateTo(mutableMapOf()) { it to it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val associateTo: MutableMap<Int, Int> = list.asSequence().filter { it > 1 }.associateTo(mutableMapOf()) { it to it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val average: Double = list.<caret>filter { it > 1 }.average()
|
||||||
|
}
|
||||||
idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/average.kt.after
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val average: Double = list.asSequence().filter { it > 1 }.average()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val contains: Boolean = list.<caret>filter { it > 1 }.contains(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val contains: Boolean = list.asSequence().filter { it > 1 }.contains(1)
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val count: Int = list.<caret>filter { it > 1 }.count()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val count: Int = list.asSequence().filter { it > 1 }.count()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAt = list.<caret>filter { it > 1 }.elementAt(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAt = list.asSequence().filter { it > 1 }.elementAt(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAtOrElse: Int = list.<caret>filter { it > 1 }.elementAtOrElse(1) { 1 }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAtOrElse: Int = list.asSequence().filter { it > 1 }.elementAtOrElse(1) { 1 }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAtOrNull: Int? = list.<caret>filter { it > 1 }.elementAtOrNull(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val elementAtOrNull: Int? = list.asSequence().filter { it > 1 }.elementAtOrNull(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterIndexedTo: MutableList<Int> = list.<caret>filter { it > 1 }.filterIndexedTo(mutableListOf()) { index, it -> true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterIndexedTo: MutableList<Int> = list.asSequence().filter { it > 1 }.filterIndexedTo(mutableListOf()) { index, it -> true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterIsInstanceTo = list.<caret>filter { it > 1 }.filterIsInstanceTo(mutableListOf<Int>())
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterIsInstanceTo = list.asSequence().filter { it > 1 }.filterIsInstanceTo(mutableListOf<Int>())
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterNotNullTo: MutableList<Int> = list.<caret>filter { it > 1 }.filterNotNullTo(mutableListOf())
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterNotNullTo: MutableList<Int> = list.asSequence().filter { it > 1 }.filterNotNullTo(mutableListOf())
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterNotTo: MutableList<Int> = list.<caret>filter { it > 1 }.filterNotTo(mutableListOf()) { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterNotTo: MutableList<Int> = list.asSequence().filter { it > 1 }.filterNotTo(mutableListOf()) { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterTo: MutableList<Int> = list.<caret>filter { it > 1 }.filterTo(mutableListOf()) { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val filterTo: MutableList<Int> = list.asSequence().filter { it > 1 }.filterTo(mutableListOf()) { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val find: Int? = list.<caret>filter { it > 1 }.find { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val find: Int? = list.asSequence().filter { it > 1 }.find { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val findLast: Int? = list.<caret>filter { it > 1 }.findLast { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val findLast: Int? = list.asSequence().filter { it > 1 }.findLast { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val first: Int = list.<caret>filter { it > 1 }.first()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val first: Int = list.asSequence().filter { it > 1 }.first()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val firstOrNull: Int? = list.<caret>filter { it > 1 }.firstOrNull()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val firstOrNull: Int? = list.asSequence().filter { it > 1 }.firstOrNull()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val fold: Int = list.<caret>filter { it > 1 }.fold(0) { acc, i -> acc + i }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val fold: Int = list.asSequence().filter { it > 1 }.fold(0) { acc, i -> acc + i }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val foldIndexed = list.<caret>filter { it > 1 }.foldIndexed(0) { index, acc, i -> acc + i }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val foldIndexed = list.asSequence().filter { it > 1 }.foldIndexed(0) { index, acc, i -> acc + i }
|
||||||
|
}
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val forEach: Unit = list.<caret>filter { it > 1 }.forEach { }
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val forEachIndexed: Unit = list.<caret>filter { it > 1 }.forEachIndexed { index, i -> }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupBy = list.<caret>filter { it > 1 }.groupBy { it }
|
||||||
|
}
|
||||||
idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/groupBy.kt.after
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupBy = list.asSequence().filter { it > 1 }.groupBy { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupByTo: MutableMap<Int, MutableList<Int>> = list.<caret>filter { it > 1 }.groupByTo(mutableMapOf()) { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupByTo: MutableMap<Int, MutableList<Int>> = list.asSequence().filter { it > 1 }.groupByTo(mutableMapOf()) { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupingBy: Grouping<Int, Int> = list.<caret>filter { it > 1 }.groupingBy { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val groupingBy: Grouping<Int, Int> = list.asSequence().filter { it > 1 }.groupingBy { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOf: Int = list.<caret>filter { it > 1 }.indexOf(1)
|
||||||
|
}
|
||||||
idea/testData/inspectionsLocal/collections/convertCallChainIntoSequence/termination/indexOf.kt.after
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOf: Int = list.asSequence().filter { it > 1 }.indexOf(1)
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOfFirst: Int = list.<caret>filter { it > 1 }.indexOfFirst { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOfFirst: Int = list.asSequence().filter { it > 1 }.indexOfFirst { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOfLast: Int = list.<caret>filter { it > 1 }.indexOfLast { true }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val indexOfLast: Int = list.asSequence().filter { it > 1 }.indexOfLast { true }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val joinTo: StringBuilder = list.<caret>filter { it > 1 }.joinTo(StringBuilder())
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val joinTo: StringBuilder = list.asSequence().filter { it > 1 }.joinTo(StringBuilder())
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val joinToString: String = list.<caret>filter { it > 1 }.joinToString()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val joinToString: String = list.asSequence().filter { it > 1 }.joinToString()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val last: Int = list.<caret>filter { it > 1 }.last()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val last: Int = list.asSequence().filter { it > 1 }.last()
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val lastIndexOf: Int = list.<caret>filter { it > 1 }.lastIndexOf(1)
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val lastIndexOf: Int = list.asSequence().filter { it > 1 }.lastIndexOf(1)
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val lastOrNull = list.<caret>filter { it > 1 }.lastOrNull()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val lastOrNull = list.asSequence().filter { it > 1 }.lastOrNull()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapIndexedNotNullTo: MutableList<Int> = list.<caret>filter { it > 1 }.mapIndexedNotNullTo(mutableListOf()) { index, i -> i }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapIndexedNotNullTo: MutableList<Int> = list.asSequence().filter { it > 1 }.mapIndexedNotNullTo(mutableListOf()) { index, i -> i }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapIndexedTo: MutableList<Int> = list.<caret>filter { it > 1 }.mapIndexedTo(mutableListOf()) { index, i -> i }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapIndexedTo: MutableList<Int> = list.asSequence().filter { it > 1 }.mapIndexedTo(mutableListOf()) { index, i -> i }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapNotNullTo: MutableList<Int> = list.<caret>filter { it > 1 }.mapNotNullTo(mutableListOf()) { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapNotNullTo: MutableList<Int> = list.asSequence().filter { it > 1 }.mapNotNullTo(mutableListOf()) { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapTo: MutableList<Int> = list.<caret>filter { it > 1 }.mapTo(mutableListOf()) { it }
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val mapTo: MutableList<Int> = list.asSequence().filter { it > 1 }.mapTo(mutableListOf()) { it }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun test(list: List<Int>) {
|
||||||
|
val max: Int? = list.<caret>filter { it > 1 }.max()
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user