Rename: Update references to facade class when renaming file via matching top-level class
#KT-11903 Fixed (cherry picked from commit a1d9a25)
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.refactoring.JavaRefactoringSettings
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener
|
||||
import com.intellij.refactoring.rename.RenamePsiElementProcessor
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import org.jetbrains.kotlin.asJava.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.KtLightClassForExplicitDeclaration
|
||||
@@ -69,7 +70,9 @@ class RenameKotlinClassProcessor : RenameKotlinPsiProcessor() {
|
||||
if (virtualFile != null) {
|
||||
val nameWithoutExtensions = virtualFile.nameWithoutExtension
|
||||
if (nameWithoutExtensions == classOrObject.name) {
|
||||
allRenames.put(file, newName + "." + virtualFile.extension)
|
||||
val newFileName = newName + "." + virtualFile.extension
|
||||
allRenames.put(file, newFileName)
|
||||
RenamePsiElementProcessor.forElement(file).prepareRenaming(file, newFileName, allRenames)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
package foo
|
||||
|
||||
class TopLevel2 {}
|
||||
fun topMe() {}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package foo;
|
||||
|
||||
public class TopUser {
|
||||
public void use() {
|
||||
TopLevel2Kt.topMe();
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
package foo
|
||||
|
||||
class /*rename*/TopLevel {}
|
||||
fun topMe() {}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package foo;
|
||||
|
||||
public class TopUser {
|
||||
public void use() {
|
||||
TopLevelKt.topMe();
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "foo/TopLevel.kt",
|
||||
"newName": "TopLevel2",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
@@ -515,6 +515,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinFacadeClassViaTopLevelClass/renameKotlinFacadeClassViaTopLevelClass.test")
|
||||
public void testRenameKotlinFacadeClassViaTopLevelClass_RenameKotlinFacadeClassViaTopLevelClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinFacadeClassViaTopLevelClass/renameKotlinFacadeClassViaTopLevelClass.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinFacadeClassWithDefaultNameAndCommentsByRef/renameKotlinFacadeClassWithDefaultNameByRef.test")
|
||||
public void testRenameKotlinFacadeClassWithDefaultNameAndCommentsByRef_RenameKotlinFacadeClassWithDefaultNameByRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameKotlinFacadeClassWithDefaultNameAndCommentsByRef/renameKotlinFacadeClassWithDefaultNameByRef.test");
|
||||
|
||||
Reference in New Issue
Block a user