if then to elvis: support calling extension function in class #KT-26343 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b34f32d4f3
commit
8f80851b9a
+6
-1
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
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.resolvedCallUtil.getImplicitReceiverValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
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
|
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() }
|
||||||
+5
@@ -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");
|
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")
|
@TestMetadata("ifAndElseBothInBlocks.kt")
|
||||||
public void testIfAndElseBothInBlocks() throws Exception {
|
public void testIfAndElseBothInBlocks() throws Exception {
|
||||||
runTest("idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt");
|
runTest("idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user