if then to elvis: support calling extension function in class #KT-26343 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-08-24 19:42:55 +09:00
committed by Mikhail Glukhikh
parent b34f32d4f3
commit 8f80851b9a
4 changed files with 21 additions and 1 deletions
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getImplicitReceiverValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
@@ -229,7 +230,11 @@ data class IfThenToSelectData(
}
}
internal fun getImplicitReceiver(): ImplicitReceiver? = baseClause.getResolvedCall(context)?.getImplicitReceiverValue()
internal fun getImplicitReceiver(): ImplicitReceiver? {
val resolvedCall = baseClause.getResolvedCall(context) ?: return null
if (resolvedCall.getExplicitReceiverValue() != null) return null
return resolvedCall.getImplicitReceiverValue()
}
internal fun hasImplicitReceiver(): Boolean = getImplicitReceiver() != null
@@ -0,0 +1,5 @@
class Foo {
fun Foo.bar(): Int = 1
}
fun Foo.test(foo: Foo?): Int = <caret>if (foo == null) { 0 } else { foo.bar() }
@@ -0,0 +1,5 @@
class Foo {
fun Foo.bar(): Int = 1
}
fun Foo.test(foo: Foo?): Int = foo?.bar() ?: 0
@@ -2276,6 +2276,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/branched/ifThenToElvis/emptyThenBlock.kt");
}
@TestMetadata("extensionFunctionInClass.kt")
public void testExtensionFunctionInClass() throws Exception {
runTest("idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt");
}
@TestMetadata("ifAndElseBothInBlocks.kt")
public void testIfAndElseBothInBlocks() throws Exception {
runTest("idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt");