Iterate Intention: Filter out functions without 'operator' modifier
This commit is contained in:
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||||
import org.jetbrains.kotlin.types.expressions.ForLoopConventionsChecker
|
import org.jetbrains.kotlin.types.expressions.ForLoopConventionsChecker
|
||||||
|
import org.jetbrains.kotlin.util.isValidOperator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class IterableTypesDetection(
|
public class IterableTypesDetection(
|
||||||
@@ -49,8 +50,8 @@ public class IterableTypesDetection(
|
|||||||
|
|
||||||
private val typesWithExtensionIterator: Collection<KotlinType> = scope
|
private val typesWithExtensionIterator: Collection<KotlinType> = scope
|
||||||
.collectFunctions(iteratorName, NoLookupLocation.FROM_IDE)
|
.collectFunctions(iteratorName, NoLookupLocation.FROM_IDE)
|
||||||
.mapNotNull { it.extensionReceiverParameter }
|
.filter { it.isValidOperator() }
|
||||||
.map { it.type }
|
.mapNotNull { it.extensionReceiverParameter?.type }
|
||||||
|
|
||||||
override fun isIterable(type: FuzzyType, loopVarType: KotlinType?): Boolean {
|
override fun isIterable(type: FuzzyType, loopVarType: KotlinType?): Boolean {
|
||||||
val elementType = elementType(type) ?: return false
|
val elementType = elementType(type) ?: return false
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// IS_APPLICABLE: false
|
||||||
|
class T<U> {
|
||||||
|
fun <U> T<U>.iterator(): Iterator<U> = listOf<U>().iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
T<Int>()<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// IS_APPLICABLE: false
|
||||||
|
class T<U>
|
||||||
|
|
||||||
|
fun <U> T<U>.iterator(): Iterator<U> = listOf<U>().iterator()
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
T<Int>()<caret>
|
||||||
|
}
|
||||||
@@ -5859,6 +5859,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonOperatorIterator.kt")
|
||||||
|
public void testNonOperatorIterator() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterateExpression/nonOperatorIterator.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonOperatotExtensionIterator.kt")
|
||||||
|
public void testNonOperatotExtensionIterator() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterateExpression/nonOperatotExtensionIterator.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterateExpression/simple.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/iterateExpression/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user