Make implicit this inspection work for lambda invocation #KT-22970 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a87f652591
commit
733cb42ced
@@ -23,6 +23,7 @@ import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.getFactoryForImplicitReceiverWithSubtypeOf
|
||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -52,8 +53,10 @@ class ImplicitThisInspection : AbstractKotlinInspection() {
|
||||
val context = reference.analyze()
|
||||
val scope = reference.getResolutionScope(context) ?: return
|
||||
|
||||
val descriptor = context[BindingContext.REFERENCE_TARGET, reference] as? CallableDescriptor ?: return
|
||||
val receiverDescriptor = descriptor.extensionReceiverParameter ?: descriptor.dispatchReceiverParameter ?: return
|
||||
val descriptor = reference.getCallableDescriptor() ?: return
|
||||
val receiverDescriptor = descriptor.extensionReceiverParameter
|
||||
?: descriptor.dispatchReceiverParameter
|
||||
?: return
|
||||
val receiverType = receiverDescriptor.type
|
||||
|
||||
val expressionFactory = scope.getFactoryForImplicitReceiverWithSubtypeOf(receiverType) ?: return
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun CharSequence.foo(bar: CharSequence.() -> Unit){
|
||||
<caret>bar()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun CharSequence.foo(bar: CharSequence.() -> Unit){
|
||||
<caret>this.bar()
|
||||
}
|
||||
+6
@@ -1485,6 +1485,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithReceiver.kt")
|
||||
public void testFunctionWithReceiver() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/implicitThis/functionWithReceiver.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleReceivers.kt")
|
||||
public void testMultipleReceivers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/implicitThis/multipleReceivers.kt");
|
||||
|
||||
Reference in New Issue
Block a user