Rename: Fix exception on property rename preview

(cherry picked from commit 7b54ad0)
This commit is contained in:
Alexey Sedunov
2016-07-13 16:52:23 +03:00
parent 1a13c21377
commit e1f58c554d
3 changed files with 11 additions and 4 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.refactoring.rename.RenameJavaSyntheticPropertyHandler
import org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinPropertyProcessor
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -52,6 +53,7 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider {
is KtDestructuringDeclarationEntry -> "variable"
is RenameJavaSyntheticPropertyHandler.SyntheticPropertyWrapper -> "property"
is KtLightClassForFacade -> "facade class"
is RenameKotlinPropertyProcessor.PropertyMethodWrapper -> "property accessor"
else -> null
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.refactoring.rename
import com.intellij.navigation.NavigationItem
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.ui.Messages
@@ -249,6 +250,12 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
return declarationToRename
}
class PropertyMethodWrapper(val propertyMethod: PsiMethod) : PsiNamedElement by propertyMethod, NavigationItem by propertyMethod {
override fun getName() = propertyMethod.name
override fun setName(name: String) = this
override fun copy() = this
}
override fun prepareRenaming(element: PsiElement, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
super.prepareRenaming(element, newName, allRenames, scope)
@@ -281,10 +288,7 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
for (propertyMethod in propertyMethods) {
if (element is KtDeclaration && newPropertyName != null) {
val wrapper = object : PsiNamedElement by propertyMethod {
override fun setName(name: String) = this
override fun copy() = this
}
val wrapper = PropertyMethodWrapper(propertyMethod)
when {
JvmAbi.isGetterName(propertyMethod.name) && getterJvmName == null ->
allRenames[wrapper] = JvmAbi.getterName(newPropertyName)