Lambda --> reference: correct handling of parameter-less function

Issue #KT-15556 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-03-10 16:32:19 +03:00
parent b6974a88c5
commit 19db4869e6
6 changed files with 28 additions and 3 deletions
@@ -99,8 +99,8 @@ class ConvertLambdaToReferenceIntention : SelfTargetingOffsetIndependentIntentio
val lambdaParameterAsExplicitReceiver = explicitReceiverDescriptor != null &&
explicitReceiverDescriptor == lambdaValueParameterDescriptors.firstOrNull()
val explicitReceiverShift = if (lambdaParameterAsExplicitReceiver) 1 else 0
val lambdaParametersCount =
if (lambdaExpression.functionLiteral.hasParameterSpecification()) lambdaExpression.valueParameters.size else 1
val lambdaParametersCount = lambdaValueParameterDescriptors.size
if (lambdaParametersCount != callableArgumentsCount + explicitReceiverShift) return false
if (explicitReceiver != null && explicitReceiverDescriptor != null && lambdaParameterAsExplicitReceiver) {
@@ -0,0 +1,5 @@
class Foo
fun usage(f: () -> Foo) {}
fun test() {
usage {<caret> Foo() }
}
@@ -0,0 +1,5 @@
class Foo
fun usage(f: () -> Foo) {}
fun test() {
usage(::Foo)
}
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// IS_APPLICABLE: true
// WITH_RUNTIME
fun foo() {
@@ -0,0 +1,9 @@
// IS_APPLICABLE: true
// WITH_RUNTIME
fun foo() {
listOf(1).forEach { run(it::bar) }
}
fun Int.bar() {
}
@@ -4340,6 +4340,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("defaultConstructor.kt")
public void testDefaultConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/defaultConstructor.kt");
doTest(fileName);
}
@TestMetadata("defaultNamed.kt")
public void testDefaultNamed() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/defaultNamed.kt");