Rename: Fix renaming of backquoted property accessors

#KT-23298 Fixed
This commit is contained in:
Alexey Sedunov
2018-03-19 15:17:15 +03:00
parent 2104a0fa2b
commit 14b1bdf627
4 changed files with 14 additions and 5 deletions
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.core.getDeepestSuperDeclarations
import org.jetbrains.kotlin.idea.core.isEnumCompanionPropertyWithEntryConflict
import org.jetbrains.kotlin.idea.core.unquote
import org.jetbrains.kotlin.idea.refactoring.checkSuperMethodsWithPopup
import org.jetbrains.kotlin.idea.refactoring.dropOverrideKeywordIfNecessary
import org.jetbrains.kotlin.idea.references.KtDestructuringDeclarationReference
@@ -57,6 +58,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.findPropertyByName
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DataClassDescriptorResolver
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
@@ -342,18 +344,19 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
}
override tailrec fun renameElement(element: PsiElement, newName: String, usages: Array<UsageInfo>, listener: RefactoringElementListener?) {
val newNameUnquoted = newName.unquote()
if (element is KtLightMethod) {
if (element.modifierList.findAnnotation(DescriptorUtils.JVM_NAME.asString()) != null) {
return super.renameElement(element, newName, usages, listener)
}
val origin = element.kotlinOrigin
val newPropertyName = propertyNameByAccessor(newName, element)
val newPropertyName = propertyNameByAccessor(newNameUnquoted, element)
// Kotlin references to Kotlin property should not use accessor name
if (newPropertyName != null && (origin is KtProperty || origin is KtParameter)) {
val (ktUsages, otherUsages) = usages.partition { it.reference is KtSimpleNameReference }
super.renameElement(element, newName, otherUsages.toTypedArray(), listener)
renameElement(origin, newPropertyName, ktUsages.toTypedArray(), listener)
renameElement(origin, newPropertyName.quoteIfNeeded(), ktUsages.toTypedArray(), listener)
return
}
}
@@ -367,7 +370,7 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
val oldGetterName = JvmAbi.getterName(name)
val oldSetterName = JvmAbi.setterName(name)
if (isEnumCompanionPropertyWithEntryConflict(element, newName)) {
if (isEnumCompanionPropertyWithEntryConflict(element, newNameUnquoted)) {
for ((i, usage) in usages.withIndex()) {
if (usage !is MoveRenameUsageInfo) continue
val ref = usage.reference ?: continue
@@ -398,11 +401,11 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
}
}
super.renameElement(element, JvmAbi.setterName(newName),
super.renameElement(element, JvmAbi.setterName(newNameUnquoted).quoteIfNeeded(),
refKindUsages[UsageKind.SETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(),
null)
super.renameElement(element, JvmAbi.getterName(newName),
super.renameElement(element, JvmAbi.getterName(newNameUnquoted).quoteIfNeeded(),
refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(),
null)
@@ -0,0 +1 @@
val <caret>`in` = 42
@@ -0,0 +1 @@
val `object` = 42
@@ -170,6 +170,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
doTestMemberInplaceRename("LocalClassB")
}
fun testBacktickedWithAccessors() {
doTestMemberInplaceRename("`object`")
}
private fun doTestImplicitLambdaParameter(newName: String) {
configureByFile(getTestName(false) + ".kt")