Rename: Use qualified class name when looking for occurrences in non-code files

#KT-14128 Fixed
 #KT-13862 Fixed
 #KT-6199 Fixed
This commit is contained in:
Alexey Sedunov
2016-10-04 18:34:57 +03:00
parent da1178fe0c
commit fad4944eee
10 changed files with 89 additions and 2 deletions
+2
View File
@@ -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
+5 -1
View File
@@ -546,7 +546,11 @@
<gotoTargetRendererProvider id="JetGotoTargetRenderProvider" implementation="org.jetbrains.kotlin.idea.KotlinGotoTargetRenderProvider"
order="first"/>
<elementDescriptionProvider implementation="org.jetbrains.kotlin.idea.findUsages.KotlinElementDescriptionProvider" order="first"/>
<elementDescriptionProvider
implementation="org.jetbrains.kotlin.idea.findUsages.KotlinElementDescriptionProvider"
order="first"/>
<elementDescriptionProvider
implementation="org.jetbrains.kotlin.idea.findUsages.KotlinNonCodeSearchElementDescriptionProvider"/>
<highlightUsagesHandlerFactory implementation="org.jetbrains.kotlin.idea.highlighter.KotlinHighlightExitPointsHandlerFactory"/>
<findUsagesHandlerFactory implementation="org.jetbrains.kotlin.idea.findUsages.KotlinFindUsagesHandlerFactory"/>
<usageTypeProvider implementation="org.jetbrains.kotlin.idea.findUsages.KotlinUsageTypeProvider"/>
@@ -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
}
}
@@ -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<PsiReference> {
if (element is KtObjectDeclaration && element.isCompanion()) {
return super.findReferences(element).filter { !it.isCompanionObjectClassReference() }
@@ -0,0 +1,3 @@
C
A.B.C
test.A.B.D
@@ -0,0 +1,9 @@
package test
class A {
private class B {
class D {
}
}
}
@@ -0,0 +1,3 @@
C
A.B.C
test.A.B.C
@@ -0,0 +1,9 @@
package test
class A {
private class B {
class /*rename*/C {
}
}
}
@@ -0,0 +1,6 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test/test.kt",
"newName": "D",
"withRuntime": "true"
}
@@ -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");