Make implicit this inspection work for lambda invocation #KT-22970 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-02-27 09:10:22 +03:00
committed by Mikhail Glukhikh
parent a87f652591
commit 733cb42ced
4 changed files with 17 additions and 2 deletions
@@ -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()
}
@@ -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");