From f3bb3e9c6eea55508472e562b331f1d286f3b3fd Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 18 Apr 2016 17:28:39 +0300 Subject: [PATCH] KT-11912 String interpolation is not converted to ${} form when accessing this.property #KT-11912 Fixed --- .../kotlin/idea/completion/KotlinCompletionContributor.kt | 3 +-- .../testData/handlers/basic/stringTemplate/AfterThisDot.kt | 6 ++++++ .../handlers/basic/stringTemplate/AfterThisDot.kt.after | 6 ++++++ .../test/handlers/BasicCompletionHandlerTestGenerated.java | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt create mode 100644 idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt.after diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 5f60e322182..34e62d27bec 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -343,9 +343,8 @@ class KotlinCompletionContributor : CompletionContributor() { assert(startOffset > 1 && document.charsSequence[startOffset - 1] == '.') val token = context.file.findElementAt(startOffset - 2)!! - assert(token.node.elementType == KtTokens.IDENTIFIER) + assert(token.node.elementType == KtTokens.IDENTIFIER || token.node.elementType == KtTokens.THIS_KEYWORD) val nameRef = token.parent as KtNameReferenceExpression - assert(nameRef.parent is KtSimpleNameStringTemplateEntry) document.insertString(nameRef.startOffset, "{") diff --git a/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt b/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt new file mode 100644 index 00000000000..e71d19566e8 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt @@ -0,0 +1,6 @@ +fun String.foo() { + val s = "$this." +} + +// ELEMENT: equals +// TAIL_TEXT: "(other: Any?)" \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt.after b/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt.after new file mode 100644 index 00000000000..2830314b149 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt.after @@ -0,0 +1,6 @@ +fun String.foo() { + val s = "${this.equals()}" +} + +// ELEMENT: equals +// TAIL_TEXT: "(other: Any?)" \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java index 213111aa6b2..2989d2ea1e0 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java @@ -672,6 +672,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion doTest(fileName); } + @TestMetadata("AfterThisDot.kt") + public void testAfterThisDot() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt"); + doTest(fileName); + } + public void testAllFilesPresentInStringTemplate() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/basic/stringTemplate"), Pattern.compile("^(.+)\\.kt$"), true); }