diff --git a/ChangeLog.md b/ChangeLog.md
index bb21d220e9a..0c05affd95b 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -237,6 +237,8 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-13726`](https://youtrack.jetbrains.com/issue/KT-13726) Move: Fix bogus conflicts due to references resolving to wrong library version
- [`KT-14114`](https://youtrack.jetbrains.com/issue/KT-14114) Move: Fix exception on moving Kotlin file without declarations
- [`KT-14157`](https://youtrack.jetbrains.com/issue/KT-14157) Rename: Rename do-while loop variables in the loop condition
+- [`KT-14128`](https://youtrack.jetbrains.com/issue/KT-14128), [`KT-13862`](https://youtrack.jetbrains.com/issue/KT-13862) Rename: Use qualified class name when looking for occurrences in non-code files
+- [`KT-6199`](https://youtrack.jetbrains.com/issue/KT-6199) Rename: Replace non-code class occurrences with new qualified name
##### New features
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index b3a8e1ea4ec..56a953c364b 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -546,7 +546,11 @@
-
+
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinNonCodeSearchElementDescriptionProvider.kt b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinNonCodeSearchElementDescriptionProvider.kt
new file mode 100644
index 00000000000..9af833be0e1
--- /dev/null
+++ b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinNonCodeSearchElementDescriptionProvider.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.kotlin.idea.findUsages
+
+import com.intellij.psi.ElementDescriptionLocation
+import com.intellij.psi.ElementDescriptionProvider
+import com.intellij.psi.PsiElement
+import com.intellij.refactoring.util.NonCodeSearchDescriptionLocation
+import org.jetbrains.kotlin.asJava.namedUnwrappedElement
+import org.jetbrains.kotlin.psi.KtClassOrObject
+
+class KotlinNonCodeSearchElementDescriptionProvider : ElementDescriptionProvider {
+ override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
+ if (location !is NonCodeSearchDescriptionLocation) return null
+ val declaration = element.namedUnwrappedElement as? KtClassOrObject ?: return null
+ return if (location.isNonJava) (declaration.fqName?.asString() ?: declaration.name) else declaration.name
+ }
+}
diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt
index 240cd27fab7..9bd5479ed00 100644
--- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt
@@ -17,15 +17,17 @@
package org.jetbrains.kotlin.idea.refactoring.rename
import com.intellij.openapi.editor.Editor
+import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReference
+import com.intellij.psi.util.PsiUtilCore
import com.intellij.refactoring.JavaRefactoringSettings
import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.refactoring.rename.RenamePsiElementProcessor
import com.intellij.usageView.UsageInfo
import org.jetbrains.kotlin.asJava.classes.KtLightClass
-import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
+import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -77,6 +79,17 @@ class RenameKotlinClassProcessor : RenameKotlinPsiProcessor() {
}
}
+ override fun getQualifiedNameAfterRename(element: PsiElement, newName: String?, nonJava: Boolean): String? {
+ if (!nonJava) return newName
+
+ val qualifiedName = when (element) {
+ is KtClassOrObject -> element.fqName?.asString() ?: element.name
+ is PsiClass -> element.qualifiedName ?: element.name
+ else -> return null
+ }
+ return PsiUtilCore.getQualifiedNameAfterRename(qualifiedName, newName)
+ }
+
override fun findReferences(element: PsiElement): Collection {
if (element is KtObjectDeclaration && element.isCompanion()) {
return super.findReferences(element).filter { !it.isCompanionObjectClassReference() }
diff --git a/idea/testData/refactoring/rename/classUsagesInTextFiles/after/dummy.txt b/idea/testData/refactoring/rename/classUsagesInTextFiles/after/dummy.txt
new file mode 100644
index 00000000000..3005af07fbc
--- /dev/null
+++ b/idea/testData/refactoring/rename/classUsagesInTextFiles/after/dummy.txt
@@ -0,0 +1,3 @@
+C
+A.B.C
+test.A.B.D
\ No newline at end of file
diff --git a/idea/testData/refactoring/rename/classUsagesInTextFiles/after/test/test.kt b/idea/testData/refactoring/rename/classUsagesInTextFiles/after/test/test.kt
new file mode 100644
index 00000000000..ae2d3432a71
--- /dev/null
+++ b/idea/testData/refactoring/rename/classUsagesInTextFiles/after/test/test.kt
@@ -0,0 +1,9 @@
+package test
+
+class A {
+ private class B {
+ class D {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/refactoring/rename/classUsagesInTextFiles/before/dummy.txt b/idea/testData/refactoring/rename/classUsagesInTextFiles/before/dummy.txt
new file mode 100644
index 00000000000..c8afaf7c748
--- /dev/null
+++ b/idea/testData/refactoring/rename/classUsagesInTextFiles/before/dummy.txt
@@ -0,0 +1,3 @@
+C
+A.B.C
+test.A.B.C
\ No newline at end of file
diff --git a/idea/testData/refactoring/rename/classUsagesInTextFiles/before/test/test.kt b/idea/testData/refactoring/rename/classUsagesInTextFiles/before/test/test.kt
new file mode 100644
index 00000000000..b523c43b6e3
--- /dev/null
+++ b/idea/testData/refactoring/rename/classUsagesInTextFiles/before/test/test.kt
@@ -0,0 +1,9 @@
+package test
+
+class A {
+ private class B {
+ class /*rename*/C {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/refactoring/rename/classUsagesInTextFiles/classUsagesInTextFiles.test b/idea/testData/refactoring/rename/classUsagesInTextFiles/classUsagesInTextFiles.test
new file mode 100644
index 00000000000..4d970dd6179
--- /dev/null
+++ b/idea/testData/refactoring/rename/classUsagesInTextFiles/classUsagesInTextFiles.test
@@ -0,0 +1,6 @@
+{
+ "type": "MARKED_ELEMENT",
+ "mainFile": "test/test.kt",
+ "newName": "D",
+ "withRuntime": "true"
+}
\ 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 492c5e3082b..82c721b2ad1 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java
@@ -167,6 +167,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
+ @TestMetadata("classUsagesInTextFiles/classUsagesInTextFiles.test")
+ public void testClassUsagesInTextFiles_ClassUsagesInTextFiles() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/classUsagesInTextFiles/classUsagesInTextFiles.test");
+ doTest(fileName);
+ }
+
@TestMetadata("companionObject/companionObject.test")
public void testCompanionObject_CompanionObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/companionObject/companionObject.test");