From 056d8dfd9f16b02ba011c7fb59179dbf87a7aeaf Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 21 Aug 2015 16:58:15 +0200 Subject: [PATCH] correcty index escaped identifiers #KT-8846 Fixed --- .../jetbrains/kotlin/idea/search/KotlinIndexers.kt | 13 +++++++++++-- .../after/RenameKotlinMethodWithEscapedName.kt | 7 +++++++ .../before/RenameKotlinMethodWithEscapedName.kt | 7 +++++++ .../renameKotlinMethodWithEscapedName.test | 6 ++++++ .../refactoring/rename/RenameTestGenerated.java | 6 ++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/after/RenameKotlinMethodWithEscapedName.kt create mode 100644 idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/before/RenameKotlinMethodWithEscapedName.kt create mode 100644 idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt index e8f3f41d745..d2a044d758c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.ALL_SEARCHABLE_OPERATIONS import org.jetbrains.kotlin.kdoc.lexer.KDocTokens import org.jetbrains.kotlin.lexer.JetLexer import org.jetbrains.kotlin.lexer.JetTokens -import java.util.ArrayDeque +import java.util.* val KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT: Short = 0x20 @@ -66,6 +66,15 @@ class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): Bas } } + JetTokens.IDENTIFIER -> { + if (myDelegate.tokenText.startsWith("`")) { + scanWordsInToken(UsageSearchContext.IN_CODE.toInt(), false, false) + } + else { + addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt()) + } + } + in codeTokens -> addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt()) in JetTokens.STRINGS -> scanWordsInToken(UsageSearchContext.IN_STRINGS + UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true) @@ -98,7 +107,7 @@ class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): Bas class KotlinIdIndexer: LexerBasedIdIndexer() { override fun createLexer(consumer: OccurrenceConsumer): Lexer = KotlinFilterLexer(consumer) - override fun getVersion() = 2 + override fun getVersion() = 3 } class KotlinTodoIndexer: LexerBasedTodoIndexer(), IdAndToDoScannerBasedOnFilterLexer { diff --git a/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/after/RenameKotlinMethodWithEscapedName.kt b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/after/RenameKotlinMethodWithEscapedName.kt new file mode 100644 index 00000000000..dde9ca32a12 --- /dev/null +++ b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/after/RenameKotlinMethodWithEscapedName.kt @@ -0,0 +1,7 @@ +package testing.rename + +public open class C { + public fun second() = 1 + + public fun foo() = second() +} diff --git a/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/before/RenameKotlinMethodWithEscapedName.kt b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/before/RenameKotlinMethodWithEscapedName.kt new file mode 100644 index 00000000000..3d698c8c624 --- /dev/null +++ b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/before/RenameKotlinMethodWithEscapedName.kt @@ -0,0 +1,7 @@ +package testing.rename + +public open class C { + public fun `first`() = 1 + + public fun foo() = `first`() +} diff --git a/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test new file mode 100644 index 00000000000..1829212b581 --- /dev/null +++ b/idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test @@ -0,0 +1,6 @@ +{ + "type": "KOTLIN_FUNCTION", + "classId": "testing/rename/C", + "oldName": "first", + "newName": "second" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java index 73cd88ee997..e42a34d80a6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java @@ -281,6 +281,12 @@ public class RenameTestGenerated extends AbstractRenameTest { doTest(fileName); } + @TestMetadata("renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test") + public void testRenameKotlinMethodWithEscapedName_RenameKotlinMethodWithEscapedName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinMethodWithEscapedName/renameKotlinMethodWithEscapedName.test"); + doTest(fileName); + } + @TestMetadata("renameKotlinPackage/renameInOtherFile.test") public void testRenameKotlinPackage_RenameInOtherFile() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPackage/renameInOtherFile.test");