Fix incorrect replacement with 'any' instead of 'all'
#KT-17730 Fixed
This commit is contained in:
+8
-11
@@ -189,6 +189,11 @@ object FindTransformationMatcher : TransformationMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
private class NegatingFindOpetationGenerator(val generator: FindOperationGenerator) : FindOperationGenerator(generator) {
|
||||
override fun generate(chainedCallGenerator: ChainedCallGenerator): KtExpression =
|
||||
generator.generate(chainedCallGenerator).negate()
|
||||
}
|
||||
|
||||
private fun generateChainedCall(
|
||||
stdlibFunName: String,
|
||||
chainedCallGenerator: ChainedCallGenerator,
|
||||
@@ -347,19 +352,11 @@ object FindTransformationMatcher : TransformationMatcher {
|
||||
val containsArgument = filterExpression.isFilterForContainsOperation(inputVariable, loop)
|
||||
if (containsArgument != null) {
|
||||
val generator = SimpleGenerator("contains", inputVariable, null, containsArgument)
|
||||
return if (negated) {
|
||||
object : FindOperationGenerator(generator) {
|
||||
override fun generate(chainedCallGenerator: ChainedCallGenerator): KtExpression =
|
||||
generator.generate(chainedCallGenerator).negate()
|
||||
}
|
||||
}
|
||||
else {
|
||||
generator
|
||||
}
|
||||
return if (negated) NegatingFindOpetationGenerator(generator) else generator
|
||||
}
|
||||
|
||||
if (filterExpression is KtPrefixExpression && filterExpression.operationToken == KtTokens.EXCL) {
|
||||
return SimpleGenerator(if (negated) "any" else "none", inputVariable, filter.asNegatedExpression(reformat))
|
||||
if (filterExpression is KtPrefixExpression && filterExpression.operationToken == KtTokens.EXCL && negated) {
|
||||
return SimpleGenerator("all", inputVariable, filter.asNegatedExpression(reformat))
|
||||
}
|
||||
|
||||
return SimpleGenerator(if (negated) "none" else "any", inputVariable, filterExpression)
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val foo = listOf(true, true)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val foo = listOf(true, true)
|
||||
return foo.any { it }
|
||||
return foo.all { it }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val foo = listOf(true, true)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val foo = listOf(true, true)
|
||||
return foo.any { f1(it) && f2(it) }
|
||||
return foo.all { f1(it) && f2(it) }
|
||||
}
|
||||
|
||||
fun f1(b: Boolean): Boolean = TODO()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val list = listOf(1, 2, 3, 4, 5)
|
||||
<caret>for (e in list) {
|
||||
if (!(e <= 3)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'all{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val list = listOf(1, 2, 3, 4, 5)
|
||||
return list.all { it <= 3 }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val list = listOf(1, 2, 3, 4, 5)
|
||||
<caret>for (e in list) {
|
||||
if (!(e <= 3)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'any{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun foo(): Boolean {
|
||||
val list = listOf(1, 2, 3, 4, 5)
|
||||
return list.any { !(it <= 3) }
|
||||
}
|
||||
@@ -194,6 +194,18 @@ public class IntentionTest2Generated extends AbstractIntentionTest2 {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17730.kt")
|
||||
public void testKt17730() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/kt17730.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17730_1.kt")
|
||||
public void testKt17730_1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/kt17730_1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("none.kt")
|
||||
public void testNone() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/none.kt");
|
||||
|
||||
@@ -10105,6 +10105,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17730.kt")
|
||||
public void testKt17730() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/kt17730.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17730_1.kt")
|
||||
public void testKt17730_1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/kt17730_1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("none.kt")
|
||||
public void testNone() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/any/none.kt");
|
||||
|
||||
Reference in New Issue
Block a user