Skip to content

Commit 2b54f1a

Browse files
cypressiousmglukhikh
authored andcommitted
"Add names to call arguments" shouldn't appear when the only argument is a trailing lambda
Fixes #KT-15501
1 parent 44e69d8 commit 2b54f1a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

idea/src/org/jetbrains/kotlin/idea/intentions/AddNamesToCallArgumentsIntention.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2016 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
1919
import com.intellij.openapi.editor.Editor
2020
import com.intellij.openapi.util.TextRange
2121
import org.jetbrains.kotlin.idea.caches.resolve.analyze
22-
import org.jetbrains.kotlin.psi.KtCallElement
23-
import org.jetbrains.kotlin.psi.KtLambdaArgument
24-
import org.jetbrains.kotlin.psi.KtPsiFactory
25-
import org.jetbrains.kotlin.psi.KtValueArgument
22+
import org.jetbrains.kotlin.psi.*
2623
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
2724
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
2825
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatchStatus
@@ -35,7 +32,7 @@ class AddNamesToCallArgumentsIntention : SelfTargetingRangeIntention<KtCallEleme
3532
) {
3633
override fun applicabilityRange(element: KtCallElement): TextRange? {
3734
val arguments = element.valueArguments
38-
if (arguments.all { it.isNamed() }) return null
35+
if (arguments.all { it.isNamed() || it is LambdaArgument }) return null
3936

4037
val resolvedCall = element.getResolvedCall(element.analyze(BodyResolveMode.PARTIAL)) ?: return null
4138
if (!resolvedCall.resultingDescriptor.hasStableParameterNames()) return null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// IS_APPLICABLE: false
2+
fun foo(f: () -> Unit) {}
3+
4+
fun bar() {
5+
<caret>foo {}
6+
}

idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2016 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -473,6 +473,12 @@ public void testSuperClassConstructor() throws Exception {
473473
doTest(fileName);
474474
}
475475

476+
@TestMetadata("trailingLambda.kt")
477+
public void testTrailingLambda() throws Exception {
478+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addNamesToCallArguments/trailingLambda.kt");
479+
doTest(fileName);
480+
}
481+
476482
@TestMetadata("varargMultiple.kt")
477483
public void testVarargMultiple() throws Exception {
478484
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addNamesToCallArguments/varargMultiple.kt");

0 commit comments

Comments
 (0)