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
+1
View File
@@ -132,6 +132,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-12294`](https://youtrack.jetbrains.com/issue/KT-12294) Introduce Property: Fix extraction of expressions referring to primary constructor parameters
- [`KT-12413`](https://youtrack.jetbrains.com/issue/KT-12413) Change Signature: Fix bogus warning about unresolved type parameters/invalid functional type replacement
- [`KT-12084`](https://youtrack.jetbrains.com/issue/KT-12084) Introduce Property: Do not skip outer classes if extractable expression is contained in object literal
- [`KT-13082`](https://youtrack.jetbrains.com/issue/KT-13082) Rename: Fix exception on property rename preview
###### New features
@@ -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)