Rename: Suggest renaming both property accessors with matching @JvmName when renaming one of them from Java
#KT-12759 Fixed (cherry picked from commit 81a8e6a)
This commit is contained in:
@@ -227,6 +227,7 @@
|
|||||||
- [`KT-7851`](https://youtrack.jetbrains.com/issue/KT-7851) Respect naming conventions in automatic variable rename
|
- [`KT-7851`](https://youtrack.jetbrains.com/issue/KT-7851) Respect naming conventions in automatic variable rename
|
||||||
- [`KT-8044`](https://youtrack.jetbrains.com/issue/KT-8044), [`KT-9432`](https://youtrack.jetbrains.com/issue/KT-9432) Support @JvmName annotation in rename refactoring
|
- [`KT-8044`](https://youtrack.jetbrains.com/issue/KT-8044), [`KT-9432`](https://youtrack.jetbrains.com/issue/KT-9432) Support @JvmName annotation in rename refactoring
|
||||||
- [`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
|
||||||
|
- [`KT-12759`](https://youtrack.jetbrains.com/issue/KT-12759) Suggest renaming both property accessors with matching @JvmName when renaming one of them from Java
|
||||||
|
|
||||||
###### 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-4791`](https://youtrack.jetbrains.com/issue/KT-4791) Rename overridden property and all its accessors on attempt to rename overriding accessor in Java code
|
||||||
|
|||||||
+16
@@ -263,6 +263,22 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
|
|||||||
|
|
||||||
val (getterJvmName, setterJvmName) = getJvmNames(namedUnwrappedElement)
|
val (getterJvmName, setterJvmName) = getJvmNames(namedUnwrappedElement)
|
||||||
|
|
||||||
|
val getter = propertyMethods.getter as? KtLightMethod
|
||||||
|
val setter = propertyMethods.setter as? KtLightMethod
|
||||||
|
if (newPropertyName != null
|
||||||
|
&& getter != null && setter != null
|
||||||
|
&& (element == getter || element == setter)
|
||||||
|
&& propertyNameByAccessor(getter.name, getter) == propertyNameByAccessor(setter.name, setter)) {
|
||||||
|
val accessorToRename = if (element == getter) setter else getter
|
||||||
|
val newAccessorName = if (element == getter) JvmAbi.setterName(newPropertyName) else JvmAbi.getterName(newPropertyName)
|
||||||
|
if (ApplicationManager.getApplication().isUnitTestMode
|
||||||
|
|| Messages.showYesNoDialog("Do you want to rename ${accessorToRename.name}() as well?",
|
||||||
|
"Rename",
|
||||||
|
Messages.getQuestionIcon()) == Messages.YES) {
|
||||||
|
allRenames[accessorToRename] = newAccessorName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (propertyMethod in propertyMethods) {
|
for (propertyMethod in propertyMethods) {
|
||||||
if (element is KtDeclaration && newPropertyName != null) {
|
if (element is KtDeclaration && newPropertyName != null) {
|
||||||
val wrapper = object : PsiNamedElement by propertyMethod {
|
val wrapper = object : PsiNamedElement by propertyMethod {
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
{
|
||||||
|
new A().getFooNew();
|
||||||
|
new A().setFooNew(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@get:JvmName("getFooNew")
|
||||||
|
@set:JvmName("setFooNew")
|
||||||
|
var first = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
A().first
|
||||||
|
A().first = 1
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
{
|
||||||
|
new A()./*rename*/getFoo();
|
||||||
|
new A().setFoo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@get:JvmName("getFoo")
|
||||||
|
@set:JvmName("setFoo")
|
||||||
|
var first = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
A().first
|
||||||
|
A().first = 1
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test/JavaClient.java",
|
||||||
|
"newName": "getFooNew",
|
||||||
|
"withRuntime": "true",
|
||||||
|
"byRef": "true"
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
{
|
||||||
|
new A().getFooNew();
|
||||||
|
new A().setFooNew(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@get:JvmName("getFooNew")
|
||||||
|
@set:JvmName("setFooNew")
|
||||||
|
var first = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
A().first
|
||||||
|
A().first = 1
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
{
|
||||||
|
new A().getFoo();
|
||||||
|
new A()./*rename*/setFoo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@get:JvmName("getFoo")
|
||||||
|
@set:JvmName("setFoo")
|
||||||
|
var first = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
A().first
|
||||||
|
A().first = 1
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test/JavaClient.java",
|
||||||
|
"newName": "setFooNew",
|
||||||
|
"withRuntime": "true",
|
||||||
|
"byRef": "true"
|
||||||
|
}
|
||||||
@@ -767,6 +767,18 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef/renameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef.test")
|
||||||
|
public void testRenameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef_RenameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef/renameKotlinPropertyWithMatchingGetterSetterJvmNameByGetterRef.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("renameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef/renameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef.test")
|
||||||
|
public void testRenameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef_RenameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef/renameKotlinPropertyWithMatchingGetterSetterJvmNameBySetterRef.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("renameKotlinPropertyWithSetterJvmName/renameKotlinPropertyWithSetterJvmName.test")
|
@TestMetadata("renameKotlinPropertyWithSetterJvmName/renameKotlinPropertyWithSetterJvmName.test")
|
||||||
public void testRenameKotlinPropertyWithSetterJvmName_RenameKotlinPropertyWithSetterJvmName() throws Exception {
|
public void testRenameKotlinPropertyWithSetterJvmName_RenameKotlinPropertyWithSetterJvmName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPropertyWithSetterJvmName/renameKotlinPropertyWithSetterJvmName.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPropertyWithSetterJvmName/renameKotlinPropertyWithSetterJvmName.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user