Reformat & cleanup: KotlinGradleSourceSetDataService
This commit is contained in:
+30
-27
@@ -54,8 +54,8 @@ import java.util.*
|
||||
|
||||
interface GradleProjectImportHandler {
|
||||
companion object : ProjectExtensionDescriptor<GradleProjectImportHandler>(
|
||||
"org.jetbrains.kotlin.gradleProjectImportHandler",
|
||||
GradleProjectImportHandler::class.java
|
||||
"org.jetbrains.kotlin.gradleProjectImportHandler",
|
||||
GradleProjectImportHandler::class.java
|
||||
)
|
||||
|
||||
fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>)
|
||||
@@ -66,10 +66,10 @@ class KotlinGradleSourceSetDataService : AbstractProjectDataService<GradleSource
|
||||
override fun getTargetDataKey() = GradleSourceSetData.KEY
|
||||
|
||||
override fun postProcess(
|
||||
toImport: Collection<DataNode<GradleSourceSetData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
toImport: Collection<DataNode<GradleSourceSetData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
for (sourceSetNode in toImport) {
|
||||
val sourceSetData = sourceSetNode.data
|
||||
@@ -86,10 +86,10 @@ class KotlinGradleProjectDataService : AbstractProjectDataService<ModuleData, Vo
|
||||
override fun getTargetDataKey() = ProjectKeys.MODULE
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<ModuleData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
toImport: MutableCollection<DataNode<ModuleData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
for (moduleNode in toImport) {
|
||||
// If source sets are present, configure facets in the their modules
|
||||
@@ -107,13 +107,14 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
|
||||
override fun getTargetDataKey() = ProjectKeys.LIBRARY
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<LibraryData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
toImport: MutableCollection<DataNode<LibraryData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
if (toImport.isEmpty()) return
|
||||
val projectDataNode = toImport.first().parent!! as DataNode<ProjectData>
|
||||
val projectDataNode = toImport.first().parent!!
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val moduleDataNodes = projectDataNode.children.filter { it.data is ModuleData } as List<DataNode<ModuleData>>
|
||||
val anyNonJvmModules = moduleDataNodes.any { detectPlatformByPlugin(it)?.takeIf { it !is TargetPlatformKind.Jvm } != null }
|
||||
for (libraryDataNode in toImport) {
|
||||
@@ -122,8 +123,7 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
|
||||
val modifiableModel = modelsProvider.getModifiableLibraryModel(ideLibrary) as LibraryEx.ModifiableModelEx
|
||||
if (anyNonJvmModules || ideLibrary.name?.looksAsNonJvmLibraryName() == true) {
|
||||
detectLibraryKind(modifiableModel.getFiles(OrderRootType.CLASSES))?.let { modifiableModel.kind = it }
|
||||
}
|
||||
else if (ideLibrary is LibraryImpl && (ideLibrary.kind is JSLibraryKind || ideLibrary.kind is CommonLibraryKind)) {
|
||||
} else if (ideLibrary is LibraryImpl && (ideLibrary.kind === JSLibraryKind || ideLibrary.kind === CommonLibraryKind)) {
|
||||
resetLibraryKind(modifiableModel)
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,7 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
|
||||
}
|
||||
}
|
||||
LOG.info("Could not find field of type PersistentLibraryKind in LibraryImpl.class")
|
||||
}
|
||||
catch (e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
LOG.info("Failed to reset library kind", e)
|
||||
}
|
||||
}
|
||||
@@ -166,15 +165,18 @@ fun detectPlatformByPlugin(moduleNode: DataNode<ModuleData>): TargetPlatformKind
|
||||
}
|
||||
|
||||
private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): TargetPlatformKind<*>? {
|
||||
val detectedPlatforms = mavenLibraryIdToPlatform.entries.filter { moduleNode.getResolvedKotlinStdlibVersionByModuleData(listOf(it.key)) != null }.map { it.value }.distinct()
|
||||
val detectedPlatforms =
|
||||
mavenLibraryIdToPlatform.entries
|
||||
.filter { moduleNode.getResolvedKotlinStdlibVersionByModuleData(listOf(it.key)) != null }
|
||||
.map { it.value }.distinct()
|
||||
return detectedPlatforms.singleOrNull() ?: detectedPlatforms.firstOrNull { it != TargetPlatformKind.Common }
|
||||
}
|
||||
|
||||
private fun configureFacetByGradleModule(
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
sourceSetNode: DataNode<GradleSourceSetData>?,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
sourceSetNode: DataNode<GradleSourceSetData>?,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
): KotlinFacet? {
|
||||
if (!moduleNode.isResolved) return null
|
||||
|
||||
@@ -188,11 +190,12 @@ private fun configureFacetByGradleModule(
|
||||
}
|
||||
|
||||
val compilerVersion = moduleNode.findAll(BuildScriptClasspathData.KEY).firstOrNull()?.data?.let(::findKotlinPluginVersion)
|
||||
?: return null
|
||||
?: return null
|
||||
val platformKind = detectPlatformByPlugin(moduleNode) ?: detectPlatformByLibrary(moduleNode)
|
||||
|
||||
val coroutinesProperty = CoroutineSupport.byCompilerArgument(
|
||||
moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project))
|
||||
moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project)
|
||||
)
|
||||
|
||||
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false)
|
||||
kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platformKind, modelsProvider)
|
||||
@@ -222,7 +225,7 @@ private fun configureFacetByGradleModule(
|
||||
}
|
||||
|
||||
private fun getExplicitOutputPath(moduleNode: DataNode<ModuleData>, platformKind: TargetPlatformKind<*>?, sourceSet: String): String? {
|
||||
if (platformKind !is TargetPlatformKind.JavaScript) return null
|
||||
if (platformKind !== TargetPlatformKind.JavaScript) return null
|
||||
val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get(sourceSet)?.currentArguments ?: return null
|
||||
return K2JSCompilerArguments().apply { parseCommandLineArguments(k2jsArgumentList, this) }.outputFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user