diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/AutomaticTestMethodRenamerFactory.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/AutomaticTestMethodRenamerFactory.kt index 89e92f22f797..cf4aeb2d7bd6 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/AutomaticTestMethodRenamerFactory.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/AutomaticTestMethodRenamerFactory.kt @@ -2,14 +2,21 @@ package com.intellij.refactoring.rename.naming import com.intellij.codeInsight.TestFrameworks +import com.intellij.ide.projectView.impl.ProjectRootsUtil import com.intellij.java.refactoring.JavaRefactoringBundle import com.intellij.openapi.module.Module +import com.intellij.psi.PsiElement import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiShortNamesCache import com.intellij.util.containers.ContainerUtil import java.util.regex.Pattern abstract class AutomaticTestMethodRenamerFactory : AutomaticRenamerFactory { + override fun isApplicable(element: PsiElement): Boolean { + val file = element.containingFile + return !ProjectRootsUtil.isInTestSource(file) + } + override fun getOptionName(): String = JavaRefactoringBundle.message("rename.test.method") protected class AutomaticTestMethodRenamer(oldMethodName: String?, diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/JavaAutomaticTestMethodRenamerFactory.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/JavaAutomaticTestMethodRenamerFactory.kt index a1a8d6e5f2f4..fa3d892c4c7c 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/JavaAutomaticTestMethodRenamerFactory.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/rename/naming/JavaAutomaticTestMethodRenamerFactory.kt @@ -1,7 +1,6 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.refactoring.rename.naming -import com.intellij.ide.projectView.impl.ProjectRootsUtil import com.intellij.openapi.module.ModuleUtil import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod @@ -11,8 +10,7 @@ import com.intellij.usageView.UsageInfo class JavaAutomaticTestMethodRenamerFactory : AutomaticTestMethodRenamerFactory() { override fun isApplicable(element: PsiElement): Boolean { if (element !is PsiMethod) return false - val file = element.containingFile - return !ProjectRootsUtil.isInTestSource(file) + return super.isApplicable(element) } override fun isEnabled(): Boolean = JavaRefactoringSettings.getInstance().isRenameTestMethods diff --git a/java/java-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.java b/jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.java similarity index 100% rename from java/java-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.java rename to jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.java diff --git a/java/java-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.java b/jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.java similarity index 100% rename from java/java-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.java rename to jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.java diff --git a/java/java-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.java b/jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.java similarity index 100% rename from java/java-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.java rename to jvm/jvm-analysis-java-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.java diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/refactoring/rename/JavaAutomaticTestMethodRenamerTest.kt b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/refactoring/rename/JavaAutomaticTestMethodRenamerTest.kt new file mode 100644 index 000000000000..9100b99f7c0f --- /dev/null +++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/refactoring/rename/JavaAutomaticTestMethodRenamerTest.kt @@ -0,0 +1,16 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.refactoring.rename + +import com.intellij.jvm.analysis.JavaJvmAnalysisTestUtil +import com.intellij.jvm.analysis.testFramework.AutomaticTestMethodRenamerTestBase + + +class JavaAutomaticTestMethodRenamerTest : AutomaticTestMethodRenamerTestBase() { + override fun getBasePath(): String = JavaJvmAnalysisTestUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/refactoring/renameTestMethod" + + fun testTestMethod() = doTest("ClassTest.java") + + fun testHelperMethod() = doTest("ClassTest.java") + + fun testHelperClass() = doTest("TestUtil.java") +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.kt b/jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.kt similarity index 100% rename from plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.kt rename to jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/helperClass/test_src/TestUtil.kt diff --git a/plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.kt b/jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.kt similarity index 100% rename from plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.kt rename to jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/helperMethod/test_src/ClassTest.kt diff --git a/plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.kt b/jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.kt similarity index 100% rename from plugins/kotlin/idea/tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.kt rename to jvm/jvm-analysis-kotlin-tests/testData/refactoring/renameTestMethod/testMethod/test_src/ClassTest.kt diff --git a/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/refactoring/rename/KotlinAutomaticTestMethodRenamerTest.kt b/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/refactoring/rename/KotlinAutomaticTestMethodRenamerTest.kt new file mode 100644 index 000000000000..60c010d0b18f --- /dev/null +++ b/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/refactoring/rename/KotlinAutomaticTestMethodRenamerTest.kt @@ -0,0 +1,15 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.refactoring.rename + +import com.intellij.jvm.analysis.KotlinJvmAnalysisTestUtil +import com.intellij.jvm.analysis.testFramework.AutomaticTestMethodRenamerTestBase + +class KotlinAutomaticTestMethodRenamerTest : AutomaticTestMethodRenamerTestBase() { + override fun getBasePath(): String = KotlinJvmAnalysisTestUtil.TEST_DATA_PROJECT_RELATIVE_BASE_PATH + "/refactoring/renameTestMethod" + + fun testTestMethod() = doTest("ClassTest.kt") + + fun testHelperMethod() = doTest("ClassTest.kt") + + fun testHelperClass() = doTest("TestUtil.kt") +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/rename/JavaAutomaticTestMethodRenamerAntiTest.kt b/jvm/jvm-analysis-testFramework/src/com/intellij/jvm/analysis/testFramework/AutomaticTestMethodRenamerTestBase.kt similarity index 60% rename from java/java-tests/testSrc/com/intellij/java/refactoring/rename/JavaAutomaticTestMethodRenamerAntiTest.kt rename to jvm/jvm-analysis-testFramework/src/com/intellij/jvm/analysis/testFramework/AutomaticTestMethodRenamerTestBase.kt index 919381ed7a8d..1d2064d33266 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/rename/JavaAutomaticTestMethodRenamerAntiTest.kt +++ b/jvm/jvm-analysis-testFramework/src/com/intellij/jvm/analysis/testFramework/AutomaticTestMethodRenamerTestBase.kt @@ -1,7 +1,5 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.java.refactoring.rename +package com.intellij.jvm.analysis.testFramework -import com.intellij.JavaTestUtil import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ContentEntry import com.intellij.openapi.roots.ModifiableRootModel @@ -9,18 +7,14 @@ import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import com.intellij.util.PathUtil import junit.framework.TestCase import org.junit.jupiter.api.Nested import java.io.File - -class JavaAutomaticTestMethodRenamerAntiTest : LightJavaCodeInsightFixtureTestCase() { - override fun getTestDataPath(): String = JavaTestUtil.getJavaTestDataPath() + "/refactoring/renameTestMethod" - - override fun getProjectDescriptor(): LightProjectDescriptor = - object : DefaultLightProjectDescriptor() { +abstract class AutomaticTestMethodRenamerTestBase : LightJvmCodeInsightFixtureTestCase() { + override fun getProjectDescriptor(): LightProjectDescriptor { + return object : DefaultLightProjectDescriptor() { override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) { super.configureModule(module, model, contentEntry) val jar1 = File(PathUtil.getJarPathForClass(Nested::class.java)) @@ -28,14 +22,8 @@ class JavaAutomaticTestMethodRenamerAntiTest : LightJavaCodeInsightFixtureTestCa contentEntry.addSourceFolder(contentEntry.url + "/${getTestName(true)}/test_src", true) } } - - fun testTestMethod() = doTest("ClassTest.java") - - fun testHelperMethod() = doTest("ClassTest.java") - - fun testHelperClass() = doTest("TestUtil.java") - - private fun doTest(filename: String) { + } + protected fun doTest(filename: String) { val filePath = "${getTestName(true)}/test_src/$filename" myFixture.configureByFile(filePath) val element = myFixture.elementAtCaret diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerAntiTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerAntiTest.kt deleted file mode 100644 index d7974b7124a2..000000000000 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerAntiTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.kotlin.idea.refactoring.rename - -import com.intellij.openapi.module.Module -import com.intellij.openapi.roots.ContentEntry -import com.intellij.openapi.roots.ModifiableRootModel -import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory -import com.intellij.testFramework.LightProjectDescriptor -import junit.framework.TestCase -import org.jetbrains.kotlin.idea.base.plugin.artifacts.TestKotlinArtifacts -import org.jetbrains.kotlin.idea.base.test.TestRoot -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.test.TestMetadata - -@TestRoot("idea/tests") -@TestMetadata("testData/refactoring/renameTestMethod") -class KotlinAutomaticTestMethodRenamerAntiTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getProjectDescriptor(): LightProjectDescriptor { - val jarPaths = listOf(TestKotlinArtifacts.kotlinStdlib, ConfigLibraryUtil.ATTACHABLE_LIBRARIES["JUnit5"]!!) - return object : KotlinWithJdkAndRuntimeLightProjectDescriptor(jarPaths, listOf(TestKotlinArtifacts.kotlinStdlibSources)) { - override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) { - super.configureModule(module, model, contentEntry) - contentEntry.addSourceFolder(contentEntry.url + "/${getTestName(true)}/test_src", true) - } - } - } - - fun testTestMethod() = doTest("ClassTest.kt") - - fun testHelperMethod() = doTest("ClassTest.kt") - - fun testHelperClass() = doTest("TestUtil.kt") - - private fun doTest(filename : String) { - val filePath = "${getTestName(true)}/test_src/$filename" - myFixture.configureByFile(filePath) - val element = myFixture.elementAtCaret - AutomaticRenamerFactory.EP_NAME.extensionList.forEach { - TestCase.assertFalse(it.isApplicable(element)) - } - } -} \ No newline at end of file diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerFactory.kt b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerFactory.kt index 3f40c1331f26..fb4194360dc7 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerFactory.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/rename/KotlinAutomaticTestMethodRenamerFactory.kt @@ -1,7 +1,6 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.refactoring.rename -import com.intellij.ide.projectView.impl.ProjectRootsUtil import com.intellij.psi.PsiElement import com.intellij.refactoring.rename.naming.AutomaticRenamer import com.intellij.refactoring.rename.naming.AutomaticTestMethodRenamerFactory @@ -14,8 +13,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject class KotlinAutomaticTestMethodRenamerFactory : AutomaticTestMethodRenamerFactory() { override fun isApplicable(element: PsiElement): Boolean { if (element !is KtNamedFunction) return false - val file = element.containingKtFile - return !ProjectRootsUtil.isInTestSource(file) + return super.isApplicable(element) } override fun createRenamer(element: PsiElement, newName: String, usages: MutableCollection): AutomaticRenamer {