Don't suggest mapTo() transformation over range literals
#KT-18816 Fixed
This commit is contained in:
+10
-3
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.intentions.loopToCallChain.*
|
||||
import org.jetbrains.kotlin.idea.intentions.loopToCallChain.sequence.*
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getCallNameExpression
|
||||
@@ -112,9 +113,13 @@ class AddToCollectionTransformation(
|
||||
TransformationMatch.Result(AddToCollectionTransformation(state.outerLoop, targetCollection))
|
||||
}
|
||||
else {
|
||||
//TODO: recognize "?: continue" in the argument
|
||||
TransformationMatch.Result(MapToTransformation.create(
|
||||
state.outerLoop, state.inputVariable, state.indexVariable, targetCollection, argumentValue, mapNotNull = false))
|
||||
if (state.outerLoop.loopRange.isRangeLiteral())
|
||||
null
|
||||
else {
|
||||
//TODO: recognize "?: continue" in the argument
|
||||
TransformationMatch.Result(MapToTransformation.create(
|
||||
state.outerLoop, state.inputVariable, state.indexVariable, targetCollection, argumentValue, mapNotNull = false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +202,8 @@ class AddToCollectionTransformation(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtExpression?.isRangeLiteral() = this is KtBinaryExpression && operationToken == KtTokens.RANGE
|
||||
|
||||
class FilterToTransformation private constructor(
|
||||
loop: KtForExpression,
|
||||
private val inputVariable: KtCallableDeclaration,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
// IS_APPLICABLE_2: false
|
||||
fun test() {
|
||||
val a = ArrayList<Int>()
|
||||
<caret>for (i in 1..100) {
|
||||
a.add(i + 1)
|
||||
}
|
||||
println(a)
|
||||
}
|
||||
@@ -1013,6 +1013,12 @@ public class IntentionTest2Generated extends AbstractIntentionTest2 {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT18816.kt")
|
||||
public void testKT18816() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/map/KT18816.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("map.kt")
|
||||
public void testMap() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/map/map.kt");
|
||||
|
||||
@@ -10924,6 +10924,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT18816.kt")
|
||||
public void testKT18816() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/map/KT18816.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("map.kt")
|
||||
public void testMap() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/loopToCallChain/map/map.kt");
|
||||
|
||||
Reference in New Issue
Block a user