Fixed keywords after 'this@' completion + fixed implementation of JetExpressionWithLabel.getLabelName()

This commit is contained in:
Valentin Kipyatkov
2015-05-20 11:46:16 +03:00
parent 2a5ca095ee
commit a6f76bbf76
13 changed files with 56 additions and 28 deletions
@@ -16,9 +16,10 @@
package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
public fun JetFunctionLiteral.findLabelAndCall(): Pair<String?, JetCallExpression?> {
public fun JetFunctionLiteral.findLabelAndCall(): Pair<Name?, JetCallExpression?> {
val literalParent = (this.getParent() as JetFunctionLiteralExpression).getParent()
fun JetValueArgument.callExpression(): JetCallExpression? {
@@ -29,12 +30,12 @@ public fun JetFunctionLiteral.findLabelAndCall(): Pair<String?, JetCallExpressio
when (literalParent) {
is JetLabeledExpression -> {
val callExpression = (literalParent.getParent() as? JetValueArgument)?.callExpression()
return Pair(literalParent.getLabelName(), callExpression)
return Pair(literalParent.getLabelNameAsName(), callExpression)
}
is JetValueArgument -> {
val callExpression = literalParent.callExpression()
val label = (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName()
val label = (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedNameAsName()
return Pair(label, callExpression)
}
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.renderName
import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.psi.JetFunctionLiteral
import org.jetbrains.kotlin.psi.JetPsiFactory
@@ -58,7 +60,7 @@ public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<Receiver
for ((index, receiver) in receivers.withIndex()) {
val owner = receiver.getContainingDeclaration()
val (expressionText, isImmediateThis) = if (owner in outerDeclarationsWithInstance) {
val thisWithLabel = thisQualifierName(receiver)?.let { "this@$it" }
val thisWithLabel = thisQualifierName(receiver)?.let { "this@${it.renderName()}" }
if (index == 0)
(thisWithLabel ?: "this") to true
else
@@ -83,12 +85,10 @@ public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<Receiver
return result
}
private fun thisQualifierName(receiver: ReceiverParameterDescriptor): String? {
private fun thisQualifierName(receiver: ReceiverParameterDescriptor): Name? {
val descriptor = receiver.getContainingDeclaration()
val name = descriptor.getName()
if (!name.isSpecial()) {
return name.asString()
}
if (!name.isSpecial()) return name
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral
return functionLiteral?.findLabelAndCall()?.first