Rename: Support automatic test renaming for facade files
#KT-10578 Fixed (cherry picked from commit 35050f4)
This commit is contained in:
@@ -227,6 +227,7 @@
|
|||||||
- [`KT-7851`](https://youtrack.jetbrains.com/issue/KT-7851) Respect naming conventions in automatic variable rename
|
- [`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-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-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-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
|
- [`KT-12759`](https://youtrack.jetbrains.com/issue/KT-12759) Suggest renaming both property accessors with matching @JvmName when renaming one of them from Java
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -21,15 +21,17 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.refactoring.rename.naming.AutomaticRenamer
|
import com.intellij.refactoring.rename.naming.AutomaticRenamer
|
||||||
import com.intellij.refactoring.rename.naming.AutomaticTestRenamerFactory
|
import com.intellij.refactoring.rename.naming.AutomaticTestRenamerFactory
|
||||||
import com.intellij.usageView.UsageInfo
|
import com.intellij.usageView.UsageInfo
|
||||||
import org.jetbrains.kotlin.asJava.KtLightClass
|
import org.jetbrains.kotlin.asJava.*
|
||||||
import org.jetbrains.kotlin.asJava.toLightClass
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
class KotlinAutomaticTestRenamerFactory : AutomaticTestRenamerFactory() {
|
class KotlinAutomaticTestRenamerFactory : AutomaticTestRenamerFactory() {
|
||||||
private fun getPsiClass(element: PsiElement): PsiClass? {
|
private fun getPsiClass(element: PsiElement): PsiClass? {
|
||||||
return when (element) {
|
return when (element) {
|
||||||
is KtLightClass -> element
|
is KtLightClassForExplicitDeclaration -> element
|
||||||
is KtClassOrObject -> element.toLightClass()
|
is KtClassOrObject -> element.toLightClass()
|
||||||
|
is KtFile -> element.findFacadeClass()
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,9 @@ class KotlinAutomaticTestRenamerFactory : AutomaticTestRenamerFactory() {
|
|||||||
return super.isApplicable(psiClass)
|
return super.isApplicable(psiClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createRenamer(element: PsiElement, newName: String?, usages: MutableCollection<UsageInfo>): AutomaticRenamer {
|
override fun createRenamer(element: PsiElement, newName: String, usages: MutableCollection<UsageInfo>): AutomaticRenamer {
|
||||||
return super.createRenamer(getPsiClass(element)!!, newName, usages)
|
val psiClass = getPsiClass(element)!!
|
||||||
|
val newPsiClassName = if (psiClass is KtLightClassForFacade) PackagePartClassUtils.getFilePartShortName(newName) else newName
|
||||||
|
return super.createRenamer(psiClass, newPsiClassName, usages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
class BarKtTest {
|
||||||
|
@Test
|
||||||
|
fun foo1() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun foo2() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
fun foo1() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo2() {
|
||||||
|
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "FILE",
|
||||||
|
"file": "foo.kt",
|
||||||
|
"newName": "bar.kt",
|
||||||
|
"withRuntime": "true",
|
||||||
|
"libraries": ["JUnit@lib/junit-4.12.jar"]
|
||||||
|
}
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
class FooKtTest {
|
||||||
|
@Test
|
||||||
|
fun foo1() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun foo2() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
fun foo1() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo2() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -71,6 +71,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("automaticRenamerOverloads/package.test")
|
||||||
public void testAutomaticRenamerOverloads_Package() throws Exception {
|
public void testAutomaticRenamerOverloads_Package() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/automaticRenamerOverloads/package.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/automaticRenamerOverloads/package.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user