Fixed KT-5110 Smart completion: do not generate comma if next argument has default value
Fixed KT-5109 Smart completion: do not insert comma if next argument is vararg #KT-5110 Fixed #KT-5109 Fixed
This commit is contained in:
@@ -48,7 +48,6 @@ import org.jetbrains.jet.lang.resolve.calls.util.noErrorsInValueArguments
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import org.jetbrains.jet.plugin.util.makeNullable
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
import org.jetbrains.jet.lang.psi.JetWhenConditionWithExpression
|
||||
import org.jetbrains.jet.lang.psi.JetWhenEntry
|
||||
@@ -149,13 +148,21 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo
|
||||
|
||||
val parameters = descriptor.getValueParameters()
|
||||
if (isFunctionLiteralArgument) {
|
||||
if (argumentIndex != parameters.size - 1) continue
|
||||
if (argumentIndex != parameters.lastIndex) continue
|
||||
}
|
||||
else {
|
||||
if (parameters.size <= argumentIndex) continue
|
||||
}
|
||||
val parameterDescriptor = parameters[argumentIndex]
|
||||
val tail = if (isFunctionLiteralArgument) null else if (argumentIndex == parameters.size - 1) Tail.RPARENTH else Tail.COMMA
|
||||
val tail = if (isFunctionLiteralArgument)
|
||||
null
|
||||
else if (argumentIndex == parameters.lastIndex)
|
||||
Tail.RPARENTH
|
||||
else if (parameters.drop(argumentIndex + 1).all { it.hasDefaultValue() || it.getVarargElementType() != null })
|
||||
null
|
||||
else
|
||||
Tail.COMMA
|
||||
|
||||
expectedInfos.add(ExpectedInfo(parameterDescriptor.getType(), tail))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p1: String, p2: String = ""){}
|
||||
|
||||
fun bar(p: String){
|
||||
foo(<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: p
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p1: String, p2: String = ""){}
|
||||
|
||||
fun bar(p: String){
|
||||
foo(p<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: p
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p1: String, vararg p2: String){}
|
||||
|
||||
fun bar(p: String){
|
||||
foo(<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: p
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p1: String, vararg p2: String){}
|
||||
|
||||
fun bar(p: String){
|
||||
foo(p<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: p
|
||||
+10
@@ -91,6 +91,16 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
||||
doTest("idea/testData/completion/handlers/smart/Comma1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Comma10.kt")
|
||||
public void testComma10() throws Exception {
|
||||
doTest("idea/testData/completion/handlers/smart/Comma10.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Comma11.kt")
|
||||
public void testComma11() throws Exception {
|
||||
doTest("idea/testData/completion/handlers/smart/Comma11.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Comma2.kt")
|
||||
public void testComma2() throws Exception {
|
||||
doTest("idea/testData/completion/handlers/smart/Comma2.kt");
|
||||
|
||||
Reference in New Issue
Block a user