Smart completion: fixed in argument with "*"
This commit is contained in:
@@ -203,26 +203,36 @@ class ExpectedInfos(
|
||||
namedArgumentTail(argumentToParameter, argumentName, descriptor)
|
||||
}
|
||||
|
||||
val alreadyHasStar = argument.getSpreadElement() != null
|
||||
|
||||
val varargElementType = parameter.getVarargElementType()
|
||||
if (varargElementType != null) {
|
||||
if (isFunctionLiteralArgument) continue
|
||||
|
||||
val starOptions = if (!alreadyHasStar) ItemOptions.STAR_PREFIX else ItemOptions.DEFAULT
|
||||
if (argumentName == null) {
|
||||
// even if it's the last parameter, there can be more arguments for the same parameter
|
||||
val varargTail = if (tail == Tail.RPARENTH) null else tail
|
||||
|
||||
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), varargTail, descriptor, argumentPosition))
|
||||
if (!alreadyHasStar) {
|
||||
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), varargTail, descriptor, argumentPosition))
|
||||
}
|
||||
|
||||
if (argumentIndex == parameters.indexOf(parameter)) {
|
||||
expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, varargTail, descriptor, argumentPosition, ItemOptions.STAR_PREFIX))
|
||||
expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, varargTail, descriptor, argumentPosition, starOptions))
|
||||
}
|
||||
}
|
||||
else {
|
||||
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), tail, descriptor, argumentPosition))
|
||||
expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, tail, descriptor, argumentPosition, ItemOptions.STAR_PREFIX))
|
||||
if (!alreadyHasStar) {
|
||||
expectedInfos.add(ArgumentExpectedInfo(varargElementType, expectedName?.unpluralize(), tail, descriptor, argumentPosition))
|
||||
}
|
||||
|
||||
expectedInfos.add(ArgumentExpectedInfo(parameter.getType(), expectedName, tail, descriptor, argumentPosition, starOptions))
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (alreadyHasStar) continue
|
||||
|
||||
val parameterType = if (useHeuristicSignatures)
|
||||
HeuristicSignatures.correctedParameterType(descriptor, parameter, moduleDescriptor, callElement.getProject()) ?: parameter.getType()
|
||||
else
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(vararg strings: String){ }
|
||||
|
||||
fun bar(list: List<String>){
|
||||
foo(*list.<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: toTypedArray
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(vararg strings: String){ }
|
||||
|
||||
fun bar(list: List<String>){
|
||||
foo(*list.toTypedArray()<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: toTypedArray
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(vararg args: Any){ }
|
||||
|
||||
fun bar(s: String, arr: Array<String>){
|
||||
foo(args = *<caret>)
|
||||
}
|
||||
|
||||
// ABSENT: s
|
||||
// EXIST: { lookupString: "arr", itemText: "arr" }
|
||||
// ABSENT: { lookupString: "arr", itemText: "*arr" }
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(vararg args: Any){ }
|
||||
fun foo(s: String){ }
|
||||
|
||||
fun bar(s: String, arr: Array<String>){
|
||||
foo(*<caret>)
|
||||
}
|
||||
|
||||
// ABSENT: s
|
||||
// EXIST: { lookupString: "arr", itemText: "arr" }
|
||||
// ABSENT: { lookupString: "arr", itemText: "*arr" }
|
||||
+12
@@ -269,6 +269,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NamedVarargAfterStar.kt")
|
||||
public void testNamedVarargAfterStar() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/NamedVarargAfterStar.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoExtensionMethodFromClassObject.kt")
|
||||
public void testNoExtensionMethodFromClassObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/NoExtensionMethodFromClassObject.kt");
|
||||
@@ -419,6 +425,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarargAfterStar.kt")
|
||||
public void testVarargAfterStar() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/VarargAfterStar.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VariableAsFunction1.kt")
|
||||
public void testVariableAsFunction1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/VariableAsFunction1.kt");
|
||||
|
||||
+6
@@ -767,6 +767,12 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarargAfterStar.kt")
|
||||
public void testVarargAfterStar() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/VarargAfterStar.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarargWithParameterAfter.kt")
|
||||
public void testVarargWithParameterAfter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/VarargWithParameterAfter.kt");
|
||||
|
||||
Reference in New Issue
Block a user