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 lastNonOptionalParam = parameters.lastOrNull { !it.hasDefaultValue() }
|
||||
|
||||
fun needCommaForParameter(parameter: ValueParameterDescriptor): Boolean {
|
||||
if (parameter.hasDefaultValue()) return false // parameter is optional
|
||||
if (parameter.getVarargElementType() != null) return false // vararg arguments list can be empty
|
||||
// last non-optional parameter of functional type can be placed outside parenthesis:
|
||||
if (parameter == lastNonOptionalParam && KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameter.getType())) return false
|
||||
// last parameter of functional type can be placed outside parenthesis:
|
||||
if (parameter == parameters.last() && KotlinBuiltIns.isFunctionOrExtensionFunctionType(parameter.getType())) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun foo(p: Int, handler: () -> Unit, optional: String = ""){}
|
||||
|
||||
fun bar(p: Int) {
|
||||
foo(p<caret>)
|
||||
foo(p, <caret>)
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@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")
|
||||
public void testMergeTail1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/MergeTail1.kt");
|
||||
|
||||
Reference in New Issue
Block a user