Lambda to reference: not-null types are now preferred for platform type receivers #KT-14394 Fixed
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
@@ -30,9 +29,6 @@ import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.approximateFlexibleTypes
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStartOffsetIn
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.REFERENCE_TARGET
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
@@ -227,7 +223,7 @@ class ConvertLambdaToReferenceIntention : SelfTargetingOffsetIndependentIntentio
|
||||
val context = receiver.analyze()
|
||||
val receiverDescriptor = context[REFERENCE_TARGET, receiver] as? ParameterDescriptor ?: return null
|
||||
val originalReceiverType = receiverDescriptor.type
|
||||
val receiverType = originalReceiverType.approximateFlexibleTypes()
|
||||
val receiverType = originalReceiverType.approximateFlexibleTypes(preferNotNull = true)
|
||||
if (shortTypes) {
|
||||
"${IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(receiverType)}::$selectorReferenceName"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val y = java.lang.String.valueOf(42)
|
||||
val x = y.let { <caret>it.capitalize() }
|
||||
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val y = java.lang.String.valueOf(42)
|
||||
val x = y.let(String::capitalize)
|
||||
@@ -2,5 +2,5 @@
|
||||
// See KT-13411
|
||||
|
||||
fun use() {
|
||||
B.text.map(Any?::toString)
|
||||
B.text.map(Any::toString)
|
||||
}
|
||||
+1
-1
@@ -3,5 +3,5 @@
|
||||
|
||||
fun use() {
|
||||
val text = B.text
|
||||
text.map(MutableList<Any>?::toString)
|
||||
text.map(MutableList<Any>::toString)
|
||||
}
|
||||
@@ -4135,6 +4135,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("platformType.kt")
|
||||
public void testPlatformType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/platformType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("receiverParameter.kt")
|
||||
public void testReceiverParameter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/receiverParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user