Skip to content

Commit ff4c16d

Browse files
committed
Rename: Allow renaming class by constructor delegation call referencing primary constructor
#KT-8860 Fixed
1 parent e89e809 commit ff4c16d

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
- [`KT-7851`](https://youtrack.jetbrains.com/issue/KT-7851) Respect naming conventions in automatic variable rename
176176

177177
###### Issues fixed
178+
- [`KT-8860`](https://youtrack.jetbrains.com/issue/KT-8860) Allow renaming class by constructor delegation call referencing primary constructor
178179
- [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references
179180
- [`KT-9157`](https://youtrack.jetbrains.com/issue/KT-9157) Fixed in-place rename of Kotlin expression referring Java declaration
180181
- [`KT-10713`](https://youtrack.jetbrains.com/issue/KT-10713) Skip read-only declarations when renaming parameters

idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameOnSecondaryConstructorHandler.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import com.intellij.psi.PsiFile
2525
import com.intellij.psi.util.PsiTreeUtil
2626
import com.intellij.refactoring.rename.RenameHandler
2727
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
28-
import org.jetbrains.kotlin.psi.KtBlockExpression
29-
import org.jetbrains.kotlin.psi.KtParameterList
30-
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
31-
import org.jetbrains.kotlin.psi.KtValueArgumentList
28+
import org.jetbrains.kotlin.psi.*
3229

3330

3431
class RenameOnSecondaryConstructorHandler : RenameHandler {
@@ -40,7 +37,7 @@ class RenameOnSecondaryConstructorHandler : RenameHandler {
4037

4138
val element = PsiTreeUtil.findElementOfClassAtOffsetWithStopSet(
4239
file, editor.caretModel.offset, KtSecondaryConstructor::class.java, false,
43-
KtBlockExpression::class.java, KtValueArgumentList::class.java, KtParameterList::class.java
40+
KtBlockExpression::class.java, KtValueArgumentList::class.java, KtParameterList::class.java, KtConstructorDelegationCall::class.java
4441
)
4542
return element != null
4643
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Bar constructor(p: Int) {
2+
constructor(p: Int) : this(p + 1)
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo constructor(p: Int) {
2+
constructor(p: Int) : /*rename*/this(p + 1)
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "MARKED_ELEMENT",
3+
"mainFile": "test.kt",
4+
"newName": "Bar"
5+
}

idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public void testRenameBundleProperty_RenameBundleProperty() throws Exception {
125125
doTest(fileName);
126126
}
127127

128+
@TestMetadata("renameClassByRefInConstructorDelegationCall/renameClassByRefInConstructorDelegationCall.test")
129+
public void testRenameClassByRefInConstructorDelegationCall_RenameClassByRefInConstructorDelegationCall() throws Exception {
130+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameClassByRefInConstructorDelegationCall/renameClassByRefInConstructorDelegationCall.test");
131+
doTest(fileName);
132+
}
133+
128134
@TestMetadata("renameClassWithAutoVarConventions/renameClassWithAutoVarConventions.test")
129135
public void testRenameClassWithAutoVarConventions_RenameClassWithAutoVarConventions() throws Exception {
130136
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameClassWithAutoVarConventions/renameClassWithAutoVarConventions.test");

0 commit comments

Comments
 (0)