From 39a5486db80bc1987eb1c83d281c73b6bb7eea71 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 26 Dec 2014 14:09:04 +0300 Subject: [PATCH] Completion of this@...: supported labeled function literals --- .../jet/plugin/completion/CompletionUtils.kt | 22 +++++++++++++------ .../completion/keywords/LabeledLambdaThis.kt | 14 ++++++++++++ .../KeywordCompletionTestGenerated.java | 7 +++++- .../CompletionCharFilterTestGenerated.java | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 idea/testData/completion/keywords/LabeledLambdaThis.kt diff --git a/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt b/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt index 2eea6dcd3be..316c65fc6c1 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/CompletionUtils.kt @@ -57,6 +57,7 @@ import org.jetbrains.jet.plugin.util.getImplicitReceiversWithInstance import com.intellij.codeInsight.lookup.LookupElementBuilder import org.jetbrains.jet.renderer.DescriptorRenderer import org.jetbrains.jet.plugin.util.FuzzyType +import org.jetbrains.jet.lang.psi.JetLabeledExpression enum class ItemPriority { MULTIPLE_ARGUMENTS_ITEM @@ -241,11 +242,18 @@ private fun thisQualifierName(receiver: ReceiverParameterDescriptor): String? { return name.asString() } - val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral - val valueArgument = (functionLiteral?.getParent() as? JetFunctionLiteralExpression) - ?.getParent() as? JetValueArgument ?: return null - val parent = valueArgument.getParent() - val callExpression = (if (parent is JetValueArgumentList) parent else valueArgument) - .getParent() as? JetCallExpression - return (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName() + val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral ?: return null + val literalParent = (functionLiteral.getParent() as JetFunctionLiteralExpression).getParent() + when (literalParent) { + is JetLabeledExpression -> return literalParent.getLabelName() + + is JetValueArgument -> { + val parent = literalParent.getParent() + val callExpression = (if (parent is JetValueArgumentList) parent else literalParent) + .getParent() as? JetCallExpression + return (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName() + } + + else -> return null + } } diff --git a/idea/testData/completion/keywords/LabeledLambdaThis.kt b/idea/testData/completion/keywords/LabeledLambdaThis.kt new file mode 100644 index 00000000000..201f1289ff4 --- /dev/null +++ b/idea/testData/completion/keywords/LabeledLambdaThis.kt @@ -0,0 +1,14 @@ +fun foo(): String.() -> Unit { + return (@label { + f { + + } + }) +} + +fun f(p: Any.() -> Unit){} + +// INVOCATION_COUNT: 1 +// EXIST: { lookupString: "this", itemText: "this", tailText: null, typeText: "Any", attributes: "bold" } +// ABSENT: "this@f" +// EXIST: { lookupString: "this@label", itemText: "this", tailText: "@label", typeText: "String", attributes: "bold" } diff --git a/idea/tests/org/jetbrains/jet/completion/KeywordCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/KeywordCompletionTestGenerated.java index 57a60fa1b97..b249dd861ca 100644 --- a/idea/tests/org/jetbrains/jet/completion/KeywordCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/KeywordCompletionTestGenerated.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.completion; import com.intellij.testFramework.TestDataPath; import org.jetbrains.jet.JUnit3RunnerWithInners; import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; import org.junit.runner.RunWith; @@ -228,6 +227,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes doTest(fileName); } + @TestMetadata("LabeledLambdaThis.kt") + public void testLabeledLambdaThis() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/LabeledLambdaThis.kt"); + doTest(fileName); + } + @TestMetadata("LineComment.kt") public void testLineComment() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/keywords/LineComment.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionCharFilterTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionCharFilterTestGenerated.java index 76065cdd80b..1c68a91f988 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionCharFilterTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionCharFilterTestGenerated.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.completion.handlers; import com.intellij.testFramework.TestDataPath; import org.jetbrains.jet.JUnit3RunnerWithInners; import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; import org.junit.runner.RunWith;