Merge remote-tracking branch 'origin/master' into ank/studio-430
[idea/community.git] / plugins / kotlin / gradle / gradle-idea / src / org / jetbrains / kotlin / idea / gradle / configuration / KotlinDataNodes.kt
1 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package org.jetbrains.kotlin.idea.gradle.configuration
3
4 import com.intellij.openapi.externalSystem.model.DataNode
5 import com.intellij.openapi.externalSystem.model.Key
6 import com.intellij.openapi.externalSystem.model.ProjectKeys
7 import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData
8 import com.intellij.openapi.externalSystem.model.project.AbstractNamedData
9 import com.intellij.openapi.externalSystem.model.project.ModuleData
10 import com.intellij.openapi.externalSystem.model.project.ProjectData
11 import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
12 import com.intellij.openapi.util.IntellijInternalApi
13 import com.intellij.serialization.PropertyMapping
14 import org.jetbrains.kotlin.gradle.ArgsInfo
15 import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
16 import org.jetbrains.plugins.gradle.util.GradleConstants
17 import java.io.Serializable
18
19 interface ImplementedModulesAware : Serializable {
20     var implementedModuleNames: List<String>
21 }
22
23 class KotlinGradleProjectData : AbstractExternalEntityData(GradleConstants.SYSTEM_ID), ImplementedModulesAware {
24     var isResolved: Boolean = false
25     var kotlinTarget: String? = null
26     var hasKotlinPlugin: Boolean = false
27     var coroutines: String? = null
28     var isHmpp: Boolean = false
29     var platformPluginId: String? = null
30     lateinit var kotlinNativeHome: String
31     override var implementedModuleNames: List<String> = emptyList()
32
33     @Transient
34     val dependenciesCache: MutableMap<DataNode<ProjectData>, Collection<DataNode<out ModuleData>>> = mutableMapOf()
35     val pureKotlinSourceFolders: MutableCollection<String> = hashSetOf()
36
37     companion object {
38         val KEY = Key.create(KotlinGradleProjectData::class.java, ProjectKeys.MODULE.processingWeight + 1)
39     }
40 }
41
42 @IntellijInternalApi
43 val DataNode<GradleSourceSetData>.kotlinGradleSourceSetDataOrFail: KotlinGradleSourceSetData
44     get() = kotlinGradleSourceSetDataOrNull ?: error("Failed to determine KotlinGradleSourceSetData for $this")
45
46 internal val DataNode<GradleSourceSetData>.kotlinGradleSourceSetDataOrNull: KotlinGradleSourceSetData?
47     get() = ExternalSystemApiUtil.getChildren(this, KotlinGradleSourceSetData.KEY).singleOrNull()?.data
48
49 class KotlinGradleSourceSetData @PropertyMapping("externalName") constructor(externalName: String) :
50     AbstractNamedData(GradleConstants.SYSTEM_ID, externalName), ImplementedModulesAware {
51
52     val sourceSetName: String
53         get() = externalName.substringAfterLast(":")
54
55     lateinit var compilerArguments: ArgsInfo
56     lateinit var additionalVisibleSourceSets: Set<String>
57     override var implementedModuleNames: List<String> = emptyList()
58
59     companion object {
60         val KEY = Key.create(KotlinGradleSourceSetData::class.java, KotlinGradleProjectData.KEY.processingWeight + 1)
61     }
62 }
63