Move: Convert AbstractMoveTest to light fixture test case
Extract multi-module move test to a separate class
This commit is contained in:
@@ -112,6 +112,7 @@ import org.jetbrains.kotlin.idea.refactoring.AbstractNameSuggestionProviderTest
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTest
|
import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTest
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractExtractionTest
|
import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractExtractionTest
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.AbstractMoveTest
|
import org.jetbrains.kotlin.idea.refactoring.move.AbstractMoveTest
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.move.AbstractMultiModuleMoveTest
|
||||||
import org.jetbrains.kotlin.idea.refactoring.pullUp.AbstractPullUpTest
|
import org.jetbrains.kotlin.idea.refactoring.pullUp.AbstractPullUpTest
|
||||||
import org.jetbrains.kotlin.idea.refactoring.pushDown.AbstractPushDownTest
|
import org.jetbrains.kotlin.idea.refactoring.pushDown.AbstractPushDownTest
|
||||||
import org.jetbrains.kotlin.idea.refactoring.rename.AbstractMultiModuleRenameTest
|
import org.jetbrains.kotlin.idea.refactoring.rename.AbstractMultiModuleRenameTest
|
||||||
@@ -711,6 +712,10 @@ fun main(args: Array<String>) {
|
|||||||
model("refactoring/move", extension = "test", singleClass = true)
|
model("refactoring/move", extension = "test", singleClass = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass<AbstractMultiModuleMoveTest> {
|
||||||
|
model("refactoring/moveMultiModule", extension = "test", singleClass = true)
|
||||||
|
}
|
||||||
|
|
||||||
testClass<AbstractMultiFileIntentionTest> {
|
testClass<AbstractMultiFileIntentionTest> {
|
||||||
model("multiFileIntentions", extension = "test", singleClass = true, filenameStartsLowerCase = true)
|
model("multiFileIntentions", extension = "test", singleClass = true, filenameStartsLowerCase = true)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.test
|
package org.jetbrains.kotlin.idea.test
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.CodeInsightTestCase
|
||||||
import com.intellij.codeInsight.daemon.impl.EditorTracker
|
import com.intellij.codeInsight.daemon.impl.EditorTracker
|
||||||
import com.intellij.ide.startup.impl.StartupManagerImpl
|
import com.intellij.ide.startup.impl.StartupManagerImpl
|
||||||
import com.intellij.openapi.actionSystem.ActionPlaces
|
import com.intellij.openapi.actionSystem.ActionPlaces
|
||||||
@@ -71,6 +72,7 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
CodeInsightTestCase.fixTemplates()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tearDown() {
|
override fun tearDown() {
|
||||||
|
|||||||
+1
-2
@@ -2,6 +2,5 @@
|
|||||||
"mainFile": "A/src/x/test.kt",
|
"mainFile": "A/src/x/test.kt",
|
||||||
"type": "MOVE_DIRECTORY_WITH_CLASSES",
|
"type": "MOVE_DIRECTORY_WITH_CLASSES",
|
||||||
"sourceDir": "A/src/x",
|
"sourceDir": "A/src/x",
|
||||||
"targetDir": "A/src/z",
|
"targetDir": "A/src/z"
|
||||||
"isMultiModule": "true"
|
|
||||||
}
|
}
|
||||||
-1
@@ -2,6 +2,5 @@
|
|||||||
"mainFile": "A/src/a1/internalTarget.kt",
|
"mainFile": "A/src/a1/internalTarget.kt",
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
}
|
}
|
||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
||||||
"targetPackage": "packJvm",
|
"targetPackage": "packJvm",
|
||||||
"targetSourceRoot": "A/src",
|
"targetSourceRoot": "A/src",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true",
|
"withRuntime": "true",
|
||||||
"modulesWithRuntime": ["A"],
|
"modulesWithRuntime": ["A"],
|
||||||
"modulesWithJsRuntime": ["B"]
|
"modulesWithJsRuntime": ["B"]
|
||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
||||||
"targetPackage": "packJs",
|
"targetPackage": "packJs",
|
||||||
"targetSourceRoot": "B/src",
|
"targetSourceRoot": "B/src",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true",
|
"withRuntime": "true",
|
||||||
"modulesWithRuntime": ["A"],
|
"modulesWithRuntime": ["A"],
|
||||||
"modulesWithJsRuntime": ["B"]
|
"modulesWithJsRuntime": ["B"]
|
||||||
-1
@@ -3,6 +3,5 @@
|
|||||||
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
||||||
"targetPackage": "packB",
|
"targetPackage": "packB",
|
||||||
"targetSourceRoot": "B/src",
|
"targetSourceRoot": "B/src",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
}
|
}
|
||||||
-1
@@ -2,7 +2,6 @@
|
|||||||
"mainFile": "A/src/a/test.kt",
|
"mainFile": "A/src/a/test.kt",
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true",
|
"withRuntime": "true",
|
||||||
"modulesWithRuntime": ["A"]
|
"modulesWithRuntime": ["A"]
|
||||||
}
|
}
|
||||||
-1
@@ -3,6 +3,5 @@
|
|||||||
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
|
||||||
"targetPackage": "target",
|
"targetPackage": "target",
|
||||||
"targetSourceRoot": "B/src",
|
"targetSourceRoot": "B/src",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
}
|
}
|
||||||
-1
@@ -2,6 +2,5 @@
|
|||||||
"mainFile": "A/src/a1/internalTarget.kt",
|
"mainFile": "A/src/a1/internalTarget.kt",
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"isMultiModule": "true",
|
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.idea.refactoring.move
|
|||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import com.intellij.codeInsight.TargetElementUtilBase
|
import com.intellij.codeInsight.TargetElementUtil
|
||||||
import com.intellij.openapi.editor.EditorFactory
|
import com.intellij.openapi.editor.EditorFactory
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.module.ModuleManager
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.openapi.vfs.LocalFileSystem
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
@@ -36,20 +36,21 @@ import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectori
|
|||||||
import com.intellij.refactoring.move.moveInner.MoveInnerProcessor
|
import com.intellij.refactoring.move.moveInner.MoveInnerProcessor
|
||||||
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions
|
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions
|
||||||
import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor
|
import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
|
import com.intellij.testFramework.UsefulTestCase
|
||||||
import com.intellij.util.ActionRunner
|
import com.intellij.util.ActionRunner
|
||||||
import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
|
import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
|
||||||
import org.jetbrains.kotlin.idea.jsonUtils.getString
|
import org.jetbrains.kotlin.idea.jsonUtils.getString
|
||||||
import org.jetbrains.kotlin.idea.refactoring.createKotlinFile
|
import org.jetbrains.kotlin.idea.refactoring.createKotlinFile
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.changePackage.KotlinChangePackageRefactoring
|
import org.jetbrains.kotlin.idea.refactoring.move.changePackage.KotlinChangePackageRefactoring
|
||||||
import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.rename.loadTestConfiguration
|
||||||
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
|
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
|
||||||
import org.jetbrains.kotlin.idea.search.allScope
|
import org.jetbrains.kotlin.idea.search.allScope
|
||||||
import org.jetbrains.kotlin.idea.search.projectScope
|
import org.jetbrains.kotlin.idea.search.projectScope
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
import org.jetbrains.kotlin.idea.test.*
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
|
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
|
||||||
import org.jetbrains.kotlin.idea.test.extractMarkerOffset
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
@@ -58,98 +59,94 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractMoveTest : KotlinMultiFileTestCase() {
|
abstract class AbstractMoveTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
|
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||||
|
if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor()
|
||||||
|
|
||||||
|
val testConfigurationFile = File(super.getTestDataPath(), fileName())
|
||||||
|
val config = loadTestConfiguration(testConfigurationFile)
|
||||||
|
val withRuntime = config["withRuntime"]?.asBoolean ?: false
|
||||||
|
if (withRuntime) {
|
||||||
|
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
}
|
||||||
|
return KotlinLightProjectDescriptor.INSTANCE
|
||||||
|
}
|
||||||
|
|
||||||
protected fun doTest(path: String) {
|
protected fun doTest(path: String) {
|
||||||
val config = JsonParser().parse(FileUtil.loadFile(File(path), true)) as JsonObject
|
val testFile = File(path)
|
||||||
|
val config = JsonParser().parse(FileUtil.loadFile(testFile, true)) as JsonObject
|
||||||
|
|
||||||
val action = MoveAction.valueOf(config.getString("type"))
|
doTestCommittingDocuments(testFile) { rootDir ->
|
||||||
|
runMoveRefactoring(path, config, rootDir, project)
|
||||||
val testDir = path.substring(0, path.lastIndexOf("/"))
|
}
|
||||||
val mainFilePath = config.getNullableString("mainFile")!!
|
|
||||||
|
|
||||||
val conflictFile = File(testDir + "/conflicts.txt")
|
|
||||||
|
|
||||||
isMultiModule = config["isMultiModule"]?.asBoolean ?: false
|
|
||||||
|
|
||||||
doTest({ rootDir, _ ->
|
|
||||||
val modulesWithJvmRuntime: List<Module>
|
|
||||||
val modulesWithJsRuntime: List<Module>
|
|
||||||
|
|
||||||
val withRuntime = config["withRuntime"]?.asBoolean ?: false
|
|
||||||
if (withRuntime) {
|
|
||||||
val moduleManager = ModuleManager.getInstance(project)
|
|
||||||
modulesWithJvmRuntime =
|
|
||||||
(config["modulesWithRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
|
|
||||||
?: moduleManager.modules.toList())
|
|
||||||
modulesWithJvmRuntime.forEach { ConfigLibraryUtil.configureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
|
|
||||||
modulesWithJsRuntime =
|
|
||||||
(config["modulesWithJsRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
|
|
||||||
?: emptyList())
|
|
||||||
modulesWithJsRuntime.forEach { ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
modulesWithJvmRuntime = emptyList()
|
|
||||||
modulesWithJsRuntime = emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
|
||||||
val mainPsiFile = PsiManager.getInstance(project!!).findFile(mainFile)!!
|
|
||||||
val document = FileDocumentManager.getInstance().getDocument(mainFile)!!
|
|
||||||
val editor = EditorFactory.getInstance()!!.createEditor(document, project!!)!!
|
|
||||||
|
|
||||||
val caretOffset = document.extractMarkerOffset(project)
|
|
||||||
val elementAtCaret = if (caretOffset >= 0) {
|
|
||||||
TargetElementUtilBase.getInstance()!!.findTargetElement(
|
|
||||||
editor,
|
|
||||||
TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED or TargetElementUtilBase.ELEMENT_NAME_ACCEPTED,
|
|
||||||
caretOffset
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else null
|
|
||||||
|
|
||||||
try {
|
|
||||||
action.runRefactoring(rootDir, mainPsiFile, elementAtCaret, config)
|
|
||||||
|
|
||||||
assert(!conflictFile.exists())
|
|
||||||
}
|
|
||||||
catch(e: ConflictsInTestsException) {
|
|
||||||
KotlinTestUtils.assertEqualsToFile(conflictFile, e.messages.sorted().joinToString("\n"))
|
|
||||||
|
|
||||||
ConflictsInTestsException.setTestIgnore(true)
|
|
||||||
|
|
||||||
// Run refactoring again with ConflictsInTestsException suppressed
|
|
||||||
action.runRefactoring(rootDir, mainPsiFile, elementAtCaret, config)
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
ConflictsInTestsException.setTestIgnore(false)
|
|
||||||
|
|
||||||
PsiDocumentManager.getInstance(project!!).commitAllDocuments()
|
|
||||||
FileDocumentManager.getInstance().saveAllDocuments()
|
|
||||||
|
|
||||||
EditorFactory.getInstance()!!.releaseEditor(editor)
|
|
||||||
|
|
||||||
modulesWithJvmRuntime.forEach {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
modulesWithJsRuntime.forEach {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getTestDirName(true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getTestDirName(lowercaseFirstLetter : Boolean) : String {
|
protected fun getTestDirName(lowercaseFirstLetter : Boolean) : String {
|
||||||
val testName = getTestName(lowercaseFirstLetter)
|
val testName = getTestName(lowercaseFirstLetter)
|
||||||
return testName.substring(0, testName.lastIndexOf('_')).replace('_', '/')
|
val endIndex = testName.lastIndexOf('_')
|
||||||
|
if (endIndex < 0) return testName
|
||||||
|
return testName.substring(0, endIndex).replace('_', '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestRoot() : String {
|
override fun getTestDataPath() = super.getTestDataPath() + "/" + getTestDirName(true)
|
||||||
return "/refactoring/move/"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTestDataPath() : String {
|
protected fun doTestCommittingDocuments(testFile: File, action: (VirtualFile) -> Unit) {
|
||||||
return PluginTestCaseBase.getTestDataPathBase()
|
val beforeVFile = myFixture.copyDirectoryToProject("before", "")
|
||||||
|
PsiDocumentManager.getInstance(myFixture.project).commitAllDocuments()
|
||||||
|
|
||||||
|
val afterDir = File(testFile.parentFile, "after")
|
||||||
|
val afterVFile = LocalFileSystem.getInstance().findFileByIoFile(afterDir)?.apply {
|
||||||
|
UsefulTestCase.refreshRecursively(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
action(beforeVFile)
|
||||||
|
|
||||||
|
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||||
|
FileDocumentManager.getInstance().saveAllDocuments()
|
||||||
|
PlatformTestUtil.assertDirectoriesEqual(afterVFile, beforeVFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun runMoveRefactoring(path: String, config: JsonObject, rootDir: VirtualFile, project: Project) {
|
||||||
|
val action = MoveAction.valueOf(config.getString("type"))
|
||||||
|
|
||||||
|
val testDir = path.substring(0, path.lastIndexOf("/"))
|
||||||
|
val mainFilePath = config.getNullableString("mainFile")!!
|
||||||
|
|
||||||
|
val conflictFile = File(testDir + "/conflicts.txt")
|
||||||
|
|
||||||
|
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
||||||
|
val mainPsiFile = PsiManager.getInstance(project).findFile(mainFile)!!
|
||||||
|
val document = FileDocumentManager.getInstance().getDocument(mainFile)!!
|
||||||
|
val editor = EditorFactory.getInstance()!!.createEditor(document, project)!!
|
||||||
|
|
||||||
|
val caretOffset = document.extractMarkerOffset(project)
|
||||||
|
val elementAtCaret = if (caretOffset >= 0) {
|
||||||
|
TargetElementUtil.getInstance().findTargetElement(
|
||||||
|
editor,
|
||||||
|
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED or TargetElementUtil.ELEMENT_NAME_ACCEPTED,
|
||||||
|
caretOffset
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else null
|
||||||
|
|
||||||
|
try {
|
||||||
|
action.runRefactoring(rootDir, mainPsiFile, elementAtCaret, config)
|
||||||
|
|
||||||
|
assert(!conflictFile.exists())
|
||||||
|
}
|
||||||
|
catch(e: ConflictsInTestsException) {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(conflictFile, e.messages.sorted().joinToString("\n"))
|
||||||
|
|
||||||
|
ConflictsInTestsException.setTestIgnore(true)
|
||||||
|
|
||||||
|
// Run refactoring again with ConflictsInTestsException suppressed
|
||||||
|
action.runRefactoring(rootDir, mainPsiFile, elementAtCaret, config)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
ConflictsInTestsException.setTestIgnore(false)
|
||||||
|
|
||||||
|
EditorFactory.getInstance()!!.releaseEditor(editor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.refactoring.move
|
||||||
|
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.module.ModuleManager
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.rename.loadTestConfiguration
|
||||||
|
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
abstract class AbstractMultiModuleMoveTest : KotlinMultiFileTestCase() {
|
||||||
|
override fun getTestRoot(): String = "/refactoring/moveMultiModule/"
|
||||||
|
|
||||||
|
override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase()
|
||||||
|
|
||||||
|
fun doTest(path: String) {
|
||||||
|
val config = loadTestConfiguration(File(path))
|
||||||
|
|
||||||
|
isMultiModule = true
|
||||||
|
|
||||||
|
doTestCommittingDocuments { rootDir, _ ->
|
||||||
|
val modulesWithJvmRuntime: List<Module>
|
||||||
|
val modulesWithJsRuntime: List<Module>
|
||||||
|
|
||||||
|
val withRuntime = config["withRuntime"]?.asBoolean ?: false
|
||||||
|
if (withRuntime) {
|
||||||
|
val moduleManager = ModuleManager.getInstance(project)
|
||||||
|
modulesWithJvmRuntime =
|
||||||
|
(config["modulesWithRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
|
||||||
|
?: moduleManager.modules.toList())
|
||||||
|
modulesWithJvmRuntime.forEach { ConfigLibraryUtil.configureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
|
||||||
|
modulesWithJsRuntime =
|
||||||
|
(config["modulesWithJsRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
|
||||||
|
?: emptyList())
|
||||||
|
modulesWithJsRuntime.forEach { ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
modulesWithJvmRuntime = emptyList()
|
||||||
|
modulesWithJsRuntime = emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
runMoveRefactoring(path, config, rootDir, project)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
modulesWithJvmRuntime.forEach {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk())
|
||||||
|
}
|
||||||
|
modulesWithJsRuntime.forEach {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun doTestCommittingDocuments(action : (VirtualFile, VirtualFile?) -> Unit) {
|
||||||
|
super.doTest({ rootDir, rootAfter ->
|
||||||
|
action(rootDir, rootAfter)
|
||||||
|
|
||||||
|
PsiDocumentManager.getInstance(project!!).commitAllDocuments()
|
||||||
|
FileDocumentManager.getInstance().saveAllDocuments()
|
||||||
|
}, getTestDirName(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun getTestDirName(lowercaseFirstLetter : Boolean) : String {
|
||||||
|
val testName = getTestName(lowercaseFirstLetter)
|
||||||
|
return testName.substring(0, testName.indexOf('_'))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -228,12 +228,6 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveDirectory/moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test")
|
|
||||||
public void testKotlin_moveDirectory_moveDirectoryKeepPackageDirective_MoveDirectoryKeepPackageDirective() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test")
|
@TestMetadata("kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test")
|
||||||
public void testKotlin_moveDirectory_moveDirectoryWithPackageDirectiveChange_MoveDirectoryWithPackageDirectiveChange() throws Exception {
|
public void testKotlin_moveDirectory_moveDirectoryWithPackageDirectiveChange_MoveDirectoryWithPackageDirectiveChange() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test");
|
||||||
@@ -522,12 +516,6 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveFileWithDeclarationsToUnrelatedModuleConflict_MoveFileWithDeclarationsToUnrelatedModuleConflict() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveFromDefaultPackage/moveFromDefaultPackage.test")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveFromDefaultPackage/moveFromDefaultPackage.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveFromDefaultPackage_MoveFromDefaultPackage() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_misc_moveFromDefaultPackage_MoveFromDefaultPackage() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveFromDefaultPackage/moveFromDefaultPackage.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveFromDefaultPackage/moveFromDefaultPackage.test");
|
||||||
@@ -540,24 +528,6 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveInternalToAnotherModule/moveInternalToAnotherModule.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveInternalToAnotherModule_MoveInternalToAnotherModule() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveInternalToAnotherModule/moveInternalToAnotherModule.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveToModuleWithoutLibConflict_MoveToModuleWithoutLibConflict() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveToUnrelatedModuleConflict_MoveToUnrelatedModuleConflict() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/selfReferences/selfReferences.test")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/selfReferences/selfReferences.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_selfReferences_SelfReferences() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_misc_selfReferences_SelfReferences() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/selfReferences/selfReferences.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/selfReferences/selfReferences.test");
|
||||||
@@ -594,12 +564,6 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/visibilityConflictInImport/visibilityConflictInImport.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_visibilityConflictInImport_VisibilityConflictInImport() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/visibilityConflictInImport/visibilityConflictInImport.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/moveClassToFile/moveClassToFile.test")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/moveClassToFile/moveClassToFile.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_moveClassToFile_MoveClassToFile() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_moveClassToFile_MoveClassToFile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/moveClassToFile.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToFile/moveClassToFile.test");
|
||||||
@@ -636,18 +600,6 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/moveFromJsModuleToJvmModule/moveFromJsModuleToJvmModule.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_moveFromJsModuleToJvmModule_MoveFromJsModuleToJvmModule() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFromJsModuleToJvmModule/moveFromJsModuleToJvmModule.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/moveFromJvmModuleToJsModule/moveFromJvmModuleToJsModule.test")
|
|
||||||
public void testKotlin_moveTopLevelDeclarations_moveFromJvmModuleToJsModule_MoveFromJvmModuleToJsModule() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFromJvmModuleToJsModule/moveFromJvmModuleToJsModule.test");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/moveFunctionToFile/moveFunctionToFile.test")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/moveFunctionToFile/moveFunctionToFile.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_moveFunctionToFile_MoveFunctionToFile() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_moveFunctionToFile_MoveFunctionToFile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/moveFunctionToFile.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToFile/moveFunctionToFile.test");
|
||||||
|
|||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.refactoring.move;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/refactoring/moveMultiModule")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public class MultiModuleMoveTestGenerated extends AbstractMultiModuleMoveTest {
|
||||||
|
public void testAllFilesPresentInMoveMultiModule() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/refactoring/moveMultiModule"), Pattern.compile("^(.+)\\.test$"), TargetBackend.ANY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test")
|
||||||
|
public void testMoveDirectoryKeepPackageDirective_MoveDirectoryKeepPackageDirective() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test")
|
||||||
|
public void testMoveFileWithDeclarationsToUnrelatedModuleConflict_MoveFileWithDeclarationsToUnrelatedModuleConflict() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveFromJsModuleToJvmModule/moveFromJsModuleToJvmModule.test")
|
||||||
|
public void testMoveFromJsModuleToJvmModule_MoveFromJsModuleToJvmModule() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveFromJsModuleToJvmModule/moveFromJsModuleToJvmModule.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveFromJvmModuleToJsModule/moveFromJvmModuleToJsModule.test")
|
||||||
|
public void testMoveFromJvmModuleToJsModule_MoveFromJvmModuleToJsModule() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveFromJvmModuleToJsModule/moveFromJvmModuleToJsModule.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveInternalToAnotherModule/moveInternalToAnotherModule.test")
|
||||||
|
public void testMoveInternalToAnotherModule_MoveInternalToAnotherModule() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/moveInternalToAnotherModule.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test")
|
||||||
|
public void testMoveToModuleWithoutLibConflict_MoveToModuleWithoutLibConflict() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test")
|
||||||
|
public void testMoveToUnrelatedModuleConflict_MoveToUnrelatedModuleConflict() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("visibilityConflictInImport/visibilityConflictInImport.test")
|
||||||
|
public void testVisibilityConflictInImport_VisibilityConflictInImport() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/visibilityConflictInImport/visibilityConflictInImport.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user