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:
@@ -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"/>
|
||||
|
||||
+32
@@ -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
|
||||
}
|
||||
}
|
||||
+14
-1
@@ -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() }
|
||||
|
||||
Reference in New Issue
Block a user