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:
Alexey Sedunov
2016-06-21 15:18:16 +03:00
parent 248f4c1645
commit efa27e6048
13 changed files with 123 additions and 0 deletions
@@ -263,6 +263,22 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
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) {
if (element is KtDeclaration && newPropertyName != null) {
val wrapper = object : PsiNamedElement by propertyMethod {
@@ -0,0 +1,8 @@
package test;
class Test {
{
new A().getFooNew();
new A().setFooNew(1);
}
}
@@ -0,0 +1,12 @@
package test
class A {
@get:JvmName("getFooNew")
@set:JvmName("setFooNew")
var first = 1
}
fun test() {
A().first
A().first = 1
}
@@ -0,0 +1,8 @@
package test;
class Test {
{
new A()./*rename*/getFoo();
new A().setFoo(1);
}
}
@@ -0,0 +1,12 @@
package test
class A {
@get:JvmName("getFoo")
@set:JvmName("setFoo")
var first = 1
}
fun test() {
A().first
A().first = 1
}
@@ -0,0 +1,7 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test/JavaClient.java",
"newName": "getFooNew",
"withRuntime": "true",
"byRef": "true"
}
@@ -0,0 +1,8 @@
package test;
class Test {
{
new A().getFooNew();
new A().setFooNew(1);
}
}
@@ -0,0 +1,12 @@
package test
class A {
@get:JvmName("getFooNew")
@set:JvmName("setFooNew")
var first = 1
}
fun test() {
A().first
A().first = 1
}
@@ -0,0 +1,8 @@
package test;
class Test {
{
new A().getFoo();
new A()./*rename*/setFoo(1);
}
}
@@ -0,0 +1,12 @@
package test
class A {
@get:JvmName("getFoo")
@set:JvmName("setFoo")
var first = 1
}
fun test() {
A().first
A().first = 1
}
@@ -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);
}
@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")
public void testRenameKotlinPropertyWithSetterJvmName_RenameKotlinPropertyWithSetterJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinPropertyWithSetterJvmName/renameKotlinPropertyWithSetterJvmName.test");