More informative intention action text

This commit is contained in:
Valentin Kipyatkov
2016-04-20 14:52:00 +03:00
parent bbb6ef4fbc
commit fe7ddbcc0d
135 changed files with 273 additions and 30 deletions
@@ -33,7 +33,23 @@ class LoopToCallChainIntention : SelfTargetingRangeIntention<KtForExpression>(
"Replace with stdlib operations" "Replace with stdlib operations"
) { ) {
override fun applicabilityRange(element: KtForExpression): TextRange? { 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?) { override fun applyTo(element: KtForExpression, editor: Editor?) {
@@ -40,6 +40,15 @@ interface Transformation {
val inputVariable: KtCallableDeclaration val inputVariable: KtCallableDeclaration
val loop: KtForExpression 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 fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression
} }
@@ -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 { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return KtPsiFactory(loop).createExpressionByPattern("$0 += $1", targetCollection, chainedCallGenerator.receiver) return KtPsiFactory(loop).createExpressionByPattern("$0 += $1", targetCollection, chainedCallGenerator.receiver)
} }
@@ -170,6 +180,9 @@ class FilterToTransformation private constructor(
private val filter: KtExpression private val filter: KtExpression
) : ReplaceLoopResultTransformation(loop, inputVariable) { ) : ReplaceLoopResultTransformation(loop, inputVariable) {
override val presentation: String
get() = "filterTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, filter) val lambda = generateLambda(inputVariable, filter)
return chainedCallGenerator.generate("filterTo($0) $1:'{}'", targetCollection, lambda) return chainedCallGenerator.generate("filterTo($0) $1:'{}'", targetCollection, lambda)
@@ -200,6 +213,9 @@ class AssignFilterToTransformation(
private val filter: KtExpression private val filter: KtExpression
) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) {
override val presentation: String
get() = "filterTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, filter) val lambda = generateLambda(inputVariable, filter)
return chainedCallGenerator.generate("filterTo($0) $1:'{}'", initialization.initializer, lambda) return chainedCallGenerator.generate("filterTo($0) $1:'{}'", initialization.initializer, lambda)
@@ -213,6 +229,9 @@ class MapToTransformation private constructor(
private val mapping: KtExpression private val mapping: KtExpression
) : ReplaceLoopResultTransformation(loop, inputVariable) { ) : ReplaceLoopResultTransformation(loop, inputVariable) {
override val presentation: String
get() = "mapTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, mapping) val lambda = generateLambda(inputVariable, mapping)
return chainedCallGenerator.generate("mapTo($0) $1:'{}'", targetCollection, lambda) return chainedCallGenerator.generate("mapTo($0) $1:'{}'", targetCollection, lambda)
@@ -243,6 +262,9 @@ class AssignMapToTransformation(
private val mapping: KtExpression private val mapping: KtExpression
) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) {
override val presentation: String
get() = "mapTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, mapping) val lambda = generateLambda(inputVariable, mapping)
return chainedCallGenerator.generate("mapTo($0) $1:'{}'", initialization.initializer, lambda) return chainedCallGenerator.generate("mapTo($0) $1:'{}'", initialization.initializer, lambda)
@@ -256,6 +278,9 @@ class FlatMapToTransformation private constructor(
private val transform: KtExpression private val transform: KtExpression
) : ReplaceLoopResultTransformation(loop, inputVariable) { ) : ReplaceLoopResultTransformation(loop, inputVariable) {
override val presentation: String
get() = "flatMapTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, transform) val lambda = generateLambda(inputVariable, transform)
return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", targetCollection, lambda) return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", targetCollection, lambda)
@@ -286,6 +311,9 @@ class AssignFlatMapToTransformation(
private val transform: KtExpression private val transform: KtExpression
) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, targetCollectionInitialization) {
override val presentation: String
get() = "flatMapTo(){}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, transform) val lambda = generateLambda(inputVariable, transform)
return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", initialization.initializer, lambda) return chainedCallGenerator.generate("flatMapTo($0) $1:'{}'", initialization.initializer, lambda)
@@ -298,6 +326,9 @@ class AssignToListTransformation(
initialization: VariableInitialization initialization: VariableInitialization
) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) {
override val presentation: String
get() = "toList()"
override fun mergeWithPrevious(previousTransformation: SequenceTransformation): ResultTransformation? { override fun mergeWithPrevious(previousTransformation: SequenceTransformation): ResultTransformation? {
if (previousTransformation !is FilterTransformation) return null if (previousTransformation !is FilterTransformation) return null
return AssignSequenceTransformationResultTransformation(previousTransformation, initialization) return AssignSequenceTransformationResultTransformation(previousTransformation, initialization)
@@ -314,6 +345,9 @@ class AssignToMutableListTransformation(
initialization: VariableInitialization initialization: VariableInitialization
) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) {
override val presentation: String
get() = "toMutableList()"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return chainedCallGenerator.generate("toMutableList()") return chainedCallGenerator.generate("toMutableList()")
} }
@@ -325,6 +359,9 @@ class AssignToSetTransformation(
initialization: VariableInitialization initialization: VariableInitialization
) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) {
override val presentation: String
get() = "toSet()"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return chainedCallGenerator.generate("toSet()") return chainedCallGenerator.generate("toSet()")
} }
@@ -336,6 +373,9 @@ class AssignToMutableSetTransformation(
initialization: VariableInitialization initialization: VariableInitialization
) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) {
override val presentation: String
get() = "toMutableSet()"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return chainedCallGenerator.generate("toMutableSet()") return chainedCallGenerator.generate("toMutableSet()")
} }
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class FindAndAssignTransformation( class FindAndAssignTransformation(
loop: KtForExpression, loop: KtForExpression,
inputVariable: KtCallableDeclaration, inputVariable: KtCallableDeclaration,
private val generator: (chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression, private val generator: FindOperatorGenerator,
initialization: VariableInitialization, initialization: VariableInitialization,
private val filter: KtExpression? = null private val filter: KtExpression? = null
) : AssignToVariableResultTransformation(loop, inputVariable, initialization) { ) : AssignToVariableResultTransformation(loop, inputVariable, initialization) {
@@ -40,8 +40,11 @@ class FindAndAssignTransformation(
return FindAndAssignTransformation(loop, previousTransformation.inputVariable, generator, initialization, previousTransformation.effectiveCondition()) 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 { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return generator(chainedCallGenerator, filter) return generator.generate(chainedCallGenerator, filter)
} }
/** /**
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
class FindAndReturnTransformation( class FindAndReturnTransformation(
override val loop: KtForExpression, override val loop: KtForExpression,
override val inputVariable: KtCallableDeclaration, override val inputVariable: KtCallableDeclaration,
private val generator: (chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression, private val generator: FindOperatorGenerator,
private val endReturn: KtReturnExpression, private val endReturn: KtReturnExpression,
private val filter: KtExpression? = null private val filter: KtExpression? = null
) : ResultTransformation { ) : ResultTransformation {
@@ -44,8 +44,11 @@ class FindAndReturnTransformation(
override fun commentRestoringRange(convertLoopResult: KtExpression) = commentRestoringRange override fun commentRestoringRange(convertLoopResult: KtExpression) = commentRestoringRange
override val presentation: String
get() = generator.functionName + (if (filter != null) "{}" else "()")
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return generator(chainedCallGenerator, filter) return generator.generate(chainedCallGenerator, filter)
} }
override fun convertLoop(resultCallChain: KtExpression): KtExpression { override fun convertLoop(resultCallChain: KtExpression): KtExpression {
@@ -43,6 +43,9 @@ class FilterTransformation(
override val affectsIndex: Boolean override val affectsIndex: Boolean
get() = true get() = true
override val presentation: String
get() = if (isInverse) "filterNot{}" else "filter{}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, condition) val lambda = generateLambda(inputVariable, condition)
val name = if (isInverse) "filterNot" else "filter" val name = if (isInverse) "filterNot" else "filter"
@@ -128,6 +131,9 @@ class FilterIsInstanceTransformation(
override val affectsIndex: Boolean override val affectsIndex: Boolean
get() = true get() = true
override val presentation: String
get() = "filterIsInstance<>()"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return chainedCallGenerator.generate("filterIsInstance<$0>()", type) return chainedCallGenerator.generate("filterIsInstance<$0>()", type)
} }
@@ -141,6 +147,9 @@ class FilterNotNullTransformation(
override val affectsIndex: Boolean override val affectsIndex: Boolean
get() = true get() = true
override val presentation: String
get() = "filterNotNull()"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return chainedCallGenerator.generate("filterNotNull()") return chainedCallGenerator.generate("filterNotNull()")
} }
@@ -34,6 +34,9 @@ class FlatMapTransformation(
override val affectsIndex: Boolean override val affectsIndex: Boolean
get() = true get() = true
override val presentation: String
get() = "flatMap{}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, transform) val lambda = generateLambda(inputVariable, transform)
return chainedCallGenerator.generate("flatMap$0:'{}'", lambda) return chainedCallGenerator.generate("flatMap$0:'{}'", lambda)
@@ -31,6 +31,9 @@ class MapTransformation(
override val affectsIndex: Boolean override val affectsIndex: Boolean
get() = false get() = false
override val presentation: String
get() = "map{}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = generateLambda(inputVariable, mapping) val lambda = generateLambda(inputVariable, mapping)
return chainedCallGenerator.generate("map$0:'{}'", lambda) return chainedCallGenerator.generate("map$0:'{}'", lambda)
@@ -112,12 +112,17 @@ fun KtProperty.hasWriteUsages(): Boolean {
} }
} }
interface FindOperatorGenerator {
val functionName: String
fun generate(chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?): KtExpression
}
fun buildFindOperationGenerator( fun buildFindOperationGenerator(
valueIfFound: KtExpression, valueIfFound: KtExpression,
valueIfNotFound: KtExpression, valueIfNotFound: KtExpression,
inputVariable: KtCallableDeclaration, inputVariable: KtCallableDeclaration,
findFirst: Boolean findFirst: Boolean
): ((chainedCallGenerator: ChainedCallGenerator, filter: KtExpression?) -> KtExpression)? { ): FindOperatorGenerator? {
assert(valueIfFound.isPhysical) assert(valueIfFound.isPhysical)
assert(valueIfNotFound.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 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 if (valueIfNotFound.isNullExpression()) return this
// we cannot use ?: if found value can be null // we cannot use ?: if found value can be null
if (inputVariableCanHoldNull) return null if (inputVariableCanHoldNull) return null
return { chainedCallGenerator, filter -> return object: FindOperatorGenerator {
val generated = this(chainedCallGenerator, filter) override val functionName: String
KtPsiFactory(generated).createExpressionByPattern("$0 ?: $1", generated, valueIfNotFound) 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 { when {
valueIfFound.isVariableReference(inputVariable) -> { valueIfFound.isVariableReference(inputVariable) -> {
val stdlibFunName = if (findFirst) "firstOrNull" else "lastOrNull" val generator = SimpleGenerator(if (findFirst) "firstOrNull" else "lastOrNull")
val generator = { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? ->
generateChainedCall(stdlibFunName, chainedCallGenerator, filter)
}
return generator.useElvisOperatorIfNeeded() return generator.useElvisOperatorIfNeeded()
} }
valueIfFound.isTrueConstant() && valueIfNotFound.isFalseConstant() -> { valueIfFound.isTrueConstant() && valueIfNotFound.isFalseConstant() -> return SimpleGenerator("any")
return { chainedCallGenerator, filter -> generateChainedCall("any", chainedCallGenerator, filter) }
}
valueIfFound.isFalseConstant() && valueIfNotFound.isTrueConstant() -> { valueIfFound.isFalseConstant() && valueIfNotFound.isTrueConstant() -> return SimpleGenerator("none")
return { chainedCallGenerator, filter -> generateChainedCall("none", chainedCallGenerator, filter) }
}
inputVariable.hasUsages(valueIfFound) -> { inputVariable.hasUsages(valueIfFound) -> {
if (!findFirst) return null // too dangerous because of side effects if (!findFirst) return null // too dangerous because of side effects
@@ -171,9 +180,14 @@ fun buildFindOperationGenerator(
val receiver = qualifiedExpression.receiverExpression val receiver = qualifiedExpression.receiverExpression
val selector = qualifiedExpression.selectorExpression val selector = qualifiedExpression.selectorExpression
if (receiver.isVariableReference(inputVariable) && selector != null && !inputVariable.hasUsages(selector)) { if (receiver.isVariableReference(inputVariable) && selector != null && !inputVariable.hasUsages(selector)) {
return { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? -> return object: FindOperatorGenerator {
val findFirstCall = generateChainedCall("firstOrNull", chainedCallGenerator, filter) override val functionName: String
KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.$1", findFirstCall, selector) 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() }.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 // 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 if (inputVariableCanHoldNull) return null
return { chainedCallGenerator: ChainedCallGenerator, filter: KtExpression? -> return object: FindOperatorGenerator {
val findFirstCall = generateChainedCall("firstOrNull", chainedCallGenerator, filter) override val functionName: String
val letBody = generateLambda(inputVariable, valueIfFound) get() = "firstOrNull" //TODO
KtPsiFactory(findFirstCall).createExpressionByPattern("$0?.let $1:'{}'", findFirstCall, letBody)
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() }.useElvisOperatorIfNeeded()
} }
else -> { else -> {
return { chainedCallGenerator, filter -> return object: FindOperatorGenerator {
val chainedCall = generateChainedCall("any", chainedCallGenerator, filter) override val functionName: String
KtPsiFactory(chainedCall).createExpressionByPattern("if ($0) $1 else $2", chainedCall, valueIfFound, valueIfNotFound) 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 initialization: VariableInitialization
) : AssignToVariableResultTransformation(sequenceTransformation.loop, sequenceTransformation.inputVariable, initialization) { ) : 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 { override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
return sequenceTransformation.generateCode(chainedCallGenerator) return sequenceTransformation.generateCode(chainedCallGenerator)
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+='"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
<caret>for (s in list) { <caret>for (s in list) {
target.add(s) target.add(s)
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+='"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
<caret>target += list <caret>target += list
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var found = false var found = false
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val found = list.any { it.length > 0 } <caret>val found = list.any { it.length > 0 }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var found = false var found = false
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val found = list.any { it.length > 0 } <caret>val found = list.any { it.length > 0 }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result = 0 var result = 0
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result = if (list.any { it.length > 0 }) 1 else 0 <caret>val result = if (list.any { it.length > 0 }) 1 else 0
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>): Boolean { fun foo(list: List<String>): Boolean {
<caret>for (s in list) { <caret>for (s in list) {
if (s.length > 0) { if (s.length > 0) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>): Boolean { fun foo(list: List<String>): Boolean {
<caret>return list.any { it.length > 0 } <caret>return list.any { it.length > 0 }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>): Int { fun foo(list: List<String>): Int {
<caret>for (s in list) { <caret>for (s in list) {
if (s.length > 0) { if (s.length > 0) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any{}'"
fun foo(list: List<String>): Int { fun foo(list: List<String>): Int {
<caret>return if (list.any { it.length > 0 }) -1 else takeInt() <caret>return if (list.any { it.length > 0 }) -1 else takeInt()
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any()'"
fun foo(list: List<String>): Boolean { fun foo(list: List<String>): Boolean {
<caret>for (s in list) { <caret>for (s in list) {
return true return true
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'any()'"
fun foo(list: List<String>): Boolean { fun foo(list: List<String>): Boolean {
<caret>return list.any() <caret>return list.any()
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>, p: Int): List<String> { fun foo(list: List<String>, p: Int): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>, p: Int): List<String> { fun foo(list: List<String>, p: Int): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): ArrayList<String> { fun foo(list: List<String>): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): ArrayList<String> { fun foo(list: List<String>): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>, p: Int): ArrayList<String> { fun foo(list: List<String>, p: Int): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>, p: Int): ArrayList<String> { fun foo(list: List<String>, p: Int): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.* import java.util.*
fun foo(list: List<String>): ArrayList<String> { fun foo(list: List<String>): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
import java.util.* import java.util.*
fun foo(list: List<String>): ArrayList<String> { fun foo(list: List<String>): ArrayList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.toMutableList()'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): MutableList<String> { fun foo(list: List<String>): MutableList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.toMutableList()'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): MutableList<String> { fun foo(list: List<String>): MutableList<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(): List<String> { fun foo(): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(): List<String> { fun foo(): List<String> {
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<Int> { fun foo(list: List<String>): List<Int> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<Int> { fun foo(list: List<String>): List<Int> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'"
fun foo(list: List<Any>): Int? { fun foo(list: List<Any>): Int? {
<caret>for (o in list) { <caret>for (o in list) {
if (o is String) { if (o is String) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'"
fun foo(list: List<Any>): Int? { fun foo(list: List<Any>): Int? {
return list return list
.filterIsInstance<String>() .filterIsInstance<String>()
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'"
fun foo(list: List<Any>): Int? { fun foo(list: List<Any>): Int? {
<caret>for (o in list) { <caret>for (o in list) {
if (o !is String) continue if (o !is String) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIsInstance<>().map{}.firstOrNull()'"
fun foo(list: List<Any>): Int? { fun foo(list: List<Any>): Int? {
return list return list
.filterIsInstance<String>() .filterIsInstance<String>()
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'"
fun foo(list: List<String?>): Int? { fun foo(list: List<String?>): Int? {
<caret>for (s in list) { <caret>for (s in list) {
if (s != null) { if (s != null) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'"
fun foo(list: List<String?>): Int? { fun foo(list: List<String?>): Int? {
<caret>return list <caret>return list
.filterNotNull() .filterNotNull()
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'"
fun foo(list: List<Any?>): Int? { fun foo(list: List<Any?>): Int? {
<caret>for (o in list) { <caret>for (o in list) {
if (o == null) continue if (o == null) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNotNull().map{}.firstOrNull()'"
fun foo(list: List<Any?>): Int? { fun foo(list: List<Any?>): Int? {
<caret>return list <caret>return list
.filterNotNull() .filterNotNull()
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNot{}.map{}.firstOrNull()'"
fun foo(list: List<String>): Int? { fun foo(list: List<String>): Int? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isEmpty()) continue if (s.isEmpty()) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterNot{}.map{}.firstOrNull()'"
fun foo(list: List<String>): Int? { fun foo(list: List<String>): Int? {
<caret>return list <caret>return list
.filterNot { it.isEmpty() } .filterNot { it.isEmpty() }
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
<caret>for (s in list) { <caret>for (s in list) {
if (s.length > 0) if (s.length > 0)
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
list.filterTo(target) { it.length > 0 } list.filterTo(target) { it.length > 0 }
} }
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
val target = createCollection() val target = createCollection()
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterTo(){}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
val target = createCollection() val target = createCollection()
<caret>list.filterTo(target) { it.length > 0 } <caret>list.filterTo(target) { it.length > 0 }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isEmpty()) continue if (s.isEmpty()) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull { !it.isEmpty() } <caret>return list.firstOrNull { !it.isEmpty() }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (!s.isEmpty()) continue if (!s.isEmpty()) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull { it.isEmpty() } <caret>return list.firstOrNull { it.isEmpty() }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isEmpty()) { if (s.isEmpty()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull { !it.isEmpty() } <caret>return list.firstOrNull { !it.isEmpty() }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}.firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isEmpty()) continue if (s.isEmpty()) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.map{}.firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
return list return list
.filter { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" } .filter { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = "" var result: String? = ""
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = "" var result: String? = ""
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result: String? = list.firstOrNull { it.length > 0 } <caret>val result: String? = list.firstOrNull { it.length > 0 }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>var result: String? = list.firstOrNull { it.length > 0 } <caret>var result: String? = list.firstOrNull { it.length > 0 }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { // search for first non-empty string in the list <caret>for (s in list) { // search for first non-empty string in the list
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result: String? = list.firstOrNull { // search for first non-empty string in the list <caret>val result: String? = list.firstOrNull { // search for first non-empty string in the list
it.length > 0 it.length > 0
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.length > 0) { if (s.length > 0) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull { it.length > 0 } <caret>return list.firstOrNull { it.length > 0 }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result: String? = list.firstOrNull { it.length > 0 }?.let { bar(it) } <caret>val result: String? = list.firstOrNull { it.length > 0 }?.let { bar(it) }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result: String? = list.firstOrNull { it.length > 0 }?.let { it.substring(0, it.length - 1) } <caret>val result: String? = list.firstOrNull { it.length > 0 }?.let { it.substring(0, it.length - 1) }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
var result = "" var result = ""
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>) { fun foo(list: List<String>) {
<caret>val result = list.firstOrNull { it.length > 0 }?.let { bar(it) } ?: "" <caret>val result = list.firstOrNull { it.length > 0 }?.let { bar(it) } ?: ""
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
return s return s
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull() <caret>return list.firstOrNull()
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): Int? { fun foo(list: List<String>): Int? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isNotEmpty()) { if (s.isNotEmpty()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): Int? { fun foo(list: List<String>): Int? {
<caret>return list.firstOrNull { it.isNotEmpty() }?.length <caret>return list.firstOrNull { it.isNotEmpty() }?.length
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): Int { fun foo(list: List<String>): Int {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isNotEmpty()) { if (s.isNotEmpty()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): Int { fun foo(list: List<String>): Int {
<caret>return list.firstOrNull { it.isNotEmpty() }?.length ?: -1 <caret>return list.firstOrNull { it.isNotEmpty() }?.length ?: -1
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String { fun foo(list: List<String>): String {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isNotEmpty()) { if (s.isNotEmpty()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String { fun foo(list: List<String>): String {
<caret>return list.firstOrNull { it.isNotEmpty() } ?: "" <caret>return list.firstOrNull { it.isNotEmpty() } ?: ""
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
return s return s
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull()'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
// return null if not found // return null if not found
return list.firstOrNull() return list.firstOrNull()
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String?>) { fun foo(list: List<String?>) {
var result: String? = null var result: String? = null
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String?>) { fun foo(list: List<String?>) {
<caret>val result: String? = list.firstOrNull { it != "" }?.substring(1) <caret>val result: String? = list.firstOrNull { it != "" }?.substring(1)
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
if (s.isEmpty()) continue if (s.isEmpty()) continue
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list.firstOrNull { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" } <caret>return list.firstOrNull { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" }
} }
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>for (s in list) { <caret>for (s in list) {
for (line in s.lines()) { for (line in s.lines()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
<caret>return list <caret>return list
.flatMap { it.lines() } .flatMap { it.lines() }
+1
View File
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
<caret>for (s in list) { <caret>for (s in list) {
for (line in s.lines()) { for (line in s.lines()) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) { fun foo(list: List<String>, target: MutableList<String>) {
<caret>list.flatMapTo(target) { it.lines() } <caret>list.flatMapTo(target) { it.lines() }
} }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
import java.util.ArrayList import java.util.ArrayList
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
val target = createCollection() val target = createCollection()
<caret>for (s in list) { <caret>for (s in list) {
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMapTo(){}'"
fun foo(list: List<String>): List<String> { fun foo(list: List<String>): List<String> {
val target = createCollection() val target = createCollection()
<caret>list.flatMapTo(target) { it.lines() } <caret>list.flatMapTo(target) { it.lines() }
@@ -1,4 +1,5 @@
// WITH_RUNTIME // WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'flatMap{}.firstOrNull{}'"
fun foo(list: List<String>): String? { fun foo(list: List<String>): String? {
var result: String? = null var result: String? = null
MainLoop@ MainLoop@

Some files were not shown because too many files have changed in this diff Show More