From 67df7de7b17b3fb9bdae66175f76949504879017 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 22 Jul 2014 18:53:41 +0400 Subject: [PATCH] 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 --- .../jet/plugin/completion/ExpectedInfos.kt | 13 ++++++++++--- idea/testData/completion/handlers/smart/Comma10.kt | 7 +++++++ .../completion/handlers/smart/Comma10.kt.after | 7 +++++++ idea/testData/completion/handlers/smart/Comma11.kt | 7 +++++++ .../completion/handlers/smart/Comma11.kt.after | 7 +++++++ .../SmartCompletionHandlerTestGenerated.java | 10 ++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 idea/testData/completion/handlers/smart/Comma10.kt create mode 100644 idea/testData/completion/handlers/smart/Comma10.kt.after create mode 100644 idea/testData/completion/handlers/smart/Comma11.kt create mode 100644 idea/testData/completion/handlers/smart/Comma11.kt.after diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index aaa2e5ebed0..9ef00fa9e7e 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -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)) } } diff --git a/idea/testData/completion/handlers/smart/Comma10.kt b/idea/testData/completion/handlers/smart/Comma10.kt new file mode 100644 index 00000000000..2f3e56ef0be --- /dev/null +++ b/idea/testData/completion/handlers/smart/Comma10.kt @@ -0,0 +1,7 @@ +fun foo(p1: String, p2: String = ""){} + +fun bar(p: String){ + foo() +} + +// ELEMENT: p diff --git a/idea/testData/completion/handlers/smart/Comma10.kt.after b/idea/testData/completion/handlers/smart/Comma10.kt.after new file mode 100644 index 00000000000..fb868a143e3 --- /dev/null +++ b/idea/testData/completion/handlers/smart/Comma10.kt.after @@ -0,0 +1,7 @@ +fun foo(p1: String, p2: String = ""){} + +fun bar(p: String){ + foo(p) +} + +// ELEMENT: p diff --git a/idea/testData/completion/handlers/smart/Comma11.kt b/idea/testData/completion/handlers/smart/Comma11.kt new file mode 100644 index 00000000000..ca7e7c7776f --- /dev/null +++ b/idea/testData/completion/handlers/smart/Comma11.kt @@ -0,0 +1,7 @@ +fun foo(p1: String, vararg p2: String){} + +fun bar(p: String){ + foo() +} + +// ELEMENT: p diff --git a/idea/testData/completion/handlers/smart/Comma11.kt.after b/idea/testData/completion/handlers/smart/Comma11.kt.after new file mode 100644 index 00000000000..618fe11a35b --- /dev/null +++ b/idea/testData/completion/handlers/smart/Comma11.kt.after @@ -0,0 +1,7 @@ +fun foo(p1: String, vararg p2: String){} + +fun bar(p: String){ + foo(p) +} + +// ELEMENT: p diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java index 26ca5b602a5..54d04511369 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java @@ -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");