Smart completion: function literal argument can correspond only to the last parameter!
This commit is contained in:
@@ -183,13 +183,11 @@ class ExpectedInfos(
|
|||||||
|
|
||||||
val expectedName = if (descriptor.hasSynthesizedParameterNames()) null else parameter.getName().asString()
|
val expectedName = if (descriptor.hasSynthesizedParameterNames()) null else parameter.getName().asString()
|
||||||
|
|
||||||
val lastNonOptionalParam = parameters.lastOrNull { !it.hasDefaultValue() }
|
|
||||||
|
|
||||||
fun needCommaForParameter(parameter: ValueParameterDescriptor): Boolean {
|
fun needCommaForParameter(parameter: ValueParameterDescriptor): Boolean {
|
||||||
if (parameter.hasDefaultValue()) return false // parameter is optional
|
if (parameter.hasDefaultValue()) return false // parameter is optional
|
||||||
if (parameter.getVarargElementType() != null) return false // vararg arguments list can be empty
|
if (parameter.getVarargElementType() != null) return false // vararg arguments list can be empty
|
||||||
// last non-optional parameter of functional type can be placed outside parenthesis:
|
// last parameter of functional type can be placed outside parenthesis:
|
||||||
if (parameter == lastNonOptionalParam && KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameter.getType())) return false
|
if (parameter == parameters.last() && KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameter.getType())) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
fun foo(p: Int, handler: () -> Unit, optional: String = ""){}
|
fun foo(p: Int, handler: () -> Unit, optional: String = ""){}
|
||||||
|
|
||||||
fun bar(p: Int) {
|
fun bar(p: Int) {
|
||||||
foo(p<caret>)
|
foo(p, <caret>)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ELEMENT: p
|
// ELEMENT: p
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(p: Int, handler: () -> Unit){}
|
||||||
|
|
||||||
|
fun bar(p: Int) {
|
||||||
|
foo(<caret>)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: p
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(p: Int, handler: () -> Unit){}
|
||||||
|
|
||||||
|
fun bar(p: Int) {
|
||||||
|
foo(p<caret>)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: p
|
||||||
+6
@@ -485,6 +485,12 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LastParamIsFunction.kt")
|
||||||
|
public void testLastParamIsFunction() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/LastParamIsFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MergeTail1.kt")
|
@TestMetadata("MergeTail1.kt")
|
||||||
public void testMergeTail1() throws Exception {
|
public void testMergeTail1() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/MergeTail1.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/MergeTail1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user