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:
@@ -223,6 +223,7 @@
|
|||||||
- [`KT-8512`](https://youtrack.jetbrains.com/issue/KT-8512) Support "Rename tests" options in Rename dialog
|
- [`KT-8512`](https://youtrack.jetbrains.com/issue/KT-8512) Support "Rename tests" options in Rename dialog
|
||||||
|
|
||||||
###### Issues fixed
|
###### Issues fixed
|
||||||
|
- [`KT-4791`](https://youtrack.jetbrains.com/issue/KT-4791) Rename overridden property and all its accessors on attempt to rename overriding accessor in Java code
|
||||||
- [`KT-6363`](https://youtrack.jetbrains.com/issue/KT-6363) Do not rename ambiguous references in import directives
|
- [`KT-6363`](https://youtrack.jetbrains.com/issue/KT-6363) Do not rename ambiguous references in import directives
|
||||||
- [`KT-6663`](https://youtrack.jetbrains.com/issue/KT-6663) Fixed rename of ambiguous import reference to class/function when some referenced declarations are not changed
|
- [`KT-6663`](https://youtrack.jetbrains.com/issue/KT-6663) Fixed rename of ambiguous import reference to class/function when some referenced declarations are not changed
|
||||||
- [`KT-8541`](https://youtrack.jetbrains.com/issue/KT-8541), [`KT-8786`](https://youtrack.jetbrains.com/issue/KT-8786) Do now show 'Rename overloads' options if target function has no overloads
|
- [`KT-8541`](https://youtrack.jetbrains.com/issue/KT-8541), [`KT-8786`](https://youtrack.jetbrains.com/issue/KT-8786) Do now show 'Rename overloads' options if target function has no overloads
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
|
|
||||||
class KotlinElementDescriptionProvider : ElementDescriptionProvider {
|
class KotlinElementDescriptionProvider : ElementDescriptionProvider {
|
||||||
override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
|
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) {
|
fun elementKind() = when (targetElement) {
|
||||||
is KtClass -> if (targetElement.isInterface()) "interface" else "class"
|
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
|
if (targetElement !is PsiNamedElement || targetElement.language != KotlinLanguage.INSTANCE) return null
|
||||||
return when(location) {
|
return when(location) {
|
||||||
is UsageViewTypeLocation -> elementKind()
|
is UsageViewTypeLocation -> elementKind()
|
||||||
is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.getName()
|
is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.name
|
||||||
is RefactoringDescriptionLocation -> {
|
is RefactoringDescriptionLocation -> {
|
||||||
val kind = elementKind() ?: return null
|
val kind = elementKind() ?: return null
|
||||||
val descriptor = targetDescriptor() ?: return null
|
val descriptor = targetDescriptor() ?: return null
|
||||||
|
|||||||
+3
-1
@@ -243,8 +243,10 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
|
|||||||
else -> throw IllegalStateException("Can't be for element $element there because of canProcessElement()")
|
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) {
|
for (propertyMethod in propertyMethods) {
|
||||||
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newName, allRenames, scope)
|
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newPropertyName, allRenames, scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
var bar: Int
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usage;
|
||||||
|
|
||||||
|
import lib.Foo;
|
||||||
|
|
||||||
|
public class JUsage implements Foo {
|
||||||
|
@Override
|
||||||
|
public int getBar() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBar(int value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
var foo: Int
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usage;
|
||||||
|
|
||||||
|
import lib.Foo;
|
||||||
|
|
||||||
|
public class JUsage implements Foo {
|
||||||
|
@Override
|
||||||
|
public int /*rename*/getFoo() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFoo(int value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "usage/JUsage.java",
|
||||||
|
"newName": "getBar",
|
||||||
|
"withRuntime": "true"
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
var bar: Int
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usage;
|
||||||
|
|
||||||
|
import lib.Foo;
|
||||||
|
|
||||||
|
public class JUsage implements Foo {
|
||||||
|
@Override
|
||||||
|
public int getBar() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBar(int value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
var foo: Int
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usage;
|
||||||
|
|
||||||
|
import lib.Foo;
|
||||||
|
|
||||||
|
public class JUsage implements Foo {
|
||||||
|
@Override
|
||||||
|
public int getFoo() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void /*rename*/setFoo(int value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "usage/JUsage.java",
|
||||||
|
"newName": "setBar",
|
||||||
|
"withRuntime": "true"
|
||||||
|
}
|
||||||
@@ -863,6 +863,18 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameOverriddenPropertyViaJavaGetter/renameOverriddenPropertyViaJavaGetter.test")
|
||||||
|
public void testRenameOverriddenPropertyViaJavaGetter_RenameOverriddenPropertyViaJavaGetter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameOverriddenPropertyViaJavaGetter/renameOverriddenPropertyViaJavaGetter.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameOverriddenPropertyViaJavaSetter/renameOverriddenPropertyViaJavaSetter.test")
|
||||||
|
public void testRenameOverriddenPropertyViaJavaSetter_RenameOverriddenPropertyViaJavaSetter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameOverriddenPropertyViaJavaSetter/renameOverriddenPropertyViaJavaSetter.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("renamePlus/plus.test")
|
@TestMetadata("renamePlus/plus.test")
|
||||||
public void testRenamePlus_Plus() throws Exception {
|
public void testRenamePlus_Plus() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renamePlus/plus.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renamePlus/plus.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user