mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-04 15:51:54 +00:00
Rename: Use RenameKotlinParameterProcessor for constructor/lambda parameters
#KT-13253 Fixed
This commit is contained in:
@@ -267,6 +267,7 @@ Using 'this' as function argument in constructor of non-final class
|
||||
- [`KT-13174`](https://youtrack.jetbrains.com/issue/KT-13174) Move: Warn about accessibility conflicts due to moving to unrelated module
|
||||
- [`KT-13175`](https://youtrack.jetbrains.com/issue/KT-13175) Move: Warn about accessibility conflicts when moving entire file
|
||||
- [`KT-13240`](https://youtrack.jetbrains.com/issue/KT-13240) Rename: Do not report shadowing conflict if redeclaration is detected
|
||||
- [`KT-13253`](https://youtrack.jetbrains.com/issue/KT-13253) Rename: Report conflicts for constructor parameters
|
||||
|
||||
##### New features
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider {
|
||||
is KtClass -> if (targetElement.isInterface()) "interface" else "class"
|
||||
is KtObjectDeclaration -> "object"
|
||||
is KtNamedFunction -> "function"
|
||||
is KtFunctionLiteral -> "lambda"
|
||||
is KtPrimaryConstructor, is KtSecondaryConstructor -> "constructor"
|
||||
is KtProperty -> if (targetElement.isLocal) "variable" else "property"
|
||||
is KtTypeParameter -> "type parameter"
|
||||
|
||||
@@ -31,13 +31,13 @@ import org.jetbrains.kotlin.idea.core.getDeepestSuperDeclarations
|
||||
import org.jetbrains.kotlin.idea.refactoring.canRefactor
|
||||
import org.jetbrains.kotlin.idea.refactoring.getAffectedCallables
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() {
|
||||
override fun canProcessElement(element: PsiElement) = element is KtParameter && element.ownerFunction is KtNamedFunction
|
||||
override fun canProcessElement(element: PsiElement) = element is KtParameter && element.ownerFunction is KtFunction
|
||||
|
||||
override fun isToSearchInComments(psiElement: PsiElement) = JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_VARIABLE
|
||||
|
||||
|
||||
@@ -64,7 +64,11 @@ import java.util.*
|
||||
|
||||
internal fun ResolvedCall<*>.noReceivers() = dispatchReceiver == null && extensionReceiver == null
|
||||
|
||||
internal fun PsiNamedElement.renderDescription() = "${UsageViewUtil.getType(this)} '$name'".trim()
|
||||
internal fun PsiNamedElement.renderDescription(): String {
|
||||
val type = UsageViewUtil.getType(this)
|
||||
if (name == null || name!!.startsWith("<")) return type
|
||||
return "$type '$name'".trim()
|
||||
}
|
||||
|
||||
internal fun PsiElement.representativeContainer(): PsiNamedElement? =
|
||||
when (this) {
|
||||
|
||||
7
idea/testData/refactoring/rename/lambdaParameterRedeclaration/before/test.kt
vendored
Normal file
7
idea/testData/refactoring/rename/lambdaParameterRedeclaration/before/test.kt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
fun foo(f: (Int, Int) -> Int) = f(1, 2)
|
||||
|
||||
fun test() {
|
||||
foo { /*rename*/a, b -> a + b }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "test.kt",
|
||||
"newName": "b",
|
||||
"withRuntime": "true",
|
||||
"hint": "Parameter 'b' is already declared in lambda"
|
||||
}
|
||||
3
idea/testData/refactoring/rename/primaryConstructorParameterRedeclaration/before/test.kt
vendored
Normal file
3
idea/testData/refactoring/rename/primaryConstructorParameterRedeclaration/before/test.kt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class A(/*rename*/cpa: Int, cpb: Int)
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "test.kt",
|
||||
"newName": "cpb",
|
||||
"withRuntime": "true",
|
||||
"hint": "Parameter 'cpb' is already declared in class 'A'"
|
||||
}
|
||||
5
idea/testData/refactoring/rename/secondaryCnstructorParameterRedeclaration/before/test.kt
vendored
Normal file
5
idea/testData/refactoring/rename/secondaryCnstructorParameterRedeclaration/before/test.kt
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
constructor(/*rename*/cpa: Int, cpb: Int)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "test.kt",
|
||||
"newName": "cpb",
|
||||
"withRuntime": "true",
|
||||
"hint": "Parameter 'cpb' is already declared in constructor 'A'"
|
||||
}
|
||||
@@ -185,6 +185,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaParameterRedeclaration/lambdaParameterRedeclaration.test")
|
||||
public void testLambdaParameterRedeclaration_LambdaParameterRedeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/lambdaParameterRedeclaration/lambdaParameterRedeclaration.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("memberFunctionRedeclaration/memberFunctionRedeclaration.test")
|
||||
public void testMemberFunctionRedeclaration_MemberFunctionRedeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/memberFunctionRedeclaration/memberFunctionRedeclaration.test");
|
||||
@@ -239,6 +245,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructorParameterRedeclaration/primaryConstructorParameterRedeclaration.test")
|
||||
public void testPrimaryConstructorParameterRedeclaration_PrimaryConstructorParameterRedeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/primaryConstructorParameterRedeclaration/primaryConstructorParameterRedeclaration.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccidentalOverrideSubclass/propertyAccidentalOverrideSubclass.test")
|
||||
public void testPropertyAccidentalOverrideSubclass_PropertyAccidentalOverrideSubclass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/propertyAccidentalOverrideSubclass/propertyAccidentalOverrideSubclass.test");
|
||||
@@ -995,6 +1007,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("secondaryCnstructorParameterRedeclaration/secondaryConstructorParameterRedeclaration.test")
|
||||
public void testSecondaryCnstructorParameterRedeclaration_SecondaryConstructorParameterRedeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/secondaryCnstructorParameterRedeclaration/secondaryConstructorParameterRedeclaration.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticPropertyUsages1/renameGetMethod.test")
|
||||
public void testSyntheticPropertyUsages1_RenameGetMethod() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/syntheticPropertyUsages1/renameGetMethod.test");
|
||||
|
||||
Reference in New Issue
Block a user