Fixed keywords after 'this@' completion + fixed implementation of JetExpressionWithLabel.getLabelName()
This commit is contained in:
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.findLabelAndCall
|
||||
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstanceToExpression
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.renderName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
@@ -209,7 +210,7 @@ fun thisExpressionItems(bindingContext: BindingContext, position: JetExpression,
|
||||
val thisType = receiver.getType()
|
||||
val fuzzyType = FuzzyType(thisType, listOf())
|
||||
|
||||
fun createLookupElement() = createKeywordWithLabelElement("this", expression.getLabelName())
|
||||
fun createLookupElement() = createKeywordWithLabelElement("this", expression.getLabelNameAsName())
|
||||
.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(thisType))
|
||||
|
||||
result.add(ThisItemInfo(::createLookupElement, fuzzyType))
|
||||
@@ -249,7 +250,7 @@ private fun returnsUnit(declaration: JetDeclarationWithBody, bindingContext: Bin
|
||||
return KotlinBuiltIns.isUnit(returnType)
|
||||
}
|
||||
|
||||
private fun createKeywordWithLabelElement(keyword: String, label: String?, addSpace: Boolean): LookupElement {
|
||||
private fun createKeywordWithLabelElement(keyword: String, label: Name?, addSpace: Boolean): LookupElement {
|
||||
val element = createKeywordWithLabelElement(keyword, label)
|
||||
return if (addSpace) {
|
||||
object: LookupElementDecorator<LookupElement>(element) {
|
||||
@@ -263,12 +264,13 @@ private fun createKeywordWithLabelElement(keyword: String, label: String?, addSp
|
||||
}
|
||||
}
|
||||
|
||||
private fun createKeywordWithLabelElement(keyword: String, label: String?): LookupElementBuilder {
|
||||
var element = LookupElementBuilder.create(KeywordLookupObject, if (label == null) keyword else "$keyword@$label")
|
||||
private fun createKeywordWithLabelElement(keyword: String, label: Name?): LookupElementBuilder {
|
||||
val labelInCode = label?.renderName()
|
||||
var element = LookupElementBuilder.create(KeywordLookupObject, if (label == null) keyword else "$keyword@$labelInCode")
|
||||
element = element.withPresentableText(keyword)
|
||||
element = element.withBoldness(true)
|
||||
if (label != null) {
|
||||
element = element.withTailText("@$label", false)
|
||||
element = element.withTailText("@$labelInCode", false)
|
||||
}
|
||||
return element
|
||||
}
|
||||
@@ -284,7 +286,7 @@ fun breakOrContinueExpressionItems(position: JetElement, breakOrContinue: String
|
||||
result.add(createKeywordWithLabelElement(breakOrContinue, null))
|
||||
}
|
||||
|
||||
val label = (parent.getParent() as? JetLabeledExpression)?.getLabelName()
|
||||
val label = (parent.getParent() as? JetLabeledExpression)?.getLabelNameAsName()
|
||||
if (label != null) {
|
||||
result.add(createKeywordWithLabelElement(breakOrContinue, label))
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ class `this` {
|
||||
}
|
||||
}
|
||||
|
||||
// ELEMENT: "this@this"
|
||||
// ELEMENT: "this@`this`"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class `this` {
|
||||
fun String.foo(){
|
||||
val foo: `this` = this@this<caret>
|
||||
val foo: `this` = this@`this`<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// ELEMENT: "this@this"
|
||||
// ELEMENT: "this@`this`"
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ fun foo(){
|
||||
})
|
||||
}
|
||||
|
||||
// ELEMENT: this@fun
|
||||
// ELEMENT: this@`fun`
|
||||
|
||||
@@ -4,9 +4,9 @@ fun bar(handler: Int.() -> Unit){}
|
||||
fun foo(){
|
||||
`fun`({
|
||||
bar({
|
||||
val s: String = this@fun<caret>
|
||||
val s: String = this@`fun`<caret>
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ELEMENT: this@fun
|
||||
// ELEMENT: this@`fun`
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
fun foo() {
|
||||
`fun` {
|
||||
`val`({ ret<caret> })
|
||||
}
|
||||
}
|
||||
|
||||
inline fun `fun`(handler: () -> Unit){}
|
||||
inline fun `val`(handler: () -> Unit){}
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: { lookupString: "return", itemText: "return", tailText: null, attributes: "bold" }
|
||||
// EXIST: { lookupString: "return@`fun`", itemText: "return", tailText: "@`fun`", attributes: "bold" }
|
||||
// EXIST: { lookupString: "return@`val`", itemText: "return", tailText: "@`val`", attributes: "bold" }
|
||||
// NOTHING_ELSE: true
|
||||
+6
@@ -401,6 +401,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ReturnKeywordName.kt")
|
||||
public void testReturnKeywordName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/ReturnKeywordName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("This.kt")
|
||||
public void testThis() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/This.kt");
|
||||
|
||||
Reference in New Issue
Block a user