mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-10 15:52:06 +00:00
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(
|
||||
element: KtArrayAccessExpression,
|
||||
override val importNames: Collection<Name>,
|
||||
|
||||
@@ -171,6 +171,8 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
|
||||
FUNCTION_EXPECTED.registerFactory(InvokeImportFix)
|
||||
|
||||
ITERATOR_MISSING.registerFactory(IteratorImportFix)
|
||||
|
||||
DELEGATE_SPECIAL_FUNCTION_MISSING.registerFactory(DelegateAccessorsImportFix)
|
||||
COMPONENT_FUNCTION_MISSING.registerFactory(ComponentsImportFix, AddDataModifierFix)
|
||||
|
||||
|
||||
12
idea/testData/quickfix/autoImports/iteratorOperator.after.kt
vendored
Normal file
12
idea/testData/quickfix/autoImports/iteratorOperator.after.kt
vendored
Normal file
@@ -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) {}
|
||||
}
|
||||
7
idea/testData/quickfix/autoImports/iteratorOperator.before.Dependency.kt
vendored
Normal file
7
idea/testData/quickfix/autoImports/iteratorOperator.before.Dependency.kt
vendored
Normal file
@@ -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()
|
||||
11
idea/testData/quickfix/autoImports/iteratorOperator.before.Main.kt
vendored
Normal file
11
idea/testData/quickfix/autoImports/iteratorOperator.before.Main.kt
vendored
Normal file
@@ -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) {}
|
||||
}
|
||||
@@ -790,6 +790,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
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")
|
||||
public void testMemberImportFunction() throws Exception {
|
||||
runTest("idea/testData/quickfix/autoImports/memberImportFunction.test");
|
||||
|
||||
Reference in New Issue
Block a user