KT-5629 Quickfix to import extension method when arguments of non-extension method do not match
#KT-5629 fixed
This commit is contained in:
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolveScope
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.codeInsight.referenceExpression
|
||||
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
||||
import org.jetbrains.kotlin.idea.core.isVisible
|
||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||
@@ -483,7 +484,8 @@ internal class ImportForMismatchingArgumentsFix(
|
||||
return callExpression.valueArguments +
|
||||
callExpression.valueArguments.mapNotNull { it.getArgumentExpression() } +
|
||||
callExpression.valueArguments.mapNotNull { it.getArgumentName()?.referenceExpression } +
|
||||
callExpression.valueArgumentList.singletonOrEmptyList()
|
||||
callExpression.valueArgumentList.singletonOrEmptyList() +
|
||||
callExpression.referenceExpression().singletonOrEmptyList()
|
||||
}
|
||||
|
||||
override fun fillCandidates(
|
||||
|
||||
@@ -147,6 +147,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
TYPE_MISMATCH.registerFactory(ImportForMismatchingArgumentsFix)
|
||||
CONSTANT_EXPECTED_TYPE_MISMATCH.registerFactory(ImportForMismatchingArgumentsFix)
|
||||
NAMED_PARAMETER_NOT_FOUND.registerFactory(ImportForMismatchingArgumentsFix)
|
||||
NONE_APPLICABLE.registerFactory(ImportForMismatchingArgumentsFix)
|
||||
|
||||
UNRESOLVED_REFERENCE.registerFactory(AddTestLibQuickFix)
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Import" "true"
|
||||
// ERROR: None of the following functions can be called with the arguments supplied: <br>public final fun buz(i: Int, l: Int): Unit defined in lib.Bar<br>public final fun buz(i: Int, m: M): Unit defined in lib.Bar
|
||||
import lib.Bar
|
||||
import lib.buz
|
||||
|
||||
fun useSite() {
|
||||
|
||||
val bar = Bar()
|
||||
bar.buz<caret>("1", "2")
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
package lib
|
||||
|
||||
class M
|
||||
|
||||
class Bar {
|
||||
fun buz(i: Int, m: M) {
|
||||
|
||||
}
|
||||
|
||||
fun buz(i: Int, l: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Bar.buz(s: String, i: String) {
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Import" "true"
|
||||
// ERROR: None of the following functions can be called with the arguments supplied: <br>public final fun buz(i: Int, l: Int): Unit defined in lib.Bar<br>public final fun buz(i: Int, m: M): Unit defined in lib.Bar
|
||||
import lib.Bar
|
||||
|
||||
fun useSite() {
|
||||
|
||||
val bar = Bar()
|
||||
bar.buz<caret>("1", "2")
|
||||
}
|
||||
@@ -510,6 +510,12 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noneApplicableFromInstanceButExtension.before.Main.kt")
|
||||
public void testNoneApplicableFromInstanceButExtension() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/noneApplicableFromInstanceButExtension.before.Main.kt");
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notExcludedClass.before.Main.kt")
|
||||
public void testNotExcludedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notExcludedClass.before.Main.kt");
|
||||
|
||||
Reference in New Issue
Block a user