Smart completion: function literal argument can correspond only to the last parameter!

This commit is contained in:
Valentin Kipyatkov
2015-06-04 22:21:11 +03:00
parent 6284f557e6
commit ee15eae6b3
5 changed files with 23 additions and 5 deletions
@@ -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,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
@@ -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");