Rename: Search text occurrences by declaration FQ name
#KT-17949 Fixed #KT-15932 Fixed
This commit is contained in:
+2
-2
@@ -21,12 +21,12 @@ import com.intellij.psi.ElementDescriptionProvider
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.refactoring.util.NonCodeSearchDescriptionLocation
|
import com.intellij.refactoring.util.NonCodeSearchDescriptionLocation
|
||||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
|
|
||||||
class KotlinNonCodeSearchElementDescriptionProvider : ElementDescriptionProvider {
|
class KotlinNonCodeSearchElementDescriptionProvider : ElementDescriptionProvider {
|
||||||
override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
|
override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
|
||||||
if (location !is NonCodeSearchDescriptionLocation) return null
|
if (location !is NonCodeSearchDescriptionLocation) return null
|
||||||
val declaration = element.namedUnwrappedElement as? KtClassOrObject ?: return null
|
val declaration = element.namedUnwrappedElement as? KtNamedDeclaration ?: return null
|
||||||
return if (location.isNonJava) (declaration.fqName?.asString() ?: declaration.name) else declaration.name
|
return if (location.isNonJava) (declaration.fqName?.asString() ?: declaration.name) else declaration.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,17 +79,6 @@ 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> {
|
override fun findReferences(element: PsiElement): Collection<PsiReference> {
|
||||||
if (element is KtObjectDeclaration && element.isCompanion()) {
|
if (element is KtObjectDeclaration && element.isCompanion()) {
|
||||||
return super.findReferences(element).filter { !it.isCompanionObjectClassReference() }
|
return super.findReferences(element).filter { !it.isCompanionObjectClassReference() }
|
||||||
|
|||||||
@@ -17,13 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.idea.refactoring.rename
|
package org.jetbrains.kotlin.idea.refactoring.rename
|
||||||
|
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.PsiImportStaticStatement
|
|
||||||
import com.intellij.psi.PsiPolyVariantReference
|
|
||||||
import com.intellij.psi.PsiReference
|
|
||||||
import com.intellij.psi.search.SearchScope
|
import com.intellij.psi.search.SearchScope
|
||||||
import com.intellij.psi.search.searches.MethodReferencesSearch
|
import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||||
import com.intellij.psi.search.searches.ReferencesSearch
|
import com.intellij.psi.search.searches.ReferencesSearch
|
||||||
|
import com.intellij.psi.util.PsiUtilCore
|
||||||
import com.intellij.refactoring.listeners.RefactoringElementListener
|
import com.intellij.refactoring.listeners.RefactoringElementListener
|
||||||
import com.intellij.refactoring.rename.RenamePsiElementProcessor
|
import com.intellij.refactoring.rename.RenamePsiElementProcessor
|
||||||
import com.intellij.usageView.UsageInfo
|
import com.intellij.usageView.UsageInfo
|
||||||
@@ -60,6 +58,17 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() {
|
|||||||
return references
|
return references
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getQualifiedNameAfterRename(element: PsiElement, newName: String?, nonJava: Boolean): String? {
|
||||||
|
if (!nonJava) return newName
|
||||||
|
|
||||||
|
val qualifiedName = when (element) {
|
||||||
|
is KtNamedDeclaration -> element.fqName?.asString() ?: element.name
|
||||||
|
is PsiClass -> element.qualifiedName ?: element.name
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
return PsiUtilCore.getQualifiedNameAfterRename(qualifiedName, newName)
|
||||||
|
}
|
||||||
|
|
||||||
override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
||||||
if (newName == null) return
|
if (newName == null) return
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun baz() {}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
baz()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
test.A.baz
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun /*rename*/foo() {}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
test.A.foo
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test.kt",
|
||||||
|
"newName": "baz",
|
||||||
|
"searchInTextOccurrences": "true"
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val baz = 1
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
baz
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
test.A.baz
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val /*rename*/foo = 1
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
test.A.foo
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test.kt",
|
||||||
|
"newName": "baz",
|
||||||
|
"searchInTextOccurrences": "true"
|
||||||
|
}
|
||||||
@@ -198,6 +198,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("funTextOccurrences/funTextOccurrences.test")
|
||||||
|
public void testFunTextOccurrences_FunTextOccurrences() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/funTextOccurrences/funTextOccurrences.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("funWithLabeledReturns/funWithLabeledReturns.test")
|
@TestMetadata("funWithLabeledReturns/funWithLabeledReturns.test")
|
||||||
public void testFunWithLabeledReturns_FunWithLabeledReturns() throws Exception {
|
public void testFunWithLabeledReturns_FunWithLabeledReturns() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/funWithLabeledReturns/funWithLabeledReturns.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/funWithLabeledReturns/funWithLabeledReturns.test");
|
||||||
@@ -1302,6 +1308,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("valTextOccurrences/valTextOccurrences.test")
|
||||||
|
public void testValTextOccurrences_ValTextOccurrences() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/valTextOccurrences/valTextOccurrences.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("varInDoWhile/varInDoWhile.test")
|
@TestMetadata("varInDoWhile/varInDoWhile.test")
|
||||||
public void testVarInDoWhile_VarInDoWhile() throws Exception {
|
public void testVarInDoWhile_VarInDoWhile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/varInDoWhile/varInDoWhile.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/varInDoWhile/varInDoWhile.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user