Convert lambda to reference intention: apply shorten references to callable reference only, not to the whole argument list

This commit is contained in:
Mikhail Glukhikh
2016-09-08 20:01:02 +03:00
parent 06b7881776
commit 23132ad519
4 changed files with 19 additions and 1 deletions
@@ -201,7 +201,9 @@ class ConvertLambdaToReferenceIntention : SelfTargetingOffsetIndependentIntentio
(lambdaArgument.replace(newArgumentList) as? KtElement)?.let { ShortenReferences.DEFAULT.process(it) }
}
else {
(argumentList.replace(newArgumentList) as? KtElement)?.let { ShortenReferences.DEFAULT.process(it) }
(argumentList.replace(newArgumentList) as? KtValueArgumentList)?.let {
ShortenReferences.DEFAULT.process(it.arguments.last())
}
lambdaArgument.delete()
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun bar(s: String) = s.length
val x = listOf("Jack", "Tom").mapTo(kotlin.collections.hashSetOf<Int>()) <caret>{ w -> bar(w) }
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun bar(s: String) = s.length
val x = listOf("Jack", "Tom").mapTo(kotlin.collections.hashSetOf<Int>(), ::bar)
@@ -3994,6 +3994,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("mapToFqName.kt")
public void testMapToFqName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/mapToFqName.kt");
doTest(fileName);
}
@TestMetadata("member.kt")
public void testMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertLambdaToReference/member.kt");