Rename: Rename overridden property and all its accessors on attempt to rename overriding accessor in Java code

#KT-4791 Fixed
(cherry picked from commit 29e450e)
This commit is contained in:
Alexey Sedunov
2016-06-14 17:04:38 +03:00
parent 4c447d0580
commit d0a3732c94
14 changed files with 107 additions and 3 deletions
@@ -38,7 +38,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
class KotlinElementDescriptionProvider : ElementDescriptionProvider {
override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
val targetElement = element.unwrapped ?: element
val shouldUnwrap = location !is UsageViewShortNameLocation && location !is UsageViewLongNameLocation
val targetElement = if (shouldUnwrap) element.unwrapped ?: element else element
fun elementKind() = when (targetElement) {
is KtClass -> if (targetElement.isInterface()) "interface" else "class"
@@ -65,7 +66,7 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider {
if (targetElement !is PsiNamedElement || targetElement.language != KotlinLanguage.INSTANCE) return null
return when(location) {
is UsageViewTypeLocation -> elementKind()
is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.getName()
is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.name
is RefactoringDescriptionLocation -> {
val kind = elementKind() ?: return null
val descriptor = targetDescriptor() ?: return null
@@ -243,8 +243,10 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
else -> throw IllegalStateException("Can't be for element $element there because of canProcessElement()")
}
val newPropertyName = if (newName != null && element is KtLightMethod) propertyNameByAccessor(newName, element) else newName
for (propertyMethod in propertyMethods) {
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newName, allRenames, scope)
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newPropertyName, allRenames, scope)
}
}