diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt index 236909d5ea7..6e1bc177eac 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt @@ -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, 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(), null) - super.renameElement(element, JvmAbi.getterName(newName), + super.renameElement(element, JvmAbi.getterName(newNameUnquoted).quoteIfNeeded(), refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf(), null) diff --git a/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt b/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt new file mode 100644 index 00000000000..504667f439e --- /dev/null +++ b/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt @@ -0,0 +1 @@ +val `in` = 42 \ No newline at end of file diff --git a/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt.after b/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt.after new file mode 100644 index 00000000000..98eb2ac0fe1 --- /dev/null +++ b/idea/testData/refactoring/rename/inplace/BacktickedWithAccessors.kt.after @@ -0,0 +1 @@ +val `object` = 42 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt index 32bd7f2f30c..6f446b69947 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt @@ -170,6 +170,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { doTestMemberInplaceRename("LocalClassB") } + fun testBacktickedWithAccessors() { + doTestMemberInplaceRename("`object`") + } + private fun doTestImplicitLambdaParameter(newName: String) { configureByFile(getTestName(false) + ".kt")