Import quick fix: suggest for operator extension function called from name reference
#KT-28049 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
998adfb098
commit
79199260b9
@@ -50,12 +50,10 @@ import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
|||||||
import org.jetbrains.kotlin.idea.core.isVisible
|
import org.jetbrains.kotlin.idea.core.isVisible
|
||||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
import org.jetbrains.kotlin.idea.util.*
|
||||||
import org.jetbrains.kotlin.idea.util.ReceiverType
|
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
|
||||||
import org.jetbrains.kotlin.idea.util.receiverTypesWithIndex
|
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -261,6 +259,12 @@ internal abstract class OrdinaryImportFixBase<T : KtExpression>(expression: T, f
|
|||||||
|
|
||||||
indicesHelper.getTopLevelCallablesByName(name).filterTo(result, filterByCallType)
|
indicesHelper.getTopLevelCallablesByName(name).filterTo(result, filterByCallType)
|
||||||
}
|
}
|
||||||
|
if (callTypeAndReceiver.callType == CallType.OPERATOR) {
|
||||||
|
val type = expression.getCallableDescriptor()?.returnType
|
||||||
|
if (type != null) {
|
||||||
|
result.addAll(indicesHelper.getCallableTopLevelExtensions(callTypeAndReceiver, listOf(type), { it == name }))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.addAll(indicesHelper.getCallableTopLevelExtensions(callTypeAndReceiver, expression, bindingContext) { it == name })
|
result.addAll(indicesHelper.getCallableTopLevelExtensions(callTypeAndReceiver, expression, bindingContext) { it == name })
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// FILE: first.before.kt
|
||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Expression 'a' of type 'A' cannot be invoked as a function. The function 'invoke()' is not found
|
||||||
|
|
||||||
|
package b
|
||||||
|
|
||||||
|
import a.A
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val a = A()
|
||||||
|
<caret>a()
|
||||||
|
}
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: second.kt
|
||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Expression 'a' of type 'A' cannot be invoked as a function. The function 'invoke()' is not found
|
||||||
|
|
||||||
|
package a
|
||||||
|
|
||||||
|
class A
|
||||||
|
operator fun A.invoke() = 42
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: first.after.kt
|
||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Expression 'a' of type 'A' cannot be invoked as a function. The function 'invoke()' is not found
|
||||||
|
|
||||||
|
package b
|
||||||
|
|
||||||
|
import a.A
|
||||||
|
import a.invoke
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val a = A()
|
||||||
|
<caret>a()
|
||||||
|
}
|
||||||
|
//-----------------------
|
||||||
|
|
||||||
|
|
||||||
+5
@@ -763,6 +763,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
runTest("idea/testData/quickfix/autoImports/invokeExtension.test");
|
runTest("idea/testData/quickfix/autoImports/invokeExtension.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("invokeExtension2.test")
|
||||||
|
public void testInvokeExtension2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/autoImports/invokeExtension2.test");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("invokeExtensionNoOperator.test")
|
@TestMetadata("invokeExtensionNoOperator.test")
|
||||||
public void testInvokeExtensionNoOperator() throws Exception {
|
public void testInvokeExtensionNoOperator() throws Exception {
|
||||||
runTest("idea/testData/quickfix/autoImports/invokeExtensionNoOperator.test");
|
runTest("idea/testData/quickfix/autoImports/invokeExtensionNoOperator.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user