diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/LoopToCallChainIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/LoopToCallChainIntention.kt index 16759cb517b..aa0d6f62681 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/LoopToCallChainIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/LoopToCallChainIntention.kt @@ -33,7 +33,23 @@ class LoopToCallChainIntention : SelfTargetingRangeIntention( "Replace with stdlib operations" ) { override fun applicabilityRange(element: KtForExpression): TextRange? { - return if (match(element) != null) element.forKeyword.textRange else null + val match = match(element) + text = if (match != null) "Replace with '${match.buildPresentation()}'" else defaultText + return if (match != null) element.forKeyword.textRange else null + } + + private fun ResultTransformationMatch.buildPresentation(): String { + var transformations = sequenceTransformations + resultTransformation + val MAX = 3 + var result: String? = null + if (transformations.size > MAX) { + transformations = transformations.drop(transformations.size - MAX) + result = ".." + } + for (transformation in transformations) { + result = transformation.buildPresentation(result) + } + return result!! } override fun applyTo(element: KtForExpression, editor: Editor?) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/interfaces.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/interfaces.kt index ca042dd3464..d00e3507309 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/interfaces.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/interfaces.kt @@ -40,6 +40,15 @@ interface Transformation { val inputVariable: KtCallableDeclaration val loop: KtForExpression + val presentation: String + + open fun buildPresentation(prevTransformationsPresentation: String?): String { + return if (prevTransformationsPresentation != null) + prevTransformationsPresentation + "." + presentation + else + presentation + } + fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt index ae7ba0ba203..1c2d5d70268 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/AddToCollectionTransformation.kt @@ -55,6 +55,16 @@ class AddToCollectionTransformation( } } + override val presentation: String + get() = "+=" + + override fun buildPresentation(prevTransformationsPresentation: String?): String { + return if (prevTransformationsPresentation != null) + "+= $prevTransformationsPresentation" + else + "+=" + } + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return KtPsiFactory(loop).createExpressionByPattern("$0 += $1", targetCollection, chainedCallGenerator.receiver) } @@ -170,6 +180,9 @@ class FilterToTransformation private constructor( private val filter: KtExpression ) : ReplaceLoopResultTransformation(loop, inputVariable) { + override val presentation: String + get() = "filterTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, filter) return chainedCallGenerator.generate("filterTo($0) $1:'{}'", targetCollection, lambda) @@ -200,6 +213,9 @@ class AssignFilterToTransformation( private val filter: KtExpression ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { + override val presentation: String + get() = "filterTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, filter) return chainedCallGenerator.generate("filterTo($0) $1:'{}'", initialization.initializer, lambda) @@ -213,6 +229,9 @@ class MapToTransformation private constructor( private val mapping: KtExpression ) : ReplaceLoopResultTransformation(loop, inputVariable) { + override val presentation: String + get() = "mapTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, mapping) return chainedCallGenerator.generate("mapTo($0) $1:'{}'", targetCollection, lambda) @@ -243,6 +262,9 @@ class AssignMapToTransformation( private val mapping: KtExpression ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { + override val presentation: String + get() = "mapTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, mapping) return chainedCallGenerator.generate("mapTo($0) $1:'{}'", initialization.initializer, lambda) @@ -256,6 +278,9 @@ class FlatMapToTransformation private constructor( private val transform: KtExpression ) : ReplaceLoopResultTransformation(loop, inputVariable) { + override val presentation: String + get() = "flatMapTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, transform) return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", targetCollection, lambda) @@ -286,6 +311,9 @@ class AssignFlatMapToTransformation( private val transform: KtExpression ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { + override val presentation: String + get() = "flatMapTo(){}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, transform) return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", initialization.initializer, lambda) @@ -298,6 +326,9 @@ class AssignToListTransformation( initialization: VariableInitialization ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { + override val presentation: String + get() = "toList()" + override fun mergeWithPrevious(previousTransformation: SequenceTransformation): ResultTransformation? { if (previousTransformation !is FilterTransformation) return null return AssignSequenceTransformationResultTransformation(previousTransformation, initialization) @@ -314,6 +345,9 @@ class AssignToMutableListTransformation( initialization: VariableInitialization ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { + override val presentation: String + get() = "toMutableList()" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return chainedCallGenerator.generate("toMutableList()") } @@ -325,6 +359,9 @@ class AssignToSetTransformation( initialization: VariableInitialization ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { + override val presentation: String + get() = "toSet()" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return chainedCallGenerator.generate("toSet()") } @@ -336,6 +373,9 @@ class AssignToMutableSetTransformation( initialization: VariableInitialization ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { + override val presentation: String + get() = "toMutableSet()" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return chainedCallGenerator.generate("toMutableSet()") } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndAssignTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndAssignTransformation.kt index 386cd18a312..d43a12ebb22 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndAssignTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndAssignTransformation.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class FindAndAssignTransformation( loop: KtForExpression, inputVariable: KtCallableDeclaration, - private val generator: (chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression, + private val generator: FindOperatorGenerator, initialization: VariableInitialization, private val filter: KtExpression? = null ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { @@ -40,8 +40,11 @@ class FindAndAssignTransformation( return FindAndAssignTransformation(loop, previousTransformation.inputVariable, generator, initialization, previousTransformation.effectiveCondition()) } + override val presentation: String + get() = generator.functionName + (if (filter != null) "{}" else "()") + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { - return generator(chainedCallGenerator, filter) + return generator.generate(chainedCallGenerator, filter) } /** diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndReturnTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndReturnTransformation.kt index e8b6b810a2e..aa4ecf9370e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndReturnTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/result/FindAndReturnTransformation.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange class FindAndReturnTransformation( override val loop: KtForExpression, override val inputVariable: KtCallableDeclaration, - private val generator: (chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression, + private val generator: FindOperatorGenerator, private val endReturn: KtReturnExpression, private val filter: KtExpression? = null ) : ResultTransformation { @@ -44,8 +44,11 @@ class FindAndReturnTransformation( override fun commentRestoringRange(convertLoopResult: KtExpression) = commentRestoringRange + override val presentation: String + get() = generator.functionName + (if (filter != null) "{}" else "()") + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { - return generator(chainedCallGenerator, filter) + return generator.generate(chainedCallGenerator, filter) } override fun convertLoop(resultCallChain: KtExpression): KtExpression { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt index f0b6e61a7dc..50be9170781 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt @@ -43,6 +43,9 @@ class FilterTransformation( override val affectsIndex: Boolean get() = true + override val presentation: String + get() = if (isInverse) "filterNot{}" else "filter{}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, condition) val name = if (isInverse) "filterNot" else "filter" @@ -128,6 +131,9 @@ class FilterIsInstanceTransformation( override val affectsIndex: Boolean get() = true + override val presentation: String + get() = "filterIsInstance<>()" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return chainedCallGenerator.generate("filterIsInstance<$0>()", type) } @@ -141,6 +147,9 @@ class FilterNotNullTransformation( override val affectsIndex: Boolean get() = true + override val presentation: String + get() = "filterNotNull()" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return chainedCallGenerator.generate("filterNotNull()") } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FlatMapTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FlatMapTransformation.kt index 06a2fbd5a8e..492efb13e9c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FlatMapTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FlatMapTransformation.kt @@ -34,6 +34,9 @@ class FlatMapTransformation( override val affectsIndex: Boolean get() = true + override val presentation: String + get() = "flatMap{}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, transform) return chainedCallGenerator.generate("flatMap$0:'{}'", lambda) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/MapTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/MapTransformation.kt index f3aed211e53..7b42e909d2b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/MapTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/MapTransformation.kt @@ -31,6 +31,9 @@ class MapTransformation( override val affectsIndex: Boolean get() = false + override val presentation: String + get() = "map{}" + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { val lambda = generateLambda(inputVariable, mapping) return chainedCallGenerator.generate("map$0:'{}'", lambda) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt index a1312c73d39..c4573b41272 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt @@ -112,12 +112,17 @@ fun KtProperty.hasWriteUsages(): Boolean { } } +interface FindOperatorGenerator { + val functionName: String + fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression +} + fun buildFindOperationGenerator( valueIfFound: KtExpression, valueIfNotFound: KtExpression, inputVariable: KtCallableDeclaration, findFirst: Boolean -): ((chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression)? { +): FindOperatorGenerator? { assert(valueIfFound.isPhysical) assert(valueIfNotFound.isPhysical) @@ -131,36 +136,40 @@ fun buildFindOperationGenerator( } } + class SimpleGenerator(override val functionName: String) : FindOperatorGenerator { + override fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression { + return generateChainedCall(functionName, chainedCallGenerator, filter) + } + } + val inputVariableCanHoldNull = (inputVariable.resolveToDescriptor() as VariableDescriptor).type.nullability() != TypeNullability.NOT_NULL - fun ((chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression).useElvisOperatorIfNeeded(): ((chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression)? { + fun FindOperatorGenerator.useElvisOperatorIfNeeded(): FindOperatorGenerator? { if (valueIfNotFound.isNullExpression()) return this // we cannot use ?: if found value can be null if (inputVariableCanHoldNull) return null - return { chainedCallGenerator, filter -> - val generated = this(chainedCallGenerator, filter) - KtPsiFactory(generated).createExpressionByPattern("$0 ?: $1", generated, valueIfNotFound) + return object: FindOperatorGenerator { + override val functionName: String + get() = this@useElvisOperatorIfNeeded.functionName + + override fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression { + val generated = this@useElvisOperatorIfNeeded.generate(chainedCallGenerator, filter) + return KtPsiFactory(generated).createExpressionByPattern("$0 ?: $1", generated, valueIfNotFound) + } } } when { valueIfFound.isVariableReference(inputVariable) -> { - val stdlibFunName = if (findFirst) "firstOrNull" else "lastOrNull" - val generator = { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? -> - generateChainedCall(stdlibFunName, chainedCallGenerator, filter) - } + val generator = SimpleGenerator(if (findFirst) "firstOrNull" else "lastOrNull") return generator.useElvisOperatorIfNeeded() } - valueIfFound.isTrueConstant() && valueIfNotFound.isFalseConstant() -> { - return { chainedCallGenerator, filter -> generateChainedCall("any", chainedCallGenerator, filter) } - } + valueIfFound.isTrueConstant() && valueIfNotFound.isFalseConstant() -> return SimpleGenerator("any") - valueIfFound.isFalseConstant() && valueIfNotFound.isTrueConstant() -> { - return { chainedCallGenerator, filter -> generateChainedCall("none", chainedCallGenerator, filter) } - } + valueIfFound.isFalseConstant() && valueIfNotFound.isTrueConstant() -> return SimpleGenerator("none") inputVariable.hasUsages(valueIfFound) -> { if (!findFirst) return null // too dangerous because of side effects @@ -171,9 +180,14 @@ fun buildFindOperationGenerator( val receiver = qualifiedExpression.receiverExpression val selector = qualifiedExpression.selectorExpression if (receiver.isVariableReference(inputVariable) && selector != null && !inputVariable.hasUsages(selector)) { - return { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? -> - val findFirstCall = generateChainedCall("firstOrNull", chainedCallGenerator, filter) - KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.$1", findFirstCall, selector) + return object: FindOperatorGenerator { + override val functionName: String + get() = "firstOrNull" + + override fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression { + val findFirstCall = generateChainedCall(functionName, chainedCallGenerator, filter) + return KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.$1", findFirstCall, selector) + } }.useElvisOperatorIfNeeded() } } @@ -181,17 +195,27 @@ fun buildFindOperationGenerator( // in case of nullable input variable we cannot distinguish by the result of "firstOrNull" whether nothing was found or 'null' was found if (inputVariableCanHoldNull) return null - return { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? -> - val findFirstCall = generateChainedCall("firstOrNull", chainedCallGenerator, filter) - val letBody = generateLambda(inputVariable, valueIfFound) - KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.let $1:'{}'", findFirstCall, letBody) + return object: FindOperatorGenerator { + override val functionName: String + get() = "firstOrNull" //TODO + + override fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression { + val findFirstCall = generateChainedCall(functionName, chainedCallGenerator, filter) + val letBody = generateLambda(inputVariable, valueIfFound) + return KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.let $1:'{}'", findFirstCall, letBody) + } }.useElvisOperatorIfNeeded() } else -> { - return { chainedCallGenerator, filter -> - val chainedCall = generateChainedCall("any", chainedCallGenerator, filter) - KtPsiFactory(chainedCall).createExpressionByPattern("if ($0) $1 else $2", chainedCall, valueIfFound, valueIfNotFound) + return object: FindOperatorGenerator { + override val functionName: String + get() = "any" + + override fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression { + val chainedCall = generateChainedCall(functionName, chainedCallGenerator, filter) + return KtPsiFactory(chainedCall).createExpressionByPattern("if ($0) $1 else $2", chainedCall, valueIfFound, valueIfNotFound) + } } } } @@ -313,6 +337,13 @@ class AssignSequenceTransformationResultTransformation( initialization: VariableInitialization ) : AssignToVariableResultTransformation(sequenceTransformation.loop, sequenceTransformation.inputVariable, initialization) { + override val presentation: String + get() = sequenceTransformation.presentation + + override fun buildPresentation(prevTransformationsPresentation: String?): String { + return sequenceTransformation.buildPresentation(prevTransformationsPresentation) + } + override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { return sequenceTransformation.generateCode(chainedCallGenerator) } diff --git a/idea/testData/intentions/loopToCallChain/addToCollection.kt b/idea/testData/intentions/loopToCallChain/addToCollection.kt index 89468ad2141..a3f3d38b1cf 100644 --- a/idea/testData/intentions/loopToCallChain/addToCollection.kt +++ b/idea/testData/intentions/loopToCallChain/addToCollection.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '+='" fun foo(list: List, target: MutableList) { for (s in list) { target.add(s) diff --git a/idea/testData/intentions/loopToCallChain/addToCollection.kt.after b/idea/testData/intentions/loopToCallChain/addToCollection.kt.after index bdf72b472a5..fb662a13435 100644 --- a/idea/testData/intentions/loopToCallChain/addToCollection.kt.after +++ b/idea/testData/intentions/loopToCallChain/addToCollection.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '+='" fun foo(list: List, target: MutableList) { target += list } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign.kt b/idea/testData/intentions/loopToCallChain/any_ifAssign.kt index b868dd48e20..dc823a0245b 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign.kt +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { var found = false for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign.kt.after b/idea/testData/intentions/loopToCallChain/any_ifAssign.kt.after index fd09759adb2..5d0f8a902f9 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { val found = list.any { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt b/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt index b284ea5dcf1..15106c2af9c 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { var found = false for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt.after b/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt.after index fd09759adb2..5d0f8a902f9 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign_noBreak.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { val found = list.any { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt b/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt index 17e7e736b41..2e73f7036f3 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { var result = 0 for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt.after b/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt.after index bf40f90df27..ae8a052f811 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_ifAssign_nonBooleanResult.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List) { val result = if (list.any { it.length > 0 }) 1 else 0 } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/any_ifReturn.kt b/idea/testData/intentions/loopToCallChain/any_ifReturn.kt index 4bc14f4a29e..0dd4ff1e3bc 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifReturn.kt +++ b/idea/testData/intentions/loopToCallChain/any_ifReturn.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List): Boolean { for (s in list) { if (s.length > 0) { diff --git a/idea/testData/intentions/loopToCallChain/any_ifReturn.kt.after b/idea/testData/intentions/loopToCallChain/any_ifReturn.kt.after index 9ea88dff52e..fad34492c7a 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifReturn.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_ifReturn.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List): Boolean { return list.any { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt b/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt index 3183f3afce8..9b37cedb621 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt +++ b/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List): Int { for (s in list) { if (s.length > 0) { diff --git a/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt.after b/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt.after index d09c043b311..546c3c2ec78 100644 --- a/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_ifReturn_nonBooleanResult.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List): Int { return if (list.any { it.length > 0 }) -1 else takeInt() } diff --git a/idea/testData/intentions/loopToCallChain/any_return.kt b/idea/testData/intentions/loopToCallChain/any_return.kt index 70ee9498b99..923129475f7 100644 --- a/idea/testData/intentions/loopToCallChain/any_return.kt +++ b/idea/testData/intentions/loopToCallChain/any_return.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any()'" fun foo(list: List): Boolean { for (s in list) { return true diff --git a/idea/testData/intentions/loopToCallChain/any_return.kt.after b/idea/testData/intentions/loopToCallChain/any_return.kt.after index 9fbc88d15c3..db6dcf84008 100644 --- a/idea/testData/intentions/loopToCallChain/any_return.kt.after +++ b/idea/testData/intentions/loopToCallChain/any_return.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any()'" fun foo(list: List): Boolean { return list.any() } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/assignFilter.kt b/idea/testData/intentions/loopToCallChain/assignFilter.kt index 4176eb06310..6279c957b15 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter.kt.after index d9e1916c29d..d22853926bb 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter2.kt b/idea/testData/intentions/loopToCallChain/assignFilter2.kt index f756a363cdb..b326df270c6 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter2.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(list: List, p: Int): List { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter2.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter2.kt.after index a20e01608db..b35198b5954 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter2.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(list: List, p: Int): List { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt index 1366a23a335..250501a5984 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.ArrayList fun foo(list: List): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt.after index 3c46f7c8610..5d6c598537c 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.ArrayList fun foo(list: List): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt index 890d4f8456b..37258137dab 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.ArrayList fun foo(list: List, p: Int): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt.after index 3a734969cfb..139df1b3467 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.ArrayList fun foo(list: List, p: Int): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt index 393ca2b4d2e..d72439126b3 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.* fun foo(list: List): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt.after index 2f78ebc5387..729452260ef 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter_ArrayListRequired3.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" import java.util.* fun foo(list: List): ArrayList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt b/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt index e2458bd74bc..42288ec8d7b 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.toMutableList()'" import java.util.ArrayList fun foo(list: List): MutableList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt.after index b7117e200b3..2d468694d2d 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter_MutableListRequired.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.toMutableList()'" import java.util.ArrayList fun foo(list: List): MutableList { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt b/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt index f38419eae34..ad76817eeb6 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt +++ b/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(): List { diff --git a/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt.after b/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt.after index 632d876548f..c0644ce4490 100644 --- a/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignFilter_breakAndContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}'" import java.util.ArrayList fun foo(): List { diff --git a/idea/testData/intentions/loopToCallChain/assignMap.kt b/idea/testData/intentions/loopToCallChain/assignMap.kt index beb502fa41b..f2f97c28baa 100644 --- a/idea/testData/intentions/loopToCallChain/assignMap.kt +++ b/idea/testData/intentions/loopToCallChain/assignMap.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.map{}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/assignMap.kt.after b/idea/testData/intentions/loopToCallChain/assignMap.kt.after index 0918a8afa72..d9f65c3fd7b 100644 --- a/idea/testData/intentions/loopToCallChain/assignMap.kt.after +++ b/idea/testData/intentions/loopToCallChain/assignMap.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.map{}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/filterIsInstance.kt b/idea/testData/intentions/loopToCallChain/filterIsInstance.kt index 50c2f1a3972..5cc56d506a9 100644 --- a/idea/testData/intentions/loopToCallChain/filterIsInstance.kt +++ b/idea/testData/intentions/loopToCallChain/filterIsInstance.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'" fun foo(list: List): Int? { for (o in list) { if (o is String) { diff --git a/idea/testData/intentions/loopToCallChain/filterIsInstance.kt.after b/idea/testData/intentions/loopToCallChain/filterIsInstance.kt.after index 520d2755b99..ea7ba4023ec 100644 --- a/idea/testData/intentions/loopToCallChain/filterIsInstance.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterIsInstance.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'" fun foo(list: List): Int? { return list .filterIsInstance() diff --git a/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt b/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt index 7a361f37264..341badbcf83 100644 --- a/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt +++ b/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'" fun foo(list: List): Int? { for (o in list) { if (o !is String) continue diff --git a/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt.after b/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt.after index 520d2755b99..ea7ba4023ec 100644 --- a/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterIsInstance_ifContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'" fun foo(list: List): Int? { return list .filterIsInstance() diff --git a/idea/testData/intentions/loopToCallChain/filterNotNull.kt b/idea/testData/intentions/loopToCallChain/filterNotNull.kt index 9854f3b53ef..1568629e637 100644 --- a/idea/testData/intentions/loopToCallChain/filterNotNull.kt +++ b/idea/testData/intentions/loopToCallChain/filterNotNull.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'" fun foo(list: List): Int? { for (s in list) { if (s != null) { diff --git a/idea/testData/intentions/loopToCallChain/filterNotNull.kt.after b/idea/testData/intentions/loopToCallChain/filterNotNull.kt.after index e058daf6cd1..dcf15bb6767 100644 --- a/idea/testData/intentions/loopToCallChain/filterNotNull.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterNotNull.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'" fun foo(list: List): Int? { return list .filterNotNull() diff --git a/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt b/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt index 4cad52eab77..fed19dc9b94 100644 --- a/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt +++ b/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'" fun foo(list: List): Int? { for (o in list) { if (o == null) continue diff --git a/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt.after b/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt.after index bd2c62248b0..85d51b00bba 100644 --- a/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterNotNull_ifContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'" fun foo(list: List): Int? { return list .filterNotNull() diff --git a/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt b/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt index 4c5d9b99104..d1e74c23d8a 100644 --- a/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt +++ b/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNot{}.map{}.firstOrNull()'" fun foo(list: List): Int? { for (s in list) { if (s.isEmpty()) continue diff --git a/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt.after b/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt.after index 83a3cdd96ff..34ac70fb56a 100644 --- a/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterNot_ifContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterNot{}.map{}.firstOrNull()'" fun foo(list: List): Int? { return list .filterNot { it.isEmpty() } diff --git a/idea/testData/intentions/loopToCallChain/filterTo.kt b/idea/testData/intentions/loopToCallChain/filterTo.kt index ac352e6d2e8..24a3c70e5ee 100644 --- a/idea/testData/intentions/loopToCallChain/filterTo.kt +++ b/idea/testData/intentions/loopToCallChain/filterTo.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" fun foo(list: List, target: MutableList) { for (s in list) { if (s.length > 0) diff --git a/idea/testData/intentions/loopToCallChain/filterTo.kt.after b/idea/testData/intentions/loopToCallChain/filterTo.kt.after index 4157c689b97..40c646820fc 100644 --- a/idea/testData/intentions/loopToCallChain/filterTo.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterTo.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" fun foo(list: List, target: MutableList) { list.filterTo(target) { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/filterTo2.kt b/idea/testData/intentions/loopToCallChain/filterTo2.kt index 0e4c50a82a1..d9b8845d6a1 100644 --- a/idea/testData/intentions/loopToCallChain/filterTo2.kt +++ b/idea/testData/intentions/loopToCallChain/filterTo2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" fun foo(list: List) { val target = createCollection() for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/filterTo2.kt.after b/idea/testData/intentions/loopToCallChain/filterTo2.kt.after index 41a98d1c40c..641d0ff05eb 100644 --- a/idea/testData/intentions/loopToCallChain/filterTo2.kt.after +++ b/idea/testData/intentions/loopToCallChain/filterTo2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filterTo(){}'" fun foo(list: List) { val target = createCollection() list.filterTo(target) { it.length > 0 } diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt b/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt index f7ee7de0713..25c19e283b1 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { for (s in list) { if (s.isEmpty()) continue diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt.after b/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt.after index f0cb4a66221..7478c511744 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { return list.firstOrNull { !it.isEmpty() } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt b/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt index abe2d4462e8..f69e1faeae6 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { for (s in list) { if (!s.isEmpty()) continue diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt.after b/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt.after index 68cbd908b51..e1bcb0743d1 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt.after +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinue2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { return list.firstOrNull { it.isEmpty() } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt b/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt index 9c7df778b7f..323626a1c30 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { for (s in list) { if (s.isEmpty()) { diff --git a/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt.after b/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt.after index f0cb4a66221..7478c511744 100644 --- a/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt.after +++ b/idea/testData/intentions/loopToCallChain/filter_ifContinueInBlock.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { return list.firstOrNull { !it.isEmpty() } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt b/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt index 0d400e62205..97cac304f92 100644 --- a/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt +++ b/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.map{}.firstOrNull()'" fun foo(list: List): String? { for (s in list) { if (s.isEmpty()) continue diff --git a/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt.after b/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt.after index 3eda4d2a5b7..8e5695a2d46 100644 --- a/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt.after +++ b/idea/testData/intentions/loopToCallChain/filter_mergeMultiple.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.map{}.firstOrNull()'" fun foo(list: List): String? { return list .filter { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt index 2303fc20329..70c4de29415 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = "" diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt.after index e1ae7ae8556..4921bac310d 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_assignmentInitialization.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = "" diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt index 913ba2f7717..b3d721456d0 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt.after index 59861dac227..da5894d8436 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result: String? = list.firstOrNull { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt index 68f50b6227c..22158797cb3 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt.after index 62b74844596..9ce187c79da 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_cannotBeVal.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = list.firstOrNull { it.length > 0 } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt index ee520cce9b1..58108c325f7 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { // search for first non-empty string in the list diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt.after index a9b987bec34..7fed0e7d82d 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifAssign_preserveComments.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result: String? = list.firstOrNull { // search for first non-empty string in the list it.length > 0 diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt index dbeb013cf82..2702f03b0ba 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { for (s in list) { if (s.length > 0) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt.after index 8e5db467919..074857a8c28 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_ifReturn.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { return list.firstOrNull { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt index dc125a973f3..91201450805 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt.after index 22ac38a35a0..8bea49b813d 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_let.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result: String? = list.firstOrNull { it.length > 0 }?.let { bar(it) } } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt index e9937f7bc83..dabcc9ae4c7 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt.after index 1e25b004c78..2eda11a721c 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_let2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result: String? = list.firstOrNull { it.length > 0 }?.let { it.substring(0, it.length - 1) } } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt index de30a83dc59..e1e0d65e9f8 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result = "" for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt.after index 024e429a018..a452fe5e3e5 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_letOrNotNull.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result = list.firstOrNull { it.length > 0 }?.let { bar(it) } ?: "" } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt index 1ddc0d2242f..6e881270ce4 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull()'" fun foo(list: List): String? { for (s in list) { return s diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt.after index 8b73d9828be..26d37bfb2fe 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_return.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull()'" fun foo(list: List): String? { return list.firstOrNull() } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt index e95eb77b314..872e6287d91 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): Int? { for (s in list) { if (s.isNotEmpty()) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt.after index a8416cb456e..459c4048fab 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpression.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): Int? { return list.firstOrNull { it.isNotEmpty() }?.length } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt index b992bdc7995..f911b1b73b1 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): Int { for (s in list) { if (s.isNotEmpty()) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt.after index d51bb1d9876..bf4e8bfc9e2 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnExpressionOrNotNull.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): Int { return list.firstOrNull { it.isNotEmpty() }?.length ?: -1 } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt index 1e2abf7f26e..6af1ddb9cfb 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String { for (s in list) { if (s.isNotEmpty()) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt.after index 39bae0eee04..e993548be15 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_returnNotNullIfNone.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String { return list.firstOrNull { it.isNotEmpty() } ?: "" } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt index f6361b940e7..d6397e54ef7 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull()'" fun foo(list: List): String? { for (s in list) { return s diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt.after index 6c995a36a6d..52dbc147c9a 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_return_comment.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull()'" fun foo(list: List): String? { // return null if not found return list.firstOrNull() diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt index 28c60180bfb..f34bb7d5038 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt.after index 5674bd90763..d8c8fbaf6c0 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_safeDotExpression.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List) { val result: String? = list.firstOrNull { it != "" }?.substring(1) } diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt b/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt index cdad088829d..e5ba339ec3d 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { for (s in list) { if (s.isEmpty()) continue diff --git a/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt.after b/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt.after index 1217edfac9b..427f43b6e0c 100644 --- a/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt.after +++ b/idea/testData/intentions/loopToCallChain/firstOrNull_withMergedFilter.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'firstOrNull{}'" fun foo(list: List): String? { return list.firstOrNull { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/flatMap.kt b/idea/testData/intentions/loopToCallChain/flatMap.kt index c47aa331112..57caae2c70c 100644 --- a/idea/testData/intentions/loopToCallChain/flatMap.kt +++ b/idea/testData/intentions/loopToCallChain/flatMap.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { for (s in list) { for (line in s.lines()) { diff --git a/idea/testData/intentions/loopToCallChain/flatMap.kt.after b/idea/testData/intentions/loopToCallChain/flatMap.kt.after index 5f01a657855..04e54759526 100644 --- a/idea/testData/intentions/loopToCallChain/flatMap.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMap.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { return list .flatMap { it.lines() } diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo.kt b/idea/testData/intentions/loopToCallChain/flatMapTo.kt index ff889d57ad6..17bc715c2c3 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo.kt +++ b/idea/testData/intentions/loopToCallChain/flatMapTo.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" fun foo(list: List, target: MutableList) { for (s in list) { for (line in s.lines()) { diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo.kt.after b/idea/testData/intentions/loopToCallChain/flatMapTo.kt.after index cd41c91bafe..78f3c136715 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMapTo.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" fun foo(list: List, target: MutableList) { list.flatMapTo(target) { it.lines() } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo2.kt b/idea/testData/intentions/loopToCallChain/flatMapTo2.kt index 3536bc0ebad..f03cf24ab83 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo2.kt +++ b/idea/testData/intentions/loopToCallChain/flatMapTo2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo2.kt.after b/idea/testData/intentions/loopToCallChain/flatMapTo2.kt.after index b56dc54682d..8a9ea3999f9 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo2.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMapTo2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo3.kt b/idea/testData/intentions/loopToCallChain/flatMapTo3.kt index 82c0296d7a8..c27591e2b01 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo3.kt +++ b/idea/testData/intentions/loopToCallChain/flatMapTo3.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" fun foo(list: List): List { val target = createCollection() for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/flatMapTo3.kt.after b/idea/testData/intentions/loopToCallChain/flatMapTo3.kt.after index 6d8693689b4..1cf490c63fb 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapTo3.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMapTo3.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMapTo(){}'" fun foo(list: List): List { val target = createCollection() list.flatMapTo(target) { it.lines() } diff --git a/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt b/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt index 2640ad0df8f..7884d5d7956 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt +++ b/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { var result: String? = null MainLoop@ diff --git a/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt.after b/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt.after index 5032a175aef..6dcf1b84bbc 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMapWithBreak.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { val result: String? = list .flatMap { it.lines() } diff --git a/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt b/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt index c7bacce5653..7b8004e1845 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt +++ b/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { for (s in list) { for (line in s.lines()) { diff --git a/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt.after b/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt.after index f2d639fee1f..a72f85c246e 100644 --- a/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt.after +++ b/idea/testData/intentions/loopToCallChain/flatMapWithContinue.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'" fun foo(list: List): String? { return list .flatMap { it.lines() } diff --git a/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt b/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt index 49a0b5f5737..55d326766de 100644 --- a/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt +++ b/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List, it: Int) { var found = false for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt.after b/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt.after index 5f97566217b..b134376c15f 100644 --- a/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt.after +++ b/idea/testData/intentions/loopToCallChain/itAlreadyUsed.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'any{}'" fun foo(list: List, it: Int) { val found = list.any { s -> s.length > it } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt b/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt index 9aade7bcfc2..08c46eb0202 100644 --- a/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt +++ b/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'lastOrNull{}'" fun foo(list: List) { var result: String? = null for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt.after b/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt.after index 0e830fecfa2..f0519cffaf2 100644 --- a/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt.after +++ b/idea/testData/intentions/loopToCallChain/lastOrNull_ifAssign.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'lastOrNull{}'" fun foo(list: List) { val result: String? = list.lastOrNull { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/map.kt b/idea/testData/intentions/loopToCallChain/map.kt index 0d8950238d0..fdff9eab6d4 100644 --- a/idea/testData/intentions/loopToCallChain/map.kt +++ b/idea/testData/intentions/loopToCallChain/map.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.firstOrNull{}'" fun foo(list: List): Int? { for (s in list) { val length = s.length diff --git a/idea/testData/intentions/loopToCallChain/map.kt.after b/idea/testData/intentions/loopToCallChain/map.kt.after index 5311e57e96a..66e475bfdfe 100644 --- a/idea/testData/intentions/loopToCallChain/map.kt.after +++ b/idea/testData/intentions/loopToCallChain/map.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.firstOrNull{}'" fun foo(list: List): Int? { return list .map { it.length } diff --git a/idea/testData/intentions/loopToCallChain/mapTo.kt b/idea/testData/intentions/loopToCallChain/mapTo.kt index 4e41d41c043..8fe2d47fb78 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo.kt +++ b/idea/testData/intentions/loopToCallChain/mapTo.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" fun foo(list: List, target: MutableList) { for (s in list) { if (s.length > 0) diff --git a/idea/testData/intentions/loopToCallChain/mapTo.kt.after b/idea/testData/intentions/loopToCallChain/mapTo.kt.after index f50cc4c7bdd..19fdb4b8503 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo.kt.after +++ b/idea/testData/intentions/loopToCallChain/mapTo.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" fun foo(list: List, target: MutableList) { list .filter { it.length > 0 } diff --git a/idea/testData/intentions/loopToCallChain/mapTo2.kt b/idea/testData/intentions/loopToCallChain/mapTo2.kt index 3cca030a1f2..24690627026 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo2.kt +++ b/idea/testData/intentions/loopToCallChain/mapTo2.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'mapTo(){}'" fun foo(list: List, target: MutableList) { for (s in list) { val l = s.length diff --git a/idea/testData/intentions/loopToCallChain/mapTo2.kt.after b/idea/testData/intentions/loopToCallChain/mapTo2.kt.after index 9c936cb091f..1192bd5a3f8 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo2.kt.after +++ b/idea/testData/intentions/loopToCallChain/mapTo2.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'mapTo(){}'" fun foo(list: List, target: MutableList) { list.mapTo(target) { it.length } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/mapTo3.kt b/idea/testData/intentions/loopToCallChain/mapTo3.kt index 871617d12d0..82f1fd99ad3 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo3.kt +++ b/idea/testData/intentions/loopToCallChain/mapTo3.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/mapTo3.kt.after b/idea/testData/intentions/loopToCallChain/mapTo3.kt.after index 2d1ac0d20dd..bb1fa37f9cd 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo3.kt.after +++ b/idea/testData/intentions/loopToCallChain/mapTo3.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/mapTo4.kt b/idea/testData/intentions/loopToCallChain/mapTo4.kt index 9267ac1218f..f8dc988896c 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo4.kt +++ b/idea/testData/intentions/loopToCallChain/mapTo4.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" fun foo(list: List): List { val target = createCollection() for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/mapTo4.kt.after b/idea/testData/intentions/loopToCallChain/mapTo4.kt.after index 2eeef470098..50d13a5c8df 100644 --- a/idea/testData/intentions/loopToCallChain/mapTo4.kt.after +++ b/idea/testData/intentions/loopToCallChain/mapTo4.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" fun foo(list: List): List { val target = createCollection() list diff --git a/idea/testData/intentions/loopToCallChain/mapVar.kt b/idea/testData/intentions/loopToCallChain/mapVar.kt index eb80ed93774..21cdabbd835 100644 --- a/idea/testData/intentions/loopToCallChain/mapVar.kt +++ b/idea/testData/intentions/loopToCallChain/mapVar.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.firstOrNull{}'" fun foo(list: List): Int? { for (s in list) { var length = s.length diff --git a/idea/testData/intentions/loopToCallChain/mapVar.kt.after b/idea/testData/intentions/loopToCallChain/mapVar.kt.after index 5311e57e96a..66e475bfdfe 100644 --- a/idea/testData/intentions/loopToCallChain/mapVar.kt.after +++ b/idea/testData/intentions/loopToCallChain/mapVar.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.firstOrNull{}'" fun foo(list: List): Int? { return list .map { it.length } diff --git a/idea/testData/intentions/loopToCallChain/none_ifReturn.kt b/idea/testData/intentions/loopToCallChain/none_ifReturn.kt index b96faa94eb8..f41bee0f240 100644 --- a/idea/testData/intentions/loopToCallChain/none_ifReturn.kt +++ b/idea/testData/intentions/loopToCallChain/none_ifReturn.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'none{}'" fun foo(list: List): Boolean { for (s in list) { if (s.length > 0) { diff --git a/idea/testData/intentions/loopToCallChain/none_ifReturn.kt.after b/idea/testData/intentions/loopToCallChain/none_ifReturn.kt.after index 2113034825a..06100d88495 100644 --- a/idea/testData/intentions/loopToCallChain/none_ifReturn.kt.after +++ b/idea/testData/intentions/loopToCallChain/none_ifReturn.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'none{}'" fun foo(list: List): Boolean { return list.none { it.length > 0 } } \ No newline at end of file diff --git a/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt b/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt index 2545bbb4723..9d934a5b4ef 100644 --- a/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt +++ b/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt.after b/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt.after index 94d73dd0600..c82ea8451c3 100644 --- a/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt.after +++ b/idea/testData/intentions/loopToCallChain/resultCollectionUsedInsideLoop.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'filter{}.mapTo(){}'" import java.util.ArrayList fun foo(list: List): List { diff --git a/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt b/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt index e1362dddb9d..a794cfd1575 100644 --- a/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt +++ b/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'" fun foo(list: List, o: Any): Int? { if (o is Int) { for (s in list) { diff --git a/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt.after b/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt.after index dfa0d74e515..11391fe2604 100644 --- a/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt.after +++ b/idea/testData/intentions/loopToCallChain/smartCastNotBroken.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'" fun foo(list: List, o: Any): Int? { if (o is Int) { return list diff --git a/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt b/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt index 48f6e21a119..6d16b22cb96 100644 --- a/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt +++ b/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'" fun foo(list: List, o: Any): Int? { for (s in list) { val length = s.length + (o as Int) diff --git a/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt.after b/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt.after index 06f65d63017..b60878628e2 100644 --- a/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt.after +++ b/idea/testData/intentions/loopToCallChain/smartCastNotRequired.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'" fun foo(list: List, o: Any): Int? { return list .map { it.length + (o as Int) } diff --git a/idea/testData/intentions/loopToCallChain/toList.kt b/idea/testData/intentions/loopToCallChain/toList.kt index 919a46b47bc..737eb48f9c7 100644 --- a/idea/testData/intentions/loopToCallChain/toList.kt +++ b/idea/testData/intentions/loopToCallChain/toList.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toList()'" import java.util.ArrayList fun foo(map: Map): List { diff --git a/idea/testData/intentions/loopToCallChain/toList.kt.after b/idea/testData/intentions/loopToCallChain/toList.kt.after index 985d603ff6a..0d27a73d4bf 100644 --- a/idea/testData/intentions/loopToCallChain/toList.kt.after +++ b/idea/testData/intentions/loopToCallChain/toList.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toList()'" import java.util.ArrayList fun foo(map: Map): List { diff --git a/idea/testData/intentions/loopToCallChain/toMutableSet.kt b/idea/testData/intentions/loopToCallChain/toMutableSet.kt index 3a1446efa1d..45ed829385e 100644 --- a/idea/testData/intentions/loopToCallChain/toMutableSet.kt +++ b/idea/testData/intentions/loopToCallChain/toMutableSet.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toMutableSet()'" import java.util.HashSet fun foo(map: Map): MutableCollection { diff --git a/idea/testData/intentions/loopToCallChain/toMutableSet.kt.after b/idea/testData/intentions/loopToCallChain/toMutableSet.kt.after index 2b5241c540d..663b95fc513 100644 --- a/idea/testData/intentions/loopToCallChain/toMutableSet.kt.after +++ b/idea/testData/intentions/loopToCallChain/toMutableSet.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toMutableSet()'" import java.util.HashSet fun foo(map: Map): MutableCollection { diff --git a/idea/testData/intentions/loopToCallChain/toSet.kt b/idea/testData/intentions/loopToCallChain/toSet.kt index e7b09bb9dd9..b91a2fede16 100644 --- a/idea/testData/intentions/loopToCallChain/toSet.kt +++ b/idea/testData/intentions/loopToCallChain/toSet.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toSet()'" import java.util.HashSet fun foo(map: Map): Collection { diff --git a/idea/testData/intentions/loopToCallChain/toSet.kt.after b/idea/testData/intentions/loopToCallChain/toSet.kt.after index 990e3818f8c..343e616b851 100644 --- a/idea/testData/intentions/loopToCallChain/toSet.kt.after +++ b/idea/testData/intentions/loopToCallChain/toSet.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'toSet()'" import java.util.HashSet fun foo(map: Map): Collection { diff --git a/idea/testData/intentions/loopToCallChain/toSetWithMap.kt b/idea/testData/intentions/loopToCallChain/toSetWithMap.kt index 13da6a5e383..7aacd903d39 100644 --- a/idea/testData/intentions/loopToCallChain/toSetWithMap.kt +++ b/idea/testData/intentions/loopToCallChain/toSetWithMap.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.toSet()'" import java.util.HashSet fun foo(map: Map): Collection { diff --git a/idea/testData/intentions/loopToCallChain/toSetWithMap.kt.after b/idea/testData/intentions/loopToCallChain/toSetWithMap.kt.after index dd5e26c235b..8f1a22d5dc2 100644 --- a/idea/testData/intentions/loopToCallChain/toSetWithMap.kt.after +++ b/idea/testData/intentions/loopToCallChain/toSetWithMap.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// INTENTION_TEXT: "Replace with 'map{}.toSet()'" import java.util.HashSet fun foo(map: Map): Collection {