From 7410c36e3a883839f9be75d122a3a341e164aa0d Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 14 Nov 2014 21:23:05 +0300 Subject: [PATCH] Completion: moved signatures from "item text" to tail #KT-5652 Fixed --- .../jet/plugin/completion/CompletionUtils.kt | 10 +++- .../completion/KotlinLookupElementFactory.kt | 51 ++++++++++--------- .../completion/LookupElementsCollector.kt | 6 ++- .../completion/smart/SmartCompletion.kt | 3 +- .../smart/TypeInstantiationItems.kt | 7 ++- .../common/FunctionCompletionFormatting.kt | 2 +- .../basic/common/HigherOrderFunction1.kt | 4 +- .../basic/common/HigherOrderFunction2.kt | 8 +++ .../java/ExtensionFromStandardLibrary.kt | 2 +- .../smart/JavaStaticMethodInsertsImport.kt | 3 +- .../JavaStaticMethodInsertsImport.kt.after | 3 +- .../handlers/smart/NullableValue2.kt | 3 +- .../handlers/smart/NullableValue2.kt.after | 3 +- .../handlers/smart/NullableValue3.kt | 3 +- .../handlers/smart/NullableValue3.kt.after | 3 +- .../completion/smart/ClassObjectMembers.kt | 2 +- .../smart/ClassObjectMembersForNullable.kt | 2 +- idea/testData/completion/smart/Constructor.kt | 2 +- .../smart/ConstructorForGenericType.kt | 2 +- .../smart/ConstructorForJavaClass.kt | 2 +- .../smart/ConstructorForNullable.kt | 2 +- .../smart/ConstructorWithParameters.kt | 2 +- idea/testData/completion/smart/EmptyPrefix.kt | 2 +- .../completion/smart/FunctionReference1.kt | 2 +- .../completion/smart/InElvisOperator2.kt | 8 +-- .../completion/smart/JavaStaticMethods.kt | 6 +-- .../smart/NoExtensionMethodFromClassObject.kt | 2 +- .../testData/completion/smart/SAMExpected1.kt | 2 +- .../completion/ExpectedCompletionUtils.java | 6 ++- .../JSBasicCompletionTestGenerated.java | 6 +++ .../JvmBasicCompletionTestGenerated.java | 6 +++ .../handlers/BasicCompletionHandlerTest.kt | 8 +-- 32 files changed, 112 insertions(+), 61 deletions(-) create mode 100644 idea/testData/completion/basic/common/HigherOrderFunction2.kt diff --git a/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt b/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt index b69e492965d..255b3118600 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers import com.intellij.codeInsight.completion.PrefixMatcher import org.jetbrains.jet.lang.resolve.name.Name +import com.intellij.codeInsight.lookup.LookupElementPresentation enum class ItemPriority { MULTIPLE_ARGUMENTS_ITEM @@ -79,4 +80,11 @@ private fun qualifierName(descriptor: DeclarationDescriptor): String? = when (de else -> null } -fun PrefixMatcher.asNameFilter() = { (name: Name) -> !name.isSpecial() && prefixMatches(name.getIdentifier()) } \ No newline at end of file +fun PrefixMatcher.asNameFilter() = { (name: Name) -> !name.isSpecial() && prefixMatches(name.getIdentifier()) } + +fun LookupElementPresentation.prependTailText(text: String, grayed: Boolean) { + val tails = getTailFragments() + clearTail() + appendTailText(text, grayed) + tails.forEach { appendTailText(it.text, it.isGrayed()) } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/completion/KotlinLookupElementFactory.kt b/idea/src/org/jetbrains/jet/plugin/completion/KotlinLookupElementFactory.kt index 017d40e183f..ae39e508b3e 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/KotlinLookupElementFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/KotlinLookupElementFactory.kt @@ -58,40 +58,43 @@ public object KotlinLookupElementFactory { return createLookupElementForJavaClass(declaration) } - val name = descriptor.getName().asString() - var element = LookupElementBuilder.create(DeclarationDescriptorLookupObject(descriptor, analyzer, declaration), name) - var presentableText = name - var typeText = "" - var tailText = "" + var element = LookupElementBuilder.create(DeclarationDescriptorLookupObject(descriptor, analyzer, declaration), descriptor.getName().asString()) + .withIcon(JetDescriptorIconProvider.getIcon(descriptor, declaration, Iconable.ICON_FLAG_VISIBILITY)) - if (descriptor is FunctionDescriptor) { - val returnType = descriptor.getReturnType() - typeText = if (returnType != null) DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(returnType) else "" - presentableText += DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(descriptor) + when (descriptor) { + is FunctionDescriptor -> { + val returnType = descriptor.getReturnType() + element = element.withTypeText(if (returnType != null) DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(returnType) else "") + element = element.appendTailText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(descriptor), false) - if (descriptor.getExtensionReceiverParameter() != null) { - tailText += " for " + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getExtensionReceiverParameter()!!.getType()) - tailText += " in " + DescriptorUtils.getFqName(descriptor.getContainingDeclaration()) + if (descriptor.getExtensionReceiverParameter() != null) { + val tail = " for " + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getExtensionReceiverParameter()!!.getType()) + + " in " + DescriptorUtils.getFqName(descriptor.getContainingDeclaration()) + element = element.appendTailText(tail, true) + } + } + + is VariableDescriptor -> { + element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType())) + } + + is ClassDescriptor -> { + element = element.appendTailText(" (" + DescriptorUtils.getFqName(descriptor.getContainingDeclaration()) + ")", true) + } + + else -> { + element = element.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor)) } } - else if (descriptor is VariableDescriptor) { - typeText = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()) - } - else if (descriptor is ClassDescriptor) { - tailText = " (" + DescriptorUtils.getFqName(descriptor.getContainingDeclaration()) + ")" - } - else { - typeText = DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor) + + if (KotlinBuiltIns.getInstance().isDeprecated(descriptor)) { + element = element.withStrikeoutness(true) } val insertHandler = getDefaultInsertHandler(descriptor) element = element.withInsertHandler(insertHandler) - element = element.withTailText(tailText, true).withTypeText(typeText).withPresentableText(presentableText) - element = element.withIcon(JetDescriptorIconProvider.getIcon(descriptor, declaration, Iconable.ICON_FLAG_VISIBILITY)) - element = element.withStrikeoutness(KotlinBuiltIns.getInstance().isDeprecated(descriptor)) - if (insertHandler is KotlinFunctionInsertHandler && insertHandler.lambdaInfo != null) { element.putUserData(KotlinCompletionCharFilter.ACCEPT_OPENING_BRACE, true) } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/LookupElementsCollector.kt b/idea/src/org/jetbrains/jet/plugin/completion/LookupElementsCollector.kt index 89887faa0cc..eecb96d0a15 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/LookupElementsCollector.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/LookupElementsCollector.kt @@ -80,7 +80,11 @@ class LookupElementsCollector( addElement(object : LookupElementDecorator(lookupElement) { override fun renderElement(presentation: LookupElementPresentation) { super.renderElement(presentation) - presentation.setItemText(getLookupString() + " " + buildLambdaPresentation(parameterType)) + + val tails = presentation.getTailFragments() + presentation.clearTail() + presentation.appendTailText(" " + buildLambdaPresentation(parameterType), false) + tails.drop(1)/*drop old function signature*/.forEach { presentation.appendTailText(it.text, it.isGrayed()) } } override fun handleInsert(context: InsertionContext) { diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt index 319a578114d..c8808fb50ae 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt @@ -246,7 +246,8 @@ class SmartCompletion(val expression: JetSimpleNameExpression, override fun renderElement(presentation: LookupElementPresentation) { super.renderElement(presentation) presentation.setItemText(text) - presentation.setTypeText("") + presentation.clearTail() + presentation.setTypeText(null) } override fun handleInsert(context: InsertionContext) { diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/TypeInstantiationItems.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/TypeInstantiationItems.kt index c5589f00c9e..1ca84dd089c 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/TypeInstantiationItems.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/TypeInstantiationItems.kt @@ -74,6 +74,7 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi val typeArgs = jetType.getArguments() var itemText = lookupString + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgs) + var signatureText: String? = null val insertHandler: InsertHandler val typeText = qualifiedNameForSourceCode(classifier) + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgs) @@ -99,7 +100,7 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi } else { //TODO: when constructor has one parameter of lambda type with more than one parameter, generate special additional item - itemText += when (visibleConstructors.size) { + signatureText = when (visibleConstructors.size) { 0 -> "()" 1 -> DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(visibleConstructors.single()) else -> "(...)" @@ -138,6 +139,10 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi override fun renderElement(presentation: LookupElementPresentation) { getDelegate().renderElement(presentation) presentation.setItemText(itemText) + + if (signatureText != null) { + presentation.prependTailText(signatureText!!, false) + } } override fun handleInsert(context: InsertionContext) { diff --git a/idea/testData/completion/basic/common/FunctionCompletionFormatting.kt b/idea/testData/completion/basic/common/FunctionCompletionFormatting.kt index 5958b694ea2..c01528b67db 100644 --- a/idea/testData/completion/basic/common/FunctionCompletionFormatting.kt +++ b/idea/testData/completion/basic/common/FunctionCompletionFormatting.kt @@ -4,4 +4,4 @@ fun some() { tes } -// EXIST: { lookupString:"test", itemText:"test(a: Int)" } \ No newline at end of file +// EXIST: { lookupString:"test", itemText:"test", tailText:"(a: Int)" } \ No newline at end of file diff --git a/idea/testData/completion/basic/common/HigherOrderFunction1.kt b/idea/testData/completion/basic/common/HigherOrderFunction1.kt index e3cec87323c..6c193db26e8 100644 --- a/idea/testData/completion/basic/common/HigherOrderFunction1.kt +++ b/idea/testData/completion/basic/common/HigherOrderFunction1.kt @@ -4,5 +4,5 @@ fun test() { fo } -// EXIST: { lookupString:"foo", itemText: "foo(p: (String, Char) -> Unit)", typeText:"Unit" } -// EXIST: { lookupString:"foo", itemText: "foo { (String, Char) -> ... }", typeText:"Unit" } +// EXIST: { lookupString:"foo", itemText: "foo", tailText: "(p: (String, Char) -> Unit)", typeText:"Unit" } +// EXIST: { lookupString:"foo", itemText: "foo", tailText: " { (String, Char) -> ... }", typeText:"Unit" } diff --git a/idea/testData/completion/basic/common/HigherOrderFunction2.kt b/idea/testData/completion/basic/common/HigherOrderFunction2.kt new file mode 100644 index 00000000000..3037f76ad78 --- /dev/null +++ b/idea/testData/completion/basic/common/HigherOrderFunction2.kt @@ -0,0 +1,8 @@ +fun String.foo(p: (String, Char) -> Unit){} + +fun test() { + "".fo +} + +// EXIST: { lookupString:"foo", itemText: "foo", tailText: "(p: (String, Char) -> Unit) for String in ", typeText:"Unit" } +// EXIST: { lookupString:"foo", itemText: "foo", tailText: " { (String, Char) -> ... } for String in ", typeText:"Unit" } diff --git a/idea/testData/completion/basic/java/ExtensionFromStandardLibrary.kt b/idea/testData/completion/basic/java/ExtensionFromStandardLibrary.kt index 7278be92567..60021cd39b6 100644 --- a/idea/testData/completion/basic/java/ExtensionFromStandardLibrary.kt +++ b/idea/testData/completion/basic/java/ExtensionFromStandardLibrary.kt @@ -8,5 +8,5 @@ fun firstFun() { } // INVOCATION_COUNT: 1 -// EXIST: { lookupString:"toLinkedList", itemText:"toLinkedList()", tailText:" for Iterable in kotlin" } +// EXIST: { lookupString:"toLinkedList", itemText:"toLinkedList", tailText:"() for Iterable in kotlin" } // NUMBER: 1 diff --git a/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt b/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt index 2b79d4c6de3..75fb8fd629f 100644 --- a/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt +++ b/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt @@ -2,4 +2,5 @@ fun foo(){ val l : java.util.Calendar = } -// ELEMENT_TEXT: Calendar.getInstance(TimeZone!) +// ELEMENT_TEXT: Calendar.getInstance +// TAIL_TEXT: (TimeZone!) diff --git a/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt.after b/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt.after index 8309bfd4595..6cf13af7212 100644 --- a/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt.after +++ b/idea/testData/completion/handlers/smart/JavaStaticMethodInsertsImport.kt.after @@ -4,4 +4,5 @@ fun foo(){ val l : java.util.Calendar = Calendar.getInstance() } -// ELEMENT_TEXT: Calendar.getInstance(TimeZone!) +// ELEMENT_TEXT: Calendar.getInstance +// TAIL_TEXT: (TimeZone!) diff --git a/idea/testData/completion/handlers/smart/NullableValue2.kt b/idea/testData/completion/handlers/smart/NullableValue2.kt index 2256819947a..a1e7783e4d7 100644 --- a/idea/testData/completion/handlers/smart/NullableValue2.kt +++ b/idea/testData/completion/handlers/smart/NullableValue2.kt @@ -6,4 +6,5 @@ fun bar() { foo() } -// ELEMENT_TEXT: "?: getString(i: Int)" +// ELEMENT_TEXT: "?: getString" +// TAIL_TEXT: "(i: Int)" diff --git a/idea/testData/completion/handlers/smart/NullableValue2.kt.after b/idea/testData/completion/handlers/smart/NullableValue2.kt.after index 0d28b7437ff..71edf2f6b98 100644 --- a/idea/testData/completion/handlers/smart/NullableValue2.kt.after +++ b/idea/testData/completion/handlers/smart/NullableValue2.kt.after @@ -6,4 +6,5 @@ fun bar() { foo(getString() ?: ) } -// ELEMENT_TEXT: "?: getString(i: Int)" +// ELEMENT_TEXT: "?: getString" +// TAIL_TEXT: "(i: Int)" diff --git a/idea/testData/completion/handlers/smart/NullableValue3.kt b/idea/testData/completion/handlers/smart/NullableValue3.kt index c1604bc16d1..39e3a165e96 100644 --- a/idea/testData/completion/handlers/smart/NullableValue3.kt +++ b/idea/testData/completion/handlers/smart/NullableValue3.kt @@ -8,4 +8,5 @@ fun foo(){ val k : K = } -// ELEMENT_TEXT: "!! K.bar()" +// ELEMENT_TEXT: "!! K.bar" +// TAIL_TEXT: "()" diff --git a/idea/testData/completion/handlers/smart/NullableValue3.kt.after b/idea/testData/completion/handlers/smart/NullableValue3.kt.after index 274bd34fb0c..dcebcc886e1 100644 --- a/idea/testData/completion/handlers/smart/NullableValue3.kt.after +++ b/idea/testData/completion/handlers/smart/NullableValue3.kt.after @@ -8,4 +8,5 @@ fun foo(){ val k : K = K.bar()!! } -// ELEMENT_TEXT: "!! K.bar()" +// ELEMENT_TEXT: "!! K.bar" +// TAIL_TEXT: "()" diff --git a/idea/testData/completion/smart/ClassObjectMembers.kt b/idea/testData/completion/smart/ClassObjectMembers.kt index c6d94a72037..4ff119b5776 100644 --- a/idea/testData/completion/smart/ClassObjectMembers.kt +++ b/idea/testData/completion/smart/ClassObjectMembers.kt @@ -15,7 +15,7 @@ fun foo(){ } // EXIST: { lookupString:"foo", itemText:"K.foo", tailText:" (sample)", typeText:"K" } -// EXIST: { lookupString:"bar", itemText:"K.bar()", tailText:" (sample)", typeText:"K" } +// EXIST: { lookupString:"bar", itemText:"K.bar", tailText:"() (sample)", typeText:"K" } // ABSENT: { itemText: "K.x" } // ABSENT: { itemText:"K.kk" } // EXIST: { lookupString:"kk", itemText:"!! K.kk", tailText:" (sample)", typeText:"K?" } diff --git a/idea/testData/completion/smart/ClassObjectMembersForNullable.kt b/idea/testData/completion/smart/ClassObjectMembersForNullable.kt index f9f86bf22ec..a94c621a2c1 100644 --- a/idea/testData/completion/smart/ClassObjectMembersForNullable.kt +++ b/idea/testData/completion/smart/ClassObjectMembersForNullable.kt @@ -14,6 +14,6 @@ fun foo(){ } // EXIST: { lookupString:"foo", itemText:"K.foo", tailText:" (sample)", typeText:"K" } -// EXIST: { lookupString:"bar", itemText:"K.bar()", tailText:" (sample)", typeText:"K" } +// EXIST: { lookupString:"bar", itemText:"K.bar", tailText:"() (sample)", typeText:"K" } // ABSENT: { itemText: "K.x" } // EXIST: { lookupString:"kk", itemText:"K.kk", tailText:" (sample)", typeText:"K?" } diff --git a/idea/testData/completion/smart/Constructor.kt b/idea/testData/completion/smart/Constructor.kt index 9f18f29c067..c93b4d62965 100644 --- a/idea/testData/completion/smart/Constructor.kt +++ b/idea/testData/completion/smart/Constructor.kt @@ -2,4 +2,4 @@ class Foo var a : Foo = -// EXIST: { lookupString:"Foo", itemText:"Foo()" } +// EXIST: { lookupString:"Foo", itemText:"Foo", tailText: "() ()" } diff --git a/idea/testData/completion/smart/ConstructorForGenericType.kt b/idea/testData/completion/smart/ConstructorForGenericType.kt index 69a55351829..851177494a6 100644 --- a/idea/testData/completion/smart/ConstructorForGenericType.kt +++ b/idea/testData/completion/smart/ConstructorForGenericType.kt @@ -4,4 +4,4 @@ fun foo(p : Any){ var a : Foo = } -// EXIST: { lookupString:"Foo", itemText:"Foo()" } +// EXIST: { lookupString:"Foo", itemText:"Foo", tailText:"() ()" } diff --git a/idea/testData/completion/smart/ConstructorForJavaClass.kt b/idea/testData/completion/smart/ConstructorForJavaClass.kt index 3c356a4997d..6b96e75f08e 100644 --- a/idea/testData/completion/smart/ConstructorForJavaClass.kt +++ b/idea/testData/completion/smart/ConstructorForJavaClass.kt @@ -2,4 +2,4 @@ import java.util.Date var a : Date = -// EXIST: { lookupString:"Date", itemText:"Date(...)" } +// EXIST: { lookupString:"Date", itemText:"Date", tailText:"(...) (java.util)" } diff --git a/idea/testData/completion/smart/ConstructorForNullable.kt b/idea/testData/completion/smart/ConstructorForNullable.kt index 3922d4c8210..fb60cca277d 100644 --- a/idea/testData/completion/smart/ConstructorForNullable.kt +++ b/idea/testData/completion/smart/ConstructorForNullable.kt @@ -4,4 +4,4 @@ fun foo(p : Any){ var a : Foo? = } -// EXIST: { lookupString:"Foo", itemText:"Foo()" } +// EXIST: { lookupString:"Foo", itemText:"Foo", tailText: "() ()" } diff --git a/idea/testData/completion/smart/ConstructorWithParameters.kt b/idea/testData/completion/smart/ConstructorWithParameters.kt index de012299e99..d521c14b65e 100644 --- a/idea/testData/completion/smart/ConstructorWithParameters.kt +++ b/idea/testData/completion/smart/ConstructorWithParameters.kt @@ -2,4 +2,4 @@ class Foo(val p1: String, val p2: Any?) var a : Foo = -// EXIST: { lookupString:"Foo", itemText:"Foo(p1: String, p2: Any?)" } +// EXIST: { lookupString:"Foo", itemText:"Foo", tailText:"(p1: String, p2: Any?) ()" } diff --git a/idea/testData/completion/smart/EmptyPrefix.kt b/idea/testData/completion/smart/EmptyPrefix.kt index 74e0927cbb7..4cc54d82743 100644 --- a/idea/testData/completion/smart/EmptyPrefix.kt +++ b/idea/testData/completion/smart/EmptyPrefix.kt @@ -26,4 +26,4 @@ fun f3() : String{} // EXIST: f1 // EXIST: f2 // ABSENT: f3 -// EXIST: { lookupString:"Foo", itemText:"Foo()" } +// EXIST: { lookupString:"Foo", itemText:"Foo", tailText: "() ()" } diff --git a/idea/testData/completion/smart/FunctionReference1.kt b/idea/testData/completion/smart/FunctionReference1.kt index d334c5f794f..1d57eea8997 100644 --- a/idea/testData/completion/smart/FunctionReference1.kt +++ b/idea/testData/completion/smart/FunctionReference1.kt @@ -7,7 +7,7 @@ fun bar() { fun f1(){} fun f2(i: Int){} -// EXIST: { lookupString:"::f1", itemText:"::f1", tailText:"", typeText:"" } +// EXIST: { lookupString:"::f1", itemText:"::f1", tailText:null, typeText:null } // ABSENT: ::f2 // ABSENT: ::Unit // ABSENT: ::Nothing diff --git a/idea/testData/completion/smart/InElvisOperator2.kt b/idea/testData/completion/smart/InElvisOperator2.kt index 0ac6283556b..b816425af7f 100644 --- a/idea/testData/completion/smart/InElvisOperator2.kt +++ b/idea/testData/completion/smart/InElvisOperator2.kt @@ -6,7 +6,7 @@ fun bar() { foo1() ?: } -// EXIST: { itemText:"foo3()" } -// ABSENT: { itemText:"foo2()" } -// EXIST: { itemText:"!! foo2()" } -// EXIST: { itemText:"?: foo2()" } +// EXIST: { itemText:"foo3" } +// ABSENT: { itemText:"foo2" } +// EXIST: { itemText:"!! foo2" } +// EXIST: { itemText:"?: foo2" } diff --git a/idea/testData/completion/smart/JavaStaticMethods.kt b/idea/testData/completion/smart/JavaStaticMethods.kt index f82ca9c3eed..9d87c00bcda 100644 --- a/idea/testData/completion/smart/JavaStaticMethods.kt +++ b/idea/testData/completion/smart/JavaStaticMethods.kt @@ -2,6 +2,6 @@ fun foo(){ val l : java.util.Calendar = } -// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance()", tailText:" (java.util)", typeText:"Calendar!" } -// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance(TimeZone!)", tailText:" (java.util)", typeText:"Calendar!" } -// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance(TimeZone!, Locale!)", tailText:" (java.util)", typeText:"Calendar!" } +// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance", tailText:"() (java.util)", typeText:"Calendar!" } +// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance", tailText:"(TimeZone!) (java.util)", typeText:"Calendar!" } +// EXIST: { lookupString:"getInstance", itemText:"Calendar.getInstance", tailText:"(TimeZone!, Locale!) (java.util)", typeText:"Calendar!" } diff --git a/idea/testData/completion/smart/NoExtensionMethodFromClassObject.kt b/idea/testData/completion/smart/NoExtensionMethodFromClassObject.kt index e7ed76857cc..3f1dd895184 100644 --- a/idea/testData/completion/smart/NoExtensionMethodFromClassObject.kt +++ b/idea/testData/completion/smart/NoExtensionMethodFromClassObject.kt @@ -10,4 +10,4 @@ fun foo(): X { } // ABSENT: f -// EXIST: { lookupString:"g", itemText:"X.g()" } +// EXIST: { lookupString:"g", itemText:"X.g", tailText:"() ()" } diff --git a/idea/testData/completion/smart/SAMExpected1.kt b/idea/testData/completion/smart/SAMExpected1.kt index 3e8141be7d2..29d4eeacf05 100644 --- a/idea/testData/completion/smart/SAMExpected1.kt +++ b/idea/testData/completion/smart/SAMExpected1.kt @@ -1,3 +1,3 @@ var a : Runnable = -// EXIST: {"lookupString":"Runnable", "tailText":"", "typeText":"Runnable", "itemText":"Runnable(function: () -> Unit)"} +// EXIST: {"lookupString":"Runnable", "itemText":"Runnable", "tailText":"(function: () -> Unit)", "typeText":"Runnable"} diff --git a/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java b/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java index f50f7593006..c441aeed235 100644 --- a/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java +++ b/idea/tests/org/jetbrains/jet/completion/ExpectedCompletionUtils.java @@ -20,6 +20,7 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; +import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellij.codeInsight.lookup.LookupElement; @@ -75,7 +76,10 @@ public class ExpectedCompletionUtils { if (!validKeys.contains(key)) { throw new RuntimeException("Invalid json property '" + key + "'"); } - map.put(key, entry.getValue().getAsString()); + JsonElement value = entry.getValue(); + if (!(value instanceof JsonNull)) { + map.put(key, value.getAsString()); + } } } diff --git a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java index b39fe903384..3ce0c79770f 100644 --- a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java @@ -298,6 +298,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes doTest(fileName); } + @TestMetadata("HigherOrderFunction2.kt") + public void testHigherOrderFunction2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/HigherOrderFunction2.kt"); + doTest(fileName); + } + @TestMetadata("ImportedEnumMembers.kt") public void testImportedEnumMembers() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/ImportedEnumMembers.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java index 7da7a806e8d..47e3e143f72 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java @@ -298,6 +298,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT doTest(fileName); } + @TestMetadata("HigherOrderFunction2.kt") + public void testHigherOrderFunction2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/HigherOrderFunction2.kt"); + doTest(fileName); + } + @TestMetadata("ImportedEnumMembers.kt") public void testImportedEnumMembers() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/ImportedEnumMembers.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt index f503ccb5776..c95d37c6458 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt +++ b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt @@ -84,11 +84,11 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){ fun testHigherOrderFunctionWithArg() = doTest(2, "filterNot", null, '\n') - fun testHigherOrderFunctionWithArgs1() = doTest(1, "foo", "foo { (String, Char) -> ... }", null, '\n') + fun testHigherOrderFunctionWithArgs1() = doTest(1, "foo", "foo", " { (String, Char) -> ... }", '\n') - fun testHigherOrderFunctionWithArgs2() = doTest(1, "foo", "foo(p: (String, Char) -> Boolean)", null, '\n') + fun testHigherOrderFunctionWithArgs2() = doTest(1, "foo", "foo", "(p: (String, Char) -> Boolean)", '\n') - fun testHigherOrderFunctionWithArgs3() = doTest(1, "foo", "foo { (String, Char) -> ... }", null, '\n') + fun testHigherOrderFunctionWithArgs3() = doTest(1, "foo", "foo", " { (String, Char) -> ... }", '\n') fun testForceParenthesisForTabChar() = doTest(0, "some", null, '\t') @@ -161,7 +161,7 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){ fun testTypeArgOfSuper() = doTest(1, "X", null, '\n') fun testKeywordClassName() = doTest(1, "class", null, '\n') - fun testKeywordFunctionName() = doTest(1, "fun", "fun()", null, '\n') + fun testKeywordFunctionName() = doTest(1, "fun", "fun", "()", '\n') fun testInfixCall() = doTest(1, "to", null, null, '\n') fun testInfixCallOnSpace() = doTest(1, "to", null, null, ' ')