Rename: Do not replace Java references to synthetic component functions when renaming constructor parameter

#KT-9241 Fixed
This commit is contained in:
Alexey Sedunov
2016-05-27 16:24:55 +03:00
parent 958b402e42
commit d27f3c0189
8 changed files with 59 additions and 1 deletions
+1
View File
@@ -179,6 +179,7 @@
- [`KT-8860`](https://youtrack.jetbrains.com/issue/KT-8860) Allow renaming class by constructor delegation call referencing primary constructor
- [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references
- [`KT-9157`](https://youtrack.jetbrains.com/issue/KT-9157) Fixed in-place rename of Kotlin expression referring Java declaration
- [`KT-9241`](https://youtrack.jetbrains.com/issue/KT-9241) Do not replace Java references to synthetic component functions when renaming constructor parameter
- [`KT-9444`](https://youtrack.jetbrains.com/issue/KT-9444) Rename dialog: Allow typing any identifier without backquotes
- [`KT-10713`](https://youtrack.jetbrains.com/issue/KT-10713) Skip read-only declarations when renaming parameters
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.OverrideResolver
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
override fun canProcessElement(element: PsiElement): Boolean {
@@ -168,7 +169,12 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
val oldGetterName = JvmAbi.getterName(name)
val oldSetterName = JvmAbi.setterName(name)
val refKindUsages = usages.toList().groupBy { usage: UsageInfo ->
val adjustedUsages = if (element is KtParameter) usages.filterNot {
val refTarget = it.reference?.resolve()
refTarget is KtLightMethod && isComponentLike(Name.guessByFirstCharacter(refTarget.name))
} else usages.toList()
val refKindUsages = adjustedUsages.groupBy { usage: UsageInfo ->
val refElement = usage.reference?.resolve()
if (refElement is PsiMethod) {
when (refElement.name) {
@@ -0,0 +1,10 @@
package test;
public class JavaClient {
void test(A a) {
a.getFooNew();
a.component1();
a.getBar();
a.component2();
}
}
@@ -0,0 +1,10 @@
package test
data class A(val fooNew: Int, val bar: String)
fun test(a: A) {
a.fooNew
a.component1()
a.bar
a.component2()
}
@@ -0,0 +1,10 @@
package test;
public class JavaClient {
void test(A a) {
a.getFoo();
a.component1();
a.getBar();
a.component2();
}
}
@@ -0,0 +1,10 @@
package test
data class A(val /*rename*/foo: Int, val bar: String)
fun test(a: A) {
a.foo
a.component1()
a.bar
a.component2()
}
@@ -0,0 +1,5 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test.kt",
"newName": "fooNew"
}
@@ -317,6 +317,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
@TestMetadata("renameKotlinDataClassParameter/renameKotlinDataClassParameter.test")
public void testRenameKotlinDataClassParameter_RenameKotlinDataClassParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinDataClassParameter/renameKotlinDataClassParameter.test");
doTest(fileName);
}
@TestMetadata("renameKotlinEnum/renameKotlinEnum.test")
public void testRenameKotlinEnum_RenameKotlinEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinEnum/renameKotlinEnum.test");