Convert to anonymous function: do not name argument when lambda is Java method
#KT-30613 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
033d7262a2
commit
93d854362b
@@ -114,7 +114,7 @@ fun KtLambdaExpression.moveFunctionLiteralOutsideParenthesesIfPossible() {
|
||||
|
||||
private fun shouldLambdaParameterBeNamed(args: List<ValueArgument>, callExpr: KtCallExpression): Boolean {
|
||||
if (args.any { it.isNamed() }) return true
|
||||
val callee = (callExpr.calleeExpression?.mainReference?.resolve() as? KtFunction) ?: return true
|
||||
val callee = (callExpr.calleeExpression?.mainReference?.resolve() as? KtFunction) ?: return false
|
||||
return if (callee.valueParameters.any { it.isVarArg }) true else callee.valueParameters.size - 1 > args.size
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Test {
|
||||
void foo(Sam s) {}
|
||||
}
|
||||
|
||||
interface Sam {
|
||||
void foo(int x);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Test {
|
||||
void foo(Sam s) {}
|
||||
}
|
||||
|
||||
interface Sam {
|
||||
void foo(int x);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
Test().foo <caret>{}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun main() {
|
||||
Test().foo(fun(it: Int) {
|
||||
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Test {
|
||||
void foo(Sam s) {}
|
||||
}
|
||||
|
||||
interface Sam {
|
||||
void foo(int x);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Test {
|
||||
void foo(Sam s) {}
|
||||
}
|
||||
|
||||
interface Sam {
|
||||
void foo(int x);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
Test().foo {}<caret>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
Test().foo({})
|
||||
}
|
||||
@@ -11105,6 +11105,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/incorrectOffset.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaMethod.kt")
|
||||
public void testJavaMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/javaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("namedArgument.kt")
|
||||
public void testNamedArgument() throws Exception {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/namedArgument.kt");
|
||||
@@ -12627,6 +12632,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/moveLambdaInsideParentheses/inapplicable2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaMethod.kt")
|
||||
public void testJavaMethod() throws Exception {
|
||||
runTest("idea/testData/intentions/moveLambdaInsideParentheses/javaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("moveLabeledLambda1.kt")
|
||||
public void testMoveLabeledLambda1() throws Exception {
|
||||
runTest("idea/testData/intentions/moveLambdaInsideParentheses/moveLabeledLambda1.kt");
|
||||
|
||||
Reference in New Issue
Block a user