[kotlin] rename: skip additional search for parameter accessors

KTIJ-12718

GitOrigin-RevId: b929805701477e8f4a461fefd59f1fb0b83a0bc0
This commit is contained in:
Anna Kozlova
2025-07-16 17:29:19 +00:00
committed by intellij-monorepo-bot
parent 72ba98bc92
commit 52ce573c1c
8 changed files with 52 additions and 7 deletions
@@ -230,6 +230,11 @@ public class RenameTestGenerated extends AbstractRenameTest {
runTest("testData/refactoring/rename/dataClassPropertyWithJava/dataClassPropertyWithJava.test");
}
@TestMetadata("dataClassValuePropertyWithJava/dataClassPropertyWithJava.test")
public void testDataClassValuePropertyWithJava_DataClassPropertyWithJava() throws Exception {
runTest("testData/refactoring/rename/dataClassValuePropertyWithJava/dataClassPropertyWithJava.test");
}
@TestMetadata("enumGetEntriesFromJava/enumValueOf.test")
public void testEnumGetEntriesFromJava_EnumValueOf() throws Exception {
runTest("testData/refactoring/rename/enumGetEntriesFromJava/enumValueOf.test");
@@ -0,0 +1,5 @@
class JavaClass {
void test() {
var a = new XYZ(1).getP1();
}
}
@@ -0,0 +1,8 @@
data class XYZ(val p1: Int, val y: Int) {
operator fun component1(): Int = p1
}
fun test(xyz: XYZ) {
val (a, b) = xyz
val c = a + b
}
@@ -0,0 +1,5 @@
class JavaClass {
void test() {
var a = new XYZ(1).getValue();
}
}
@@ -0,0 +1,8 @@
data class XYZ(val /*rename*/value: Int, val y: Int) {
operator fun component1(): Int = value
}
fun test(xyz: XYZ) {
val (a, b) = xyz
val c = a + b
}
@@ -0,0 +1,7 @@
{
"type": "AUTO_DETECT",
"mainFile": "test.kt",
"newName": "p1",
"withRuntime": "true",
"enabledInK2": true
}
@@ -67,18 +67,20 @@ abstract class RenameKotlinPsiProcessor : RenamePsiElementProcessor() {
searchParameters: KotlinReferencesSearchParameters
): Collection<PsiReference> {
val references = ReferencesSearch.search(searchParameters).asIterable().toMutableSet()
if (element is KtNamedFunction || (element is KtProperty && !element.isLocal) || (element is KtParameter && element.hasValOrVar())) {
if (element is KtNamedFunction || (element is KtProperty && !element.isLocal)) {
// property accessors for parameters should be covered by KotlinReferencesSearcher.QueryProcessor.searchMethodAware
element.toLightMethods().flatMapTo(references) { method ->
if (element is KtParameter && DataClassResolver.isComponentLike(method.name)) {
// renaming a data class property doesn't change the synthetic component name
return@flatMapTo emptyList()
}
MethodReferencesSearch.search(
// ReferenceSearch, called MethodUsagesSearcher#processQuery would still start operator conventions search
// because kotlinOptions are lost during the call
KotlinMethodReferencesSearchParameters(
method,
kotlinOptions = KotlinReferencesSearchOptions(
acceptImportAlias = false
)
acceptImportAlias = false,
searchForComponentConventions = false,
searchForOperatorConventions = false,
),
scope = searchParameters.effectiveSearchScope,
)
).asIterable()
}
@@ -230,6 +230,11 @@ public class FirRenameTestGenerated extends AbstractFirRenameTest {
runTest("../../idea/tests/testData/refactoring/rename/dataClassPropertyWithJava/dataClassPropertyWithJava.test");
}
@TestMetadata("dataClassValuePropertyWithJava/dataClassPropertyWithJava.test")
public void testDataClassValuePropertyWithJava_DataClassPropertyWithJava() throws Exception {
runTest("../../idea/tests/testData/refactoring/rename/dataClassValuePropertyWithJava/dataClassPropertyWithJava.test");
}
@TestMetadata("enumGetEntriesFromJava/enumValueOf.test")
public void testEnumGetEntriesFromJava_EnumValueOf() throws Exception {
runTest("../../idea/tests/testData/refactoring/rename/enumGetEntriesFromJava/enumValueOf.test");