diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/ThisItems.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/ThisItems.kt index 165d0093627..d2942e71be9 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/ThisItems.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/ThisItems.kt @@ -22,9 +22,6 @@ import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor import com.intellij.codeInsight.lookup.LookupElementBuilder import org.jetbrains.jet.renderer.DescriptorRenderer import org.jetbrains.jet.lang.psi.JetFunctionLiteral -import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression -import org.jetbrains.jet.lang.psi.JetObjectDeclaration -import org.jetbrains.jet.lang.psi.JetObjectLiteralExpression import org.jetbrains.jet.lang.psi.JetValueArgument import org.jetbrains.jet.lang.psi.JetValueArgumentList import org.jetbrains.jet.lang.psi.JetCallExpression @@ -33,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.plugin.completion.ExpectedInfo import org.jetbrains.jet.plugin.util.makeNotNullable import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils +import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression class ThisItems(val bindingContext: BindingContext) { public fun addToCollection(collection: MutableCollection, context: JetExpression, expectedInfos: Collection) { @@ -65,20 +63,16 @@ class ThisItems(val bindingContext: BindingContext) { val descriptor = receiver.getContainingDeclaration() val name = descriptor.getName() if (!name.isSpecial()) { - return DescriptorRenderer.SOURCE_CODE.renderName(name) + return name.asString() } - val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) - val expression = when (psiElement) { - is JetFunctionLiteral -> psiElement.getParent() as? JetFunctionLiteralExpression - is JetObjectDeclaration -> psiElement.getParent() as? JetObjectLiteralExpression - else -> null - } - return ((((expression?.getParent() as? JetValueArgument) - ?.getParent() as? JetValueArgumentList) - ?.getParent() as? JetCallExpression) - ?.getCalleeExpression() as? JetSimpleNameExpression) - ?.getReferencedName() + val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral + return (((((functionLiteral?.getParent() as? JetFunctionLiteralExpression) + ?.getParent() as? JetValueArgument) + ?.getParent() as? JetValueArgumentList) + ?.getParent() as? JetCallExpression) + ?.getCalleeExpression() as? JetSimpleNameExpression) + ?.getReferencedName() } } \ No newline at end of file diff --git a/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt new file mode 100644 index 00000000000..8b870fc5136 --- /dev/null +++ b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt @@ -0,0 +1,8 @@ +class `this` { + fun String.foo(){ + val foo: `this` = + } +} + +// ELEMENT: "this@this" + diff --git a/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt.after b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt.after new file mode 100644 index 00000000000..02867858897 --- /dev/null +++ b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt.after @@ -0,0 +1,8 @@ +class `this` { + fun String.foo(){ + val foo: `this` = this@this + } +} + +// ELEMENT: "this@this" + diff --git a/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt new file mode 100644 index 00000000000..b52b0df4d49 --- /dev/null +++ b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt @@ -0,0 +1,12 @@ +fun `fun`(handler: String.() -> Unit){} +fun bar(handler: Int.() -> Unit){} + +fun foo(){ + `fun`({ + bar({ + val s: String = + }) + }) +} + +// ELEMENT: this@fun diff --git a/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt.after b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt.after new file mode 100644 index 00000000000..101edc41195 --- /dev/null +++ b/idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt.after @@ -0,0 +1,12 @@ +fun `fun`(handler: String.() -> Unit){} +fun bar(handler: Int.() -> Unit){} + +fun foo(){ + `fun`({ + bar({ + val s: String = this@fun + }) + }) +} + +// ELEMENT: this@fun diff --git a/idea/testData/completion/smart/QualifiedThisOfAnonymousObject.kt b/idea/testData/completion/smart/NoQualifiedThisOfAnonymousObject.kt similarity index 90% rename from idea/testData/completion/smart/QualifiedThisOfAnonymousObject.kt rename to idea/testData/completion/smart/NoQualifiedThisOfAnonymousObject.kt index 1a87fd07af0..7a664426cf6 100644 --- a/idea/testData/completion/smart/QualifiedThisOfAnonymousObject.kt +++ b/idea/testData/completion/smart/NoQualifiedThisOfAnonymousObject.kt @@ -12,4 +12,4 @@ fun bar() { }) } -// EXIST: this@foo +// ABSENT: this@foo diff --git a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java index f51b640401c..4964db3334c 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java @@ -388,6 +388,11 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest("idea/testData/completion/smart/NoPrivateOverload.kt"); } + @TestMetadata("NoQualifiedThisOfAnonymousObject.kt") + public void testNoQualifiedThisOfAnonymousObject() throws Exception { + doTest("idea/testData/completion/smart/NoQualifiedThisOfAnonymousObject.kt"); + } + @TestMetadata("NoSillyAssignment.kt") public void testNoSillyAssignment() throws Exception { doTest("idea/testData/completion/smart/NoSillyAssignment.kt"); @@ -463,11 +468,6 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest("idea/testData/completion/smart/QualifiedThis.kt"); } - @TestMetadata("QualifiedThisOfAnonymousObject.kt") - public void testQualifiedThisOfAnonymousObject() throws Exception { - doTest("idea/testData/completion/smart/QualifiedThisOfAnonymousObject.kt"); - } - @TestMetadata("QualifiedThisOfExtensionFunction.kt") public void testQualifiedThisOfExtensionFunction() throws Exception { doTest("idea/testData/completion/smart/QualifiedThisOfExtensionFunction.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java index 8fc95a9646d..de65a380113 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/SmartCompletionHandlerTestGenerated.java @@ -383,6 +383,16 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion doTest("idea/testData/completion/handlers/smart/ObjectFromType.kt"); } + @TestMetadata("QualifiedThisKeywordName1.kt") + public void testQualifiedThisKeywordName1() throws Exception { + doTest("idea/testData/completion/handlers/smart/QualifiedThisKeywordName1.kt"); + } + + @TestMetadata("QualifiedThisKeywordName2.kt") + public void testQualifiedThisKeywordName2() throws Exception { + doTest("idea/testData/completion/handlers/smart/QualifiedThisKeywordName2.kt"); + } + @TestMetadata("SAMExpected1.kt") public void testSAMExpected1() throws Exception { doTest("idea/testData/completion/handlers/smart/SAMExpected1.kt");