diff --git a/ChangeLog.md b/ChangeLog.md index e113db29f87..70d2eb1a681 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -227,6 +227,7 @@ - [`KT-7851`](https://youtrack.jetbrains.com/issue/KT-7851) Respect naming conventions in automatic variable rename - [`KT-8044`](https://youtrack.jetbrains.com/issue/KT-8044), [`KT-9432`](https://youtrack.jetbrains.com/issue/KT-9432) Support @JvmName annotation in rename refactoring - [`KT-8512`](https://youtrack.jetbrains.com/issue/KT-8512) Support "Rename tests" options in Rename dialog +- [`KT-10578`](https://youtrack.jetbrains.com/issue/KT-10578) Support automatic test renaming for facade files - [`KT-12657`](https://youtrack.jetbrains.com/issue/KT-12657) Rename implicit usages of annotation method 'value' - [`KT-12759`](https://youtrack.jetbrains.com/issue/KT-12759) Suggest renaming both property accessors with matching @JvmName when renaming one of them from Java diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestRenamerFactory.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestRenamerFactory.kt index 8a9fd622f1c..122116c04f7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestRenamerFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestRenamerFactory.kt @@ -21,15 +21,17 @@ import com.intellij.psi.PsiElement import com.intellij.refactoring.rename.naming.AutomaticRenamer import com.intellij.refactoring.rename.naming.AutomaticTestRenamerFactory import com.intellij.usageView.UsageInfo -import org.jetbrains.kotlin.asJava.KtLightClass -import org.jetbrains.kotlin.asJava.toLightClass +import org.jetbrains.kotlin.asJava.* +import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtFile class KotlinAutomaticTestRenamerFactory : AutomaticTestRenamerFactory() { private fun getPsiClass(element: PsiElement): PsiClass? { return when (element) { - is KtLightClass -> element + is KtLightClassForExplicitDeclaration -> element is KtClassOrObject -> element.toLightClass() + is KtFile -> element.findFacadeClass() else -> null } } @@ -39,7 +41,9 @@ class KotlinAutomaticTestRenamerFactory : AutomaticTestRenamerFactory() { return super.isApplicable(psiClass) } - override fun createRenamer(element: PsiElement, newName: String?, usages: MutableCollection): AutomaticRenamer { - return super.createRenamer(getPsiClass(element)!!, newName, usages) + override fun createRenamer(element: PsiElement, newName: String, usages: MutableCollection): AutomaticRenamer { + val psiClass = getPsiClass(element)!! + val newPsiClassName = if (psiClass is KtLightClassForFacade) PackagePartClassUtils.getFilePartShortName(newName) else newName + return super.createRenamer(psiClass, newPsiClassName, usages) } } \ No newline at end of file diff --git a/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/BarKtTest.kt b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/BarKtTest.kt new file mode 100644 index 00000000000..2b3985b686b --- /dev/null +++ b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/BarKtTest.kt @@ -0,0 +1,16 @@ +package test + +import org.junit.Test +import org.junit.Assert.* + +class BarKtTest { + @Test + fun foo1() { + + } + + @Test + fun foo2() { + + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/bar.kt b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/bar.kt new file mode 100644 index 00000000000..517ff5a7945 --- /dev/null +++ b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/after/bar.kt @@ -0,0 +1,9 @@ +package test + +fun foo1() { + +} + +fun foo2() { + +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/automaticRenamerKotlinTestClassForFacade.test b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/automaticRenamerKotlinTestClassForFacade.test new file mode 100644 index 00000000000..d11431a8bb3 --- /dev/null +++ b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/automaticRenamerKotlinTestClassForFacade.test @@ -0,0 +1,7 @@ +{ + "type": "FILE", + "file": "foo.kt", + "newName": "bar.kt", + "withRuntime": "true", + "libraries": ["JUnit@lib/junit-4.12.jar"] +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/FooKtTest.kt b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/FooKtTest.kt new file mode 100644 index 00000000000..b0e75cdd2d6 --- /dev/null +++ b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/FooKtTest.kt @@ -0,0 +1,16 @@ +package test + +import org.junit.Test +import org.junit.Assert.* + +class FooKtTest { + @Test + fun foo1() { + + } + + @Test + fun foo2() { + + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/foo.kt b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/foo.kt new file mode 100644 index 00000000000..517ff5a7945 --- /dev/null +++ b/idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/before/foo.kt @@ -0,0 +1,9 @@ +package test + +fun foo1() { + +} + +fun foo2() { + +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java index 825774ffb45..72eb2688936 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java @@ -71,6 +71,12 @@ public class RenameTestGenerated extends AbstractRenameTest { doTest(fileName); } + @TestMetadata("automaticRenamerKotlinTestClassForFacade/automaticRenamerKotlinTestClassForFacade.test") + public void testAutomaticRenamerKotlinTestClassForFacade_AutomaticRenamerKotlinTestClassForFacade() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/automaticRenamerKotlinTestClassForFacade/automaticRenamerKotlinTestClassForFacade.test"); + doTest(fileName); + } + @TestMetadata("automaticRenamerOverloads/package.test") public void testAutomaticRenamerOverloads_Package() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/automaticRenamerOverloads/package.test");