Import quick fix: support extension iterator function
#KT-34303 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
3abfe59d75
commit
68ea677cc4
@@ -444,6 +444,16 @@ internal class InvokeImportFix(expression: KtExpression) : OrdinaryImportFixBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class IteratorImportFix(expression: KtExpression) : OrdinaryImportFixBase<KtExpression>(expression, MyFactory) {
|
||||||
|
override val importNames = listOf(OperatorNameConventions.ITERATOR)
|
||||||
|
|
||||||
|
override fun getCallTypeAndReceiver() = element?.let { CallTypeAndReceiver.OPERATOR(it) }
|
||||||
|
|
||||||
|
companion object MyFactory : Factory() {
|
||||||
|
override fun createImportAction(diagnostic: Diagnostic) = (diagnostic.psiElement as? KtExpression)?.let(::IteratorImportFix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal open class ArrayAccessorImportFix(
|
internal open class ArrayAccessorImportFix(
|
||||||
element: KtArrayAccessExpression,
|
element: KtArrayAccessExpression,
|
||||||
override val importNames: Collection<Name>,
|
override val importNames: Collection<Name>,
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
|
|
||||||
FUNCTION_EXPECTED.registerFactory(InvokeImportFix)
|
FUNCTION_EXPECTED.registerFactory(InvokeImportFix)
|
||||||
|
|
||||||
|
ITERATOR_MISSING.registerFactory(IteratorImportFix)
|
||||||
|
|
||||||
DELEGATE_SPECIAL_FUNCTION_MISSING.registerFactory(DelegateAccessorsImportFix)
|
DELEGATE_SPECIAL_FUNCTION_MISSING.registerFactory(DelegateAccessorsImportFix)
|
||||||
COMPONENT_FUNCTION_MISSING.registerFactory(ComponentsImportFix, AddDataModifierFix)
|
COMPONENT_FUNCTION_MISSING.registerFactory(ComponentsImportFix, AddDataModifierFix)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// "Import" "true"
|
||||||
|
// ERROR: For-loop range must have an 'iterator()' method
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
package bar
|
||||||
|
|
||||||
|
import foo.Foo
|
||||||
|
import foo.iterator
|
||||||
|
|
||||||
|
fun foo(start: Foo, end: Foo) {
|
||||||
|
for (date in start<caret>..end) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
class Foo : Comparable<Foo> {
|
||||||
|
override fun compareTo(other: Foo): Int = TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun ClosedRange<Foo>.iterator(): Iterator<Foo> = TODO()
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// "Import" "true"
|
||||||
|
// ERROR: For-loop range must have an 'iterator()' method
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
package bar
|
||||||
|
|
||||||
|
import foo.Foo
|
||||||
|
|
||||||
|
fun foo(start: Foo, end: Foo) {
|
||||||
|
for (date in start<caret>..end) {}
|
||||||
|
}
|
||||||
+5
@@ -790,6 +790,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
runTest("idea/testData/quickfix/autoImports/invokeExtensionNoOperator.test");
|
runTest("idea/testData/quickfix/autoImports/invokeExtensionNoOperator.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("iteratorOperator.before.Main.kt")
|
||||||
|
public void testIteratorOperator() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/autoImports/iteratorOperator.before.Main.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("memberImportFunction.test")
|
@TestMetadata("memberImportFunction.test")
|
||||||
public void testMemberImportFunction() throws Exception {
|
public void testMemberImportFunction() throws Exception {
|
||||||
runTest("idea/testData/quickfix/autoImports/memberImportFunction.test");
|
runTest("idea/testData/quickfix/autoImports/memberImportFunction.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user