Smart completion: a bit more correct logic for last vararg parameter

This commit is contained in:
Valentin Kipyatkov
2015-06-04 22:28:24 +03:00
parent ee15eae6b3
commit 2197d554ca
3 changed files with 7 additions and 5 deletions
@@ -208,11 +208,13 @@ class ExpectedInfos(
if (isFunctionLiteralArgument) continue if (isFunctionLiteralArgument) continue
if (argumentName == null) { if (argumentName == null) {
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), // even if it's the last parameter, there can be more arguments for the same parameter
if (tail == Tail.RPARENTH) null else tail, descriptor, argumentPosition)) val varargTail = if (tail == Tail.RPARENTH) null else tail
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), varargTail, descriptor, argumentPosition))
if (argumentIndex == parameters.indexOf(parameter)) { if (argumentIndex == parameters.indexOf(parameter)) {
expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, tail, descriptor, argumentPosition, ItemOptions.STAR_PREFIX)) expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, varargTail, descriptor, argumentPosition, ItemOptions.STAR_PREFIX))
} }
} }
else { else {
@@ -1,7 +1,7 @@
fun foo(vararg strings: String){ } fun foo(vararg strings: String){ }
fun bar(arr: Array<String>){ fun bar(arr: Array<String>){
foo(*arr)<caret> foo(*arr<caret>)
} }
// ELEMENT: arr // ELEMENT: arr
@@ -1,7 +1,7 @@
fun foo(vararg strings: String){ } fun foo(vararg strings: String){ }
fun bar(list: List<String>){ fun bar(list: List<String>){
foo(*list.toTypedArray())<caret> foo(*list.toTypedArray()<caret>)
} }
// ELEMENT: toTypedArray // ELEMENT: toTypedArray