Move: Do not consider type alias -> expect class change as a conflict

Given they have the same fqname

 #KT-23594 Fixed
This commit is contained in:
Alexey Sedunov
2018-07-11 13:21:28 +03:00
parent 1c30a12d95
commit 5275e19c76
14 changed files with 154 additions and 6 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor
import com.intellij.openapi.vfs.VfsUtil
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.test.InTextDirectivesUtils
@@ -44,6 +45,7 @@ object ConfigLibraryUtil {
private val DEFAULT_JAVA_RUNTIME_LIB_NAME = "JAVA_RUNTIME_LIB_NAME"
private val DEFAULT_KOTLIN_TEST_LIB_NAME = "KOTLIN_TEST_LIB_NAME"
private val DEFAULT_KOTLIN_JS_STDLIB_NAME = "KOTLIN_JS_STDLIB_NAME"
private val DEFAULT_KOTLIN_COMMON_STDLIB_NAME = "KOTLIN_COMMON_STDLIB_NAME"
private fun getKotlinRuntimeLibEditor(libName: String, library: File): NewLibraryEditor {
val editor = NewLibraryEditor()
@@ -65,6 +67,17 @@ object ConfigLibraryUtil {
JSLibraryKind)
}
fun configureKotlinCommonRuntime(module: Module) {
addLibrary(
getKotlinRuntimeLibEditor(
DEFAULT_KOTLIN_COMMON_STDLIB_NAME,
File("dist/common/kotlin-stdlib-common.jar")
),
module,
CommonLibraryKind
)
}
fun configureKotlinRuntime(module: Module) {
addLibrary(getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME, PathUtil.kotlinPathsForDistDirectory.stdlibPath), module)
addLibrary(getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_TEST_LIB_NAME, PathUtil.kotlinPathsForDistDirectory.kotlinTestPath), module)
@@ -85,6 +98,10 @@ object ConfigLibraryUtil {
removeLibrary(module, DEFAULT_KOTLIN_JS_STDLIB_NAME)
}
fun unConfigureKotlinCommonRuntime(module: Module) {
removeLibrary(module, DEFAULT_KOTLIN_COMMON_STDLIB_NAME)
}
fun configureSdk(module: Module, sdk: Sdk) {
ApplicationManager.getApplication().runWriteAction {
val rootManager = ModuleRootManager.getInstance(module)
@@ -285,8 +285,6 @@ class MoveConflictChecker(
val fqName = targetDescriptor.importableFqName ?: return true
val importableDescriptor = targetDescriptor.getImportableDescriptor()
val renderedImportableTarget = DESCRIPTOR_RENDERER_FOR_COMPARISON.render(importableDescriptor)
val renderedTarget by lazy { DESCRIPTOR_RENDERER_FOR_COMPARISON.render(targetDescriptor) }
val targetModuleInfo = getModuleInfoByVirtualFile(project, targetScope)
val dummyFile = KtPsiFactory(targetElement.project).createFile("dummy.kt", "").apply {
@@ -296,6 +294,14 @@ class MoveConflictChecker(
val newTargetDescriptors = dummyFile.resolveImportReference(fqName)
if (importableDescriptor is TypeAliasDescriptor
&& newTargetDescriptors.any {
it is ClassDescriptor && it.isExpect && it.importableFqName == importableDescriptor.importableFqName
}) return true
val renderedImportableTarget = DESCRIPTOR_RENDERER_FOR_COMPARISON.render(importableDescriptor)
val renderedTarget by lazy { DESCRIPTOR_RENDERER_FOR_COMPARISON.render(targetDescriptor) }
return newTargetDescriptors.any {
if (DESCRIPTOR_RENDERER_FOR_COMPARISON.render(it) != renderedImportableTarget) return@any false
if (importableDescriptor == targetDescriptor) return@any true
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<option name="multiPlatform" value="true" />
</compilerArguments>
</configuration>
</facet>
</component>
</module>
@@ -0,0 +1,5 @@
class Foo {
fun foo() {
throw IllegalStateException()
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="A" scope="COMPILE" />
</component>
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
<implements>A</implements>
<compilerSettings />
<compilerArguments>
<option name="multiPlatform" value="true" />
</compilerArguments>
</configuration>
</facet>
</component>
</module>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<option name="multiPlatform" value="true" />
</compilerArguments>
</configuration>
</facet>
</component>
</module>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="A" scope="COMPILE" />
</component>
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
<implements>A</implements>
<compilerSettings />
<compilerArguments>
<option name="multiPlatform" value="true" />
</compilerArguments>
</configuration>
</facet>
</component>
</module>
@@ -0,0 +1,7 @@
class <caret>Foo {
fun foo() {
throw IllegalStateException()
}
}
class Bar
@@ -0,0 +1,9 @@
{
"mainFile": "B/src/test.kt",
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
"targetPackage": "",
"targetSourceRoot": "A/src",
"withRuntime": "true",
"modulesWithRuntime": ["B"],
"modulesWithCommonRuntime": ["A"]
}
@@ -37,6 +37,7 @@ abstract class AbstractMultiModuleMoveTest : KotlinMultiFileTestCase() {
doTestCommittingDocuments { rootDir, _ ->
val modulesWithJvmRuntime: List<Module>
val modulesWithJsRuntime: List<Module>
val modulesWithCommonRuntime: List<Module>
PluginTestCaseBase.addJdk(testRootDisposable, PluginTestCaseBase::mockJdk)
@@ -45,16 +46,22 @@ abstract class AbstractMultiModuleMoveTest : KotlinMultiFileTestCase() {
val moduleManager = ModuleManager.getInstance(project)
modulesWithJvmRuntime =
(config["modulesWithRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
?: moduleManager.modules.toList())
?: moduleManager.modules.toList())
modulesWithJvmRuntime.forEach { ConfigLibraryUtil.configureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
modulesWithJsRuntime =
(config["modulesWithJsRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
?: emptyList())
?: emptyList())
modulesWithJsRuntime.forEach { ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
}
else {
modulesWithCommonRuntime =
(config["modulesWithCommonRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
?: emptyList())
modulesWithCommonRuntime.forEach { ConfigLibraryUtil.configureKotlinCommonRuntime(it) }
} else {
modulesWithJvmRuntime = emptyList()
modulesWithJsRuntime = emptyList()
modulesWithCommonRuntime = emptyList()
}
try {
@@ -67,6 +74,9 @@ abstract class AbstractMultiModuleMoveTest : KotlinMultiFileTestCase() {
modulesWithJsRuntime.forEach {
ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(it, PluginTestCaseBase.mockJdk())
}
modulesWithCommonRuntime.forEach {
ConfigLibraryUtil.unConfigureKotlinCommonRuntime(it)
}
}
}
}
@@ -84,6 +84,11 @@ public class MultiModuleMoveTestGenerated extends AbstractMultiModuleMoveTest {
runTest("idea/testData/refactoring/moveMultiModule/movePackageToUnrelatedModuleConflict/movePackageToUnrelatedModuleConflict.test");
}
@TestMetadata("moveRefToLibTypeAliasImplementingLibExpectClass/moveRefToLibTypeAliasImplementingLibExpectClass.test")
public void testMoveRefToLibTypeAliasImplementingLibExpectClass_MoveRefToLibTypeAliasImplementingLibExpectClass() throws Exception {
runTest("idea/testData/refactoring/moveMultiModule/moveRefToLibTypeAliasImplementingLibExpectClass/moveRefToLibTypeAliasImplementingLibExpectClass.test");
}
@TestMetadata("moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test")
public void testMoveToModuleWithoutLibConflict_MoveToModuleWithoutLibConflict() throws Exception {
runTest("idea/testData/refactoring/moveMultiModule/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test");