Rename by-name parameter usage in function calls when renaming function's parameter
#KT-32999 fixed
This commit is contained in:
+15
@@ -6,10 +6,13 @@
|
||||
package org.jetbrains.kotlin.idea.refactoring.rename
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings
|
||||
import org.jetbrains.kotlin.idea.search.or
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
@@ -39,6 +42,18 @@ class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() {
|
||||
result += collisions
|
||||
}
|
||||
|
||||
override fun findReferences(
|
||||
element: PsiElement,
|
||||
searchScope: SearchScope,
|
||||
searchInCommentsAndStrings: Boolean
|
||||
): MutableCollection<PsiReference> {
|
||||
if (element !is KtParameter) return super.findReferences(element, searchScope, searchInCommentsAndStrings)
|
||||
val ownerFunction = element.ownerFunction
|
||||
?: return super.findReferences(element, searchScope, searchInCommentsAndStrings)
|
||||
val newScope = searchScope or ownerFunction.useScope
|
||||
return super.findReferences(element, newScope, searchInCommentsAndStrings)
|
||||
}
|
||||
|
||||
override fun renameElement(element: PsiElement, newName: String, usages: Array<UsageInfo>, listener: RefactoringElementListener?) {
|
||||
super.renameElement(element, newName, usages, listener)
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun bar() {
|
||||
Foo(second = 1)
|
||||
}
|
||||
idea/testData/refactoring/rename/renameKotlinConstructorParameterWithByNameUsages/after/test/test.kt
Vendored
+1
@@ -0,0 +1 @@
|
||||
class Foo(val second: Int = 1)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun bar() {
|
||||
Foo(first = 1)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class Foo(val /*rename*/first: Int = 1)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "test/test.kt",
|
||||
"newName": "second",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun bar() {
|
||||
foo(second = 1)
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(second: Int = 1) {
|
||||
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun bar() {
|
||||
foo(first = 1)
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(/*rename*/first: Int = 1) {
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "test/test.kt",
|
||||
"newName": "second",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+10
@@ -738,6 +738,11 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinClassWithFile/kotlinClass.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinConstructorParameterWithByNameUsages/renameKotlinConstructorParameterWithByNameUsages.test")
|
||||
public void testRenameKotlinConstructorParameterWithByNameUsages_RenameKotlinConstructorParameterWithByNameUsages() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinConstructorParameterWithByNameUsages/renameKotlinConstructorParameterWithByNameUsages.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinDataClassParameter/renameKotlinDataClassParameter.test")
|
||||
public void testRenameKotlinDataClassParameter_RenameKotlinDataClassParameter() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinDataClassParameter/renameKotlinDataClassParameter.test");
|
||||
@@ -808,6 +813,11 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinFunctionInEnum/renameKotlinFunctionInEnumFromSubclass.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinFunctionParameterWithByNameUsages/renameKotlinFunctionParameterWithByNameUsages.test")
|
||||
public void testRenameKotlinFunctionParameterWithByNameUsages_RenameKotlinFunctionParameterWithByNameUsages() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinFunctionParameterWithByNameUsages/renameKotlinFunctionParameterWithByNameUsages.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinFunWithJvmName/renameKotlinFunWithJvmName.test")
|
||||
public void testRenameKotlinFunWithJvmName_RenameKotlinFunWithJvmName() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinFunWithJvmName/renameKotlinFunWithJvmName.test");
|
||||
|
||||
Reference in New Issue
Block a user