Completion of this@...: supported labeled function literals

This commit is contained in:
Valentin Kipyatkov
2014-12-26 14:09:04 +03:00
parent 05be100f53
commit 39a5486db8
4 changed files with 36 additions and 8 deletions
@@ -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
}
}
@@ -0,0 +1,14 @@
fun foo(): String.() -> Unit {
return (@label {
f {
<caret>
}
})
}
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" }
@@ -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");
@@ -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;