diff --git a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleMPPModuleDataService.kt b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleMPPModuleDataService.kt index a5684b77d25..beb1378214a 100644 --- a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleMPPModuleDataService.kt +++ b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleMPPModuleDataService.kt @@ -23,6 +23,7 @@ import org.jetbrains.jps.model.java.JavaSourceRootType import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.kotlin.gradle.KotlinCompilation import org.jetbrains.kotlin.gradle.KotlinPlatform +import org.jetbrains.kotlin.idea.configuration.KotlinSourceSetDataService import java.io.File class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService() { @@ -58,6 +59,7 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService() { @@ -56,6 +57,7 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService() { @@ -58,6 +59,7 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService() { @@ -58,6 +59,7 @@ class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService KotlinModuleKind.COMPILATION_AND_SOURCE_SET_HOLDER - is KotlinSourceSet -> KotlinModuleKind.SOURCE_SET_HOLDER - else -> KotlinModuleKind.DEFAULT - } - - private fun configureFacet( - sourceSetData: GradleSourceSetData, - kotlinSourceSet: KotlinSourceSetInfo, - mainModuleNode: DataNode, - ideModule: Module, - modelsProvider: IdeModifiableModelsProvider - ) { - val compilerVersion = mainModuleNode - .findAll(BuildScriptClasspathData.KEY) - .firstOrNull() - ?.data - ?.let { findKotlinPluginVersion(it) } ?: return - - val platformKind = IdePlatformKindTooling.getTooling(kotlinSourceSet.platform).kind - val platform = when (platformKind) { - is JvmIdePlatformKind -> { - val target = JvmTarget.fromString(sourceSetData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT - JvmIdePlatformKind.Platform(target) + companion object { + private val KotlinModule.kind + get() = when (this) { + is KotlinCompilation -> KotlinModuleKind.COMPILATION_AND_SOURCE_SET_HOLDER + is KotlinSourceSet -> KotlinModuleKind.SOURCE_SET_HOLDER + else -> KotlinModuleKind.DEFAULT } - else -> platformKind.defaultPlatform - } - val coroutinesProperty = CoroutineSupport.byCompilerArgument( - mainModuleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project) - ) + fun configureFacet( + moduleData: ModuleData, + kotlinSourceSet: KotlinSourceSetInfo, + mainModuleNode: DataNode, + ideModule: Module, + modelsProvider: IdeModifiableModelsProvider + ) { + val compilerVersion = mainModuleNode + .findAll(BuildScriptClasspathData.KEY) + .firstOrNull() + ?.data + ?.let { findKotlinPluginVersion(it) } ?: return - val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false) - kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platform, modelsProvider) + val platformKind = IdePlatformKindTooling.getTooling(kotlinSourceSet.platform).kind + val platform = when (platformKind) { + is JvmIdePlatformKind -> { + val target = JvmTarget.fromString(moduleData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT + JvmIdePlatformKind.Platform(target) + } + else -> platformKind.defaultPlatform + } - val compilerArguments = kotlinSourceSet.compilerArguments - val defaultCompilerArguments = kotlinSourceSet.defaultCompilerArguments - if (compilerArguments != null) { - applyCompilerArgumentsToFacet( - compilerArguments, - defaultCompilerArguments, - kotlinFacet, - modelsProvider + val coroutinesProperty = CoroutineSupport.byCompilerArgument( + mainModuleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project) ) - } - adjustClasspath(kotlinFacet, kotlinSourceSet.dependencyClasspath) + val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false) + kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platform, modelsProvider) - kotlinFacet.noVersionAutoAdvance() - - with(kotlinFacet.configuration.settings) { - kind = kotlinSourceSet.kotlinModule.kind - - isTestModule = kotlinSourceSet.isTestModule - - sourceSetNames = kotlinSourceSet.sourceSetIdsByName.values.mapNotNull { sourceSetId -> - val node = mainModuleNode.findChildModuleById(sourceSetId) ?: return@mapNotNull null - val data = node.data as? ModuleData ?: return@mapNotNull null - modelsProvider.findIdeModule(data)?.name + val compilerArguments = kotlinSourceSet.compilerArguments + val defaultCompilerArguments = kotlinSourceSet.defaultCompilerArguments + if (compilerArguments != null) { + applyCompilerArgumentsToFacet( + compilerArguments, + defaultCompilerArguments, + kotlinFacet, + modelsProvider + ) } - if (kotlinSourceSet.isTestModule) { - testOutputPath = (kotlinSourceSet.compilerArguments as? K2JSCompilerArguments)?.outputFile - productionOutputPath = null - } else { - productionOutputPath = (kotlinSourceSet.compilerArguments as? K2JSCompilerArguments)?.outputFile - testOutputPath = null + adjustClasspath(kotlinFacet, kotlinSourceSet.dependencyClasspath) + + kotlinFacet.noVersionAutoAdvance() + + with(kotlinFacet.configuration.settings) { + kind = kotlinSourceSet.kotlinModule.kind + + isTestModule = kotlinSourceSet.isTestModule + + sourceSetNames = kotlinSourceSet.sourceSetIdsByName.values.mapNotNull { sourceSetId -> + val node = mainModuleNode.findChildModuleById(sourceSetId) ?: return@mapNotNull null + val data = node.data as? ModuleData ?: return@mapNotNull null + modelsProvider.findIdeModule(data)?.name + } + + if (kotlinSourceSet.isTestModule) { + testOutputPath = (kotlinSourceSet.compilerArguments as? K2JSCompilerArguments)?.outputFile + productionOutputPath = null + } else { + productionOutputPath = (kotlinSourceSet.compilerArguments as? K2JSCompilerArguments)?.outputFile + testOutputPath = null + } } } }