Completion: no qualified this for anonymous object + no keyword escaping for qualified this
This commit is contained in:
@@ -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<LookupElement>, context: JetExpression, expectedInfos: Collection<ExpectedInfo>) {
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class `this` {
|
||||
fun String.foo(){
|
||||
val foo: `this` = <caret>
|
||||
}
|
||||
}
|
||||
|
||||
// ELEMENT: "this@this"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class `this` {
|
||||
fun String.foo(){
|
||||
val foo: `this` = this@this<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// ELEMENT: "this@this"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fun `fun`(handler: String.() -> Unit){}
|
||||
fun bar(handler: Int.() -> Unit){}
|
||||
|
||||
fun foo(){
|
||||
`fun`({
|
||||
bar({
|
||||
val s: String = <caret>
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ELEMENT: this@fun
|
||||
@@ -0,0 +1,12 @@
|
||||
fun `fun`(handler: String.() -> Unit){}
|
||||
fun bar(handler: Int.() -> Unit){}
|
||||
|
||||
fun foo(){
|
||||
`fun`({
|
||||
bar({
|
||||
val s: String = this@fun<caret>
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ELEMENT: this@fun
|
||||
+1
-1
@@ -12,4 +12,4 @@ fun bar() {
|
||||
})
|
||||
}
|
||||
|
||||
// EXIST: this@foo
|
||||
// ABSENT: this@foo
|
||||
@@ -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");
|
||||
|
||||
+10
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user