Rename: Do not search text occurrences of local declarations

#KT-23838 Fixed
This commit is contained in:
Alexey Sedunov
2018-04-17 20:21:28 +03:00
parent f8111c9f23
commit 4e3c1e9f56
5 changed files with 28 additions and 0 deletions
@@ -59,6 +59,12 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() {
return references
}
override fun getElementToSearchInStringsAndComments(element: PsiElement): PsiElement? {
val unwrapped = element?.unwrapped ?: return null
if ((unwrapped is KtDeclaration) && KtPsiUtil.isLocal(unwrapped as KtDeclaration)) return null
return element
}
override fun getQualifiedNameAfterRename(element: PsiElement, newName: String, nonJava: Boolean): String? {
if (!nonJava) return newName
@@ -59,6 +59,12 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() {
return references
}
override fun getElementToSearchInStringsAndComments(element: PsiElement?): PsiElement? {
val unwrapped = element?.unwrapped ?: return null
if ((unwrapped is KtDeclaration) && KtPsiUtil.isLocal(unwrapped as KtDeclaration)) return null
return element
}
override fun getQualifiedNameAfterRename(element: PsiElement, newName: String?, nonJava: Boolean): String? {
if (!nonJava) return newName
@@ -0,0 +1,6 @@
fun foo(x: Int) {
val <caret>y = x + 1
val z = y + 1
// y
val s = "y"
}
@@ -0,0 +1,6 @@
fun foo(x: Int) {
val w = x + 1
val z = w + 1
// y
val s = "y"
}
@@ -174,6 +174,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
doTestMemberInplaceRename("`object`")
}
fun testNoTextUsagesForLocalVar() {
doTestMemberInplaceRename("w")
}
private fun doTestImplicitLambdaParameter(newName: String) {
configureByFile(getTestName(false) + ".kt")