Minor: reformat and clean-up facetUtils.kt
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.idea.facet
|
package org.jetbrains.kotlin.idea.facet
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
|
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk
|
import com.intellij.openapi.projectRoots.JavaSdk
|
||||||
@@ -25,24 +24,17 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion
|
|||||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||||
import com.intellij.openapi.roots.ModuleRootManager
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import com.intellij.openapi.roots.ModuleRootModel
|
import com.intellij.openapi.roots.ModuleRootModel
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.psi.util.CachedValueProvider
|
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
|
||||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||||
import org.jetbrains.kotlin.config.*
|
import org.jetbrains.kotlin.config.*
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.caches.project.*
|
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
|
||||||
import org.jetbrains.kotlin.idea.versions.*
|
import org.jetbrains.kotlin.idea.versions.*
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
@@ -62,10 +54,10 @@ private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacetSettings.initializeIfNeeded(
|
fun KotlinFacetSettings.initializeIfNeeded(
|
||||||
module: Module,
|
module: Module,
|
||||||
rootModel: ModuleRootModel?,
|
rootModel: ModuleRootModel?,
|
||||||
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
||||||
languageVersion: String? = null
|
languageVersion: String? = null
|
||||||
) {
|
) {
|
||||||
val project = module.project
|
val project = module.project
|
||||||
|
|
||||||
@@ -88,14 +80,13 @@ fun KotlinFacetSettings.initializeIfNeeded(
|
|||||||
|
|
||||||
if (shouldInferLanguageLevel) {
|
if (shouldInferLanguageLevel) {
|
||||||
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
||||||
?: getDefaultLanguageLevel(module, languageVersion)
|
?: getDefaultLanguageLevel(module, languageVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInferAPILevel) {
|
if (shouldInferAPILevel) {
|
||||||
apiLevel = if (useProjectSettings) {
|
apiLevel = if (useProjectSettings) {
|
||||||
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,26 +102,34 @@ fun TargetPlatformKind<*>.getPlatformCompilerArgumentsByProject(project: Project
|
|||||||
|
|
||||||
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
is TargetPlatformKind.Jvm -> listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)
|
is TargetPlatformKind.Jvm -> listOf(
|
||||||
|
MAVEN_STDLIB_ID,
|
||||||
|
MAVEN_STDLIB_ID_JRE7,
|
||||||
|
MAVEN_STDLIB_ID_JDK7,
|
||||||
|
MAVEN_STDLIB_ID_JRE8,
|
||||||
|
MAVEN_STDLIB_ID_JDK8
|
||||||
|
)
|
||||||
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
||||||
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
||||||
TargetPlatformKind.ALL_PLATFORMS
|
TargetPlatformKind.ALL_PLATFORMS
|
||||||
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
||||||
.sortedByDescending { it.first.length }
|
.sortedByDescending { it.first.length }
|
||||||
.toMap()
|
.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
fun Module.getOrCreateFacet(
|
||||||
useProjectSettings: Boolean,
|
modelsProvider: IdeModifiableModelsProvider,
|
||||||
commitModel: Boolean = false): KotlinFacet {
|
useProjectSettings: Boolean,
|
||||||
|
commitModel: Boolean = false
|
||||||
|
): KotlinFacet {
|
||||||
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
||||||
|
|
||||||
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
||||||
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
||||||
.apply { facetModel.addFacet(this) }
|
.apply { facetModel.addFacet(this) }
|
||||||
facet.configuration.settings.useProjectSettings = useProjectSettings
|
facet.configuration.settings.useProjectSettings = useProjectSettings
|
||||||
if (commitModel) {
|
if (commitModel) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
@@ -141,20 +140,20 @@ fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String,
|
compilerVersion: String,
|
||||||
coroutineSupport: LanguageFeature.State,
|
coroutineSupport: LanguageFeature.State,
|
||||||
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
||||||
modelsProvider: IdeModifiableModelsProvider
|
modelsProvider: IdeModifiableModelsProvider
|
||||||
) {
|
) {
|
||||||
val module = module
|
val module = module
|
||||||
with(configuration.settings) {
|
with(configuration.settings) {
|
||||||
compilerArguments = null
|
compilerArguments = null
|
||||||
compilerSettings = null
|
compilerSettings = null
|
||||||
initializeIfNeeded(
|
initializeIfNeeded(
|
||||||
module,
|
module,
|
||||||
modelsProvider.getModifiableRootModel(module),
|
modelsProvider.getModifiableRootModel(module),
|
||||||
platformKind,
|
platformKind,
|
||||||
compilerVersion
|
compilerVersion
|
||||||
)
|
)
|
||||||
val apiLevel = apiLevel
|
val apiLevel = apiLevel
|
||||||
val languageLevel = languageLevel
|
val languageLevel = languageLevel
|
||||||
@@ -174,31 +173,41 @@ fun KotlinFacet.noVersionAutoAdvance() {
|
|||||||
|
|
||||||
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
||||||
// Update these lists when facet/project settings UI changes
|
// Update these lists when facet/project settings UI changes
|
||||||
val commonUIExposedFields = listOf(CommonCompilerArguments::languageVersion.name,
|
val commonUIExposedFields = listOf(
|
||||||
CommonCompilerArguments::apiVersion.name,
|
CommonCompilerArguments::languageVersion.name,
|
||||||
CommonCompilerArguments::suppressWarnings.name,
|
CommonCompilerArguments::apiVersion.name,
|
||||||
CommonCompilerArguments::coroutinesState.name)
|
CommonCompilerArguments::suppressWarnings.name,
|
||||||
private val commonUIHiddenFields = listOf(CommonCompilerArguments::pluginClasspaths.name,
|
CommonCompilerArguments::coroutinesState.name
|
||||||
CommonCompilerArguments::pluginOptions.name)
|
)
|
||||||
|
private val commonUIHiddenFields = listOf(
|
||||||
|
CommonCompilerArguments::pluginClasspaths.name,
|
||||||
|
CommonCompilerArguments::pluginOptions.name
|
||||||
|
)
|
||||||
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
||||||
|
|
||||||
private val jvmSpecificUIExposedFields = listOf(K2JVMCompilerArguments::jvmTarget.name,
|
private val jvmSpecificUIExposedFields = listOf(
|
||||||
K2JVMCompilerArguments::destination.name,
|
K2JVMCompilerArguments::jvmTarget.name,
|
||||||
K2JVMCompilerArguments::classpath.name)
|
K2JVMCompilerArguments::destination.name,
|
||||||
|
K2JVMCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
||||||
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
||||||
|
|
||||||
private val jsSpecificUIExposedFields = listOf(K2JSCompilerArguments::sourceMap.name,
|
private val jsSpecificUIExposedFields = listOf(
|
||||||
K2JSCompilerArguments::sourceMapPrefix.name,
|
K2JSCompilerArguments::sourceMap.name,
|
||||||
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
K2JSCompilerArguments::sourceMapPrefix.name,
|
||||||
K2JSCompilerArguments::outputPrefix.name,
|
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
||||||
K2JSCompilerArguments::outputPostfix.name,
|
K2JSCompilerArguments::outputPrefix.name,
|
||||||
K2JSCompilerArguments::moduleKind.name)
|
K2JSCompilerArguments::outputPostfix.name,
|
||||||
|
K2JSCompilerArguments::moduleKind.name
|
||||||
|
)
|
||||||
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
||||||
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
||||||
|
|
||||||
private val metadataSpecificUIExposedFields = listOf(K2MetadataCompilerArguments::destination.name,
|
private val metadataSpecificUIExposedFields = listOf(
|
||||||
K2MetadataCompilerArguments::classpath.name)
|
K2MetadataCompilerArguments::destination.name,
|
||||||
|
K2MetadataCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
||||||
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
||||||
|
|
||||||
@@ -236,10 +245,10 @@ private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArgum
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun parseCompilerArgumentsToFacet(
|
fun parseCompilerArgumentsToFacet(
|
||||||
arguments: List<String>,
|
arguments: List<String>,
|
||||||
defaultArguments: List<String>,
|
defaultArguments: List<String>,
|
||||||
kotlinFacet: KotlinFacet,
|
kotlinFacet: KotlinFacet,
|
||||||
modelsProvider: IdeModifiableModelsProvider
|
modelsProvider: IdeModifiableModelsProvider
|
||||||
) {
|
) {
|
||||||
with(kotlinFacet.configuration.settings) {
|
with(kotlinFacet.configuration.settings) {
|
||||||
val compilerArguments = this.compilerArguments ?: return
|
val compilerArguments = this.compilerArguments ?: return
|
||||||
@@ -261,7 +270,7 @@ fun parseCompilerArgumentsToFacet(
|
|||||||
val ignoredFields = compilerArguments.ignoredFields
|
val ignoredFields = compilerArguments.ignoredFields
|
||||||
|
|
||||||
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
||||||
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
||||||
|
|
||||||
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
||||||
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.idea.facet
|
package org.jetbrains.kotlin.idea.facet
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
|
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk
|
import com.intellij.openapi.projectRoots.JavaSdk
|
||||||
@@ -25,24 +24,17 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion
|
|||||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||||
import com.intellij.openapi.roots.ModuleRootManager
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import com.intellij.openapi.roots.ModuleRootModel
|
import com.intellij.openapi.roots.ModuleRootModel
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.psi.util.CachedValueProvider
|
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
|
||||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||||
import org.jetbrains.kotlin.config.*
|
import org.jetbrains.kotlin.config.*
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.caches.project.*
|
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
|
||||||
import org.jetbrains.kotlin.idea.versions.*
|
import org.jetbrains.kotlin.idea.versions.*
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
@@ -62,10 +54,10 @@ private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacetSettings.initializeIfNeeded(
|
fun KotlinFacetSettings.initializeIfNeeded(
|
||||||
module: Module,
|
module: Module,
|
||||||
rootModel: ModuleRootModel?,
|
rootModel: ModuleRootModel?,
|
||||||
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
||||||
languageVersion: String? = null
|
languageVersion: String? = null
|
||||||
) {
|
) {
|
||||||
val project = module.project
|
val project = module.project
|
||||||
|
|
||||||
@@ -88,14 +80,13 @@ fun KotlinFacetSettings.initializeIfNeeded(
|
|||||||
|
|
||||||
if (shouldInferLanguageLevel) {
|
if (shouldInferLanguageLevel) {
|
||||||
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
||||||
?: getDefaultLanguageLevel(module, languageVersion)
|
?: getDefaultLanguageLevel(module, languageVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInferAPILevel) {
|
if (shouldInferAPILevel) {
|
||||||
apiLevel = if (useProjectSettings) {
|
apiLevel = if (useProjectSettings) {
|
||||||
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,26 +102,34 @@ fun TargetPlatformKind<*>.getPlatformCompilerArgumentsByProject(project: Project
|
|||||||
|
|
||||||
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
is TargetPlatformKind.Jvm -> listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)
|
is TargetPlatformKind.Jvm -> listOf(
|
||||||
|
MAVEN_STDLIB_ID,
|
||||||
|
MAVEN_STDLIB_ID_JRE7,
|
||||||
|
MAVEN_STDLIB_ID_JDK7,
|
||||||
|
MAVEN_STDLIB_ID_JRE8,
|
||||||
|
MAVEN_STDLIB_ID_JDK8
|
||||||
|
)
|
||||||
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
||||||
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
||||||
TargetPlatformKind.ALL_PLATFORMS
|
TargetPlatformKind.ALL_PLATFORMS
|
||||||
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
||||||
.sortedByDescending { it.first.length }
|
.sortedByDescending { it.first.length }
|
||||||
.toMap()
|
.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
fun Module.getOrCreateFacet(
|
||||||
useProjectSettings: Boolean,
|
modelsProvider: IdeModifiableModelsProvider,
|
||||||
commitModel: Boolean = false): KotlinFacet {
|
useProjectSettings: Boolean,
|
||||||
|
commitModel: Boolean = false
|
||||||
|
): KotlinFacet {
|
||||||
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
||||||
|
|
||||||
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
||||||
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
||||||
.apply { facetModel.addFacet(this) }
|
.apply { facetModel.addFacet(this) }
|
||||||
facet.configuration.settings.useProjectSettings = useProjectSettings
|
facet.configuration.settings.useProjectSettings = useProjectSettings
|
||||||
if (commitModel) {
|
if (commitModel) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
@@ -141,20 +140,20 @@ fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String,
|
compilerVersion: String,
|
||||||
coroutineSupport: LanguageFeature.State,
|
coroutineSupport: LanguageFeature.State,
|
||||||
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
||||||
modelsProvider: IdeModifiableModelsProvider
|
modelsProvider: IdeModifiableModelsProvider
|
||||||
) {
|
) {
|
||||||
val module = module
|
val module = module
|
||||||
with(configuration.settings) {
|
with(configuration.settings) {
|
||||||
compilerArguments = null
|
compilerArguments = null
|
||||||
compilerSettings = null
|
compilerSettings = null
|
||||||
initializeIfNeeded(
|
initializeIfNeeded(
|
||||||
module,
|
module,
|
||||||
modelsProvider.getModifiableRootModel(module),
|
modelsProvider.getModifiableRootModel(module),
|
||||||
platformKind,
|
platformKind,
|
||||||
compilerVersion
|
compilerVersion
|
||||||
)
|
)
|
||||||
val apiLevel = apiLevel
|
val apiLevel = apiLevel
|
||||||
val languageLevel = languageLevel
|
val languageLevel = languageLevel
|
||||||
@@ -174,31 +173,41 @@ fun KotlinFacet.noVersionAutoAdvance() {
|
|||||||
|
|
||||||
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
||||||
// Update these lists when facet/project settings UI changes
|
// Update these lists when facet/project settings UI changes
|
||||||
val commonUIExposedFields = listOf(CommonCompilerArguments::languageVersion.name,
|
val commonUIExposedFields = listOf(
|
||||||
CommonCompilerArguments::apiVersion.name,
|
CommonCompilerArguments::languageVersion.name,
|
||||||
CommonCompilerArguments::suppressWarnings.name,
|
CommonCompilerArguments::apiVersion.name,
|
||||||
CommonCompilerArguments::coroutinesState.name)
|
CommonCompilerArguments::suppressWarnings.name,
|
||||||
private val commonUIHiddenFields = listOf(CommonCompilerArguments::pluginClasspaths.name,
|
CommonCompilerArguments::coroutinesState.name
|
||||||
CommonCompilerArguments::pluginOptions.name)
|
)
|
||||||
|
private val commonUIHiddenFields = listOf(
|
||||||
|
CommonCompilerArguments::pluginClasspaths.name,
|
||||||
|
CommonCompilerArguments::pluginOptions.name
|
||||||
|
)
|
||||||
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
||||||
|
|
||||||
private val jvmSpecificUIExposedFields = listOf(K2JVMCompilerArguments::jvmTarget.name,
|
private val jvmSpecificUIExposedFields = listOf(
|
||||||
K2JVMCompilerArguments::destination.name,
|
K2JVMCompilerArguments::jvmTarget.name,
|
||||||
K2JVMCompilerArguments::classpath.name)
|
K2JVMCompilerArguments::destination.name,
|
||||||
|
K2JVMCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
||||||
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
||||||
|
|
||||||
private val jsSpecificUIExposedFields = listOf(K2JSCompilerArguments::sourceMap.name,
|
private val jsSpecificUIExposedFields = listOf(
|
||||||
K2JSCompilerArguments::sourceMapPrefix.name,
|
K2JSCompilerArguments::sourceMap.name,
|
||||||
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
K2JSCompilerArguments::sourceMapPrefix.name,
|
||||||
K2JSCompilerArguments::outputPrefix.name,
|
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
||||||
K2JSCompilerArguments::outputPostfix.name,
|
K2JSCompilerArguments::outputPrefix.name,
|
||||||
K2JSCompilerArguments::moduleKind.name)
|
K2JSCompilerArguments::outputPostfix.name,
|
||||||
|
K2JSCompilerArguments::moduleKind.name
|
||||||
|
)
|
||||||
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
||||||
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
||||||
|
|
||||||
private val metadataSpecificUIExposedFields = listOf(K2MetadataCompilerArguments::destination.name,
|
private val metadataSpecificUIExposedFields = listOf(
|
||||||
K2MetadataCompilerArguments::classpath.name)
|
K2MetadataCompilerArguments::destination.name,
|
||||||
|
K2MetadataCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
||||||
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
||||||
|
|
||||||
@@ -223,23 +232,23 @@ private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArgum
|
|||||||
allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 } ?: return
|
allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 } ?: return
|
||||||
} else {
|
} else {
|
||||||
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
|
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
|
||||||
?: modelsProvider
|
?: modelsProvider
|
||||||
.modifiableModuleModel
|
.modifiableModuleModel
|
||||||
.modules
|
.modules
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
|
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
|
||||||
.firstOrNull { it.sdkType is KotlinSdkType }
|
.firstOrNull { it.sdkType is KotlinSdkType }
|
||||||
?: KotlinSdkType.INSTANCE.createSdkWithUniqueName(allSdks.toList())
|
?: KotlinSdkType.INSTANCE.createSdkWithUniqueName(allSdks.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
modelsProvider.getModifiableRootModel(this).sdk = sdk
|
modelsProvider.getModifiableRootModel(this).sdk = sdk
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseCompilerArgumentsToFacet(
|
fun parseCompilerArgumentsToFacet(
|
||||||
arguments: List<String>,
|
arguments: List<String>,
|
||||||
defaultArguments: List<String>,
|
defaultArguments: List<String>,
|
||||||
kotlinFacet: KotlinFacet,
|
kotlinFacet: KotlinFacet,
|
||||||
modelsProvider: IdeModifiableModelsProvider?
|
modelsProvider: IdeModifiableModelsProvider?
|
||||||
) {
|
) {
|
||||||
with(kotlinFacet.configuration.settings) {
|
with(kotlinFacet.configuration.settings) {
|
||||||
val compilerArguments = this.compilerArguments ?: return
|
val compilerArguments = this.compilerArguments ?: return
|
||||||
@@ -262,7 +271,7 @@ fun parseCompilerArgumentsToFacet(
|
|||||||
val ignoredFields = compilerArguments.ignoredFields
|
val ignoredFields = compilerArguments.ignoredFields
|
||||||
|
|
||||||
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
||||||
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
||||||
|
|
||||||
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
||||||
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.idea.facet
|
package org.jetbrains.kotlin.idea.facet
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
|
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk
|
import com.intellij.openapi.projectRoots.JavaSdk
|
||||||
@@ -25,24 +24,17 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion
|
|||||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||||
import com.intellij.openapi.roots.ModuleRootManager
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import com.intellij.openapi.roots.ModuleRootModel
|
import com.intellij.openapi.roots.ModuleRootModel
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.psi.util.CachedValueProvider
|
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
|
||||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||||
import org.jetbrains.kotlin.config.*
|
import org.jetbrains.kotlin.config.*
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.caches.project.*
|
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
|
||||||
import org.jetbrains.kotlin.idea.versions.*
|
import org.jetbrains.kotlin.idea.versions.*
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
@@ -62,10 +54,10 @@ private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacetSettings.initializeIfNeeded(
|
fun KotlinFacetSettings.initializeIfNeeded(
|
||||||
module: Module,
|
module: Module,
|
||||||
rootModel: ModuleRootModel?,
|
rootModel: ModuleRootModel?,
|
||||||
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies
|
||||||
languageVersion: String? = null
|
languageVersion: String? = null
|
||||||
) {
|
) {
|
||||||
val project = module.project
|
val project = module.project
|
||||||
|
|
||||||
@@ -88,14 +80,13 @@ fun KotlinFacetSettings.initializeIfNeeded(
|
|||||||
|
|
||||||
if (shouldInferLanguageLevel) {
|
if (shouldInferLanguageLevel) {
|
||||||
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
|
||||||
?: getDefaultLanguageLevel(module, languageVersion)
|
?: getDefaultLanguageLevel(module, languageVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInferAPILevel) {
|
if (shouldInferAPILevel) {
|
||||||
apiLevel = if (useProjectSettings) {
|
apiLevel = if (useProjectSettings) {
|
||||||
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,26 +102,34 @@ fun TargetPlatformKind<*>.getPlatformCompilerArgumentsByProject(project: Project
|
|||||||
|
|
||||||
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
is TargetPlatformKind.Jvm -> listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)
|
is TargetPlatformKind.Jvm -> listOf(
|
||||||
|
MAVEN_STDLIB_ID,
|
||||||
|
MAVEN_STDLIB_ID_JRE7,
|
||||||
|
MAVEN_STDLIB_ID_JDK7,
|
||||||
|
MAVEN_STDLIB_ID_JRE8,
|
||||||
|
MAVEN_STDLIB_ID_JDK8
|
||||||
|
)
|
||||||
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
|
||||||
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
||||||
TargetPlatformKind.ALL_PLATFORMS
|
TargetPlatformKind.ALL_PLATFORMS
|
||||||
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
||||||
.sortedByDescending { it.first.length }
|
.sortedByDescending { it.first.length }
|
||||||
.toMap()
|
.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
fun Module.getOrCreateFacet(
|
||||||
useProjectSettings: Boolean,
|
modelsProvider: IdeModifiableModelsProvider,
|
||||||
commitModel: Boolean = false): KotlinFacet {
|
useProjectSettings: Boolean,
|
||||||
|
commitModel: Boolean = false
|
||||||
|
): KotlinFacet {
|
||||||
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
||||||
|
|
||||||
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
val facet = facetModel.findFacet(KotlinFacetType.TYPE_ID, KotlinFacetType.INSTANCE.defaultFacetName)
|
||||||
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
?: with(KotlinFacetType.INSTANCE) { createFacet(this@getOrCreateFacet, defaultFacetName, createDefaultConfiguration(), null) }
|
||||||
.apply { facetModel.addFacet(this) }
|
.apply { facetModel.addFacet(this) }
|
||||||
facet.configuration.settings.useProjectSettings = useProjectSettings
|
facet.configuration.settings.useProjectSettings = useProjectSettings
|
||||||
if (commitModel) {
|
if (commitModel) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
@@ -141,20 +140,20 @@ fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacet.configureFacet(
|
fun KotlinFacet.configureFacet(
|
||||||
compilerVersion: String,
|
compilerVersion: String,
|
||||||
coroutineSupport: LanguageFeature.State,
|
coroutineSupport: LanguageFeature.State,
|
||||||
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies
|
||||||
modelsProvider: IdeModifiableModelsProvider
|
modelsProvider: IdeModifiableModelsProvider
|
||||||
) {
|
) {
|
||||||
val module = module
|
val module = module
|
||||||
with(configuration.settings) {
|
with(configuration.settings) {
|
||||||
compilerArguments = null
|
compilerArguments = null
|
||||||
compilerSettings = null
|
compilerSettings = null
|
||||||
initializeIfNeeded(
|
initializeIfNeeded(
|
||||||
module,
|
module,
|
||||||
modelsProvider.getModifiableRootModel(module),
|
modelsProvider.getModifiableRootModel(module),
|
||||||
platformKind,
|
platformKind,
|
||||||
compilerVersion
|
compilerVersion
|
||||||
)
|
)
|
||||||
val apiLevel = apiLevel
|
val apiLevel = apiLevel
|
||||||
val languageLevel = languageLevel
|
val languageLevel = languageLevel
|
||||||
@@ -174,31 +173,41 @@ fun KotlinFacet.noVersionAutoAdvance() {
|
|||||||
|
|
||||||
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
|
||||||
// Update these lists when facet/project settings UI changes
|
// Update these lists when facet/project settings UI changes
|
||||||
val commonUIExposedFields = listOf(CommonCompilerArguments::languageVersion.name,
|
val commonUIExposedFields = listOf(
|
||||||
CommonCompilerArguments::apiVersion.name,
|
CommonCompilerArguments::languageVersion.name,
|
||||||
CommonCompilerArguments::suppressWarnings.name,
|
CommonCompilerArguments::apiVersion.name,
|
||||||
CommonCompilerArguments::coroutinesState.name)
|
CommonCompilerArguments::suppressWarnings.name,
|
||||||
private val commonUIHiddenFields = listOf(CommonCompilerArguments::pluginClasspaths.name,
|
CommonCompilerArguments::coroutinesState.name
|
||||||
CommonCompilerArguments::pluginOptions.name)
|
)
|
||||||
|
private val commonUIHiddenFields = listOf(
|
||||||
|
CommonCompilerArguments::pluginClasspaths.name,
|
||||||
|
CommonCompilerArguments::pluginOptions.name
|
||||||
|
)
|
||||||
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
|
||||||
|
|
||||||
private val jvmSpecificUIExposedFields = listOf(K2JVMCompilerArguments::jvmTarget.name,
|
private val jvmSpecificUIExposedFields = listOf(
|
||||||
K2JVMCompilerArguments::destination.name,
|
K2JVMCompilerArguments::jvmTarget.name,
|
||||||
K2JVMCompilerArguments::classpath.name)
|
K2JVMCompilerArguments::destination.name,
|
||||||
|
K2JVMCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
|
||||||
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
|
||||||
|
|
||||||
private val jsSpecificUIExposedFields = listOf(K2JSCompilerArguments::sourceMap.name,
|
private val jsSpecificUIExposedFields = listOf(
|
||||||
K2JSCompilerArguments::sourceMapPrefix.name,
|
K2JSCompilerArguments::sourceMap.name,
|
||||||
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
K2JSCompilerArguments::sourceMapPrefix.name,
|
||||||
K2JSCompilerArguments::outputPrefix.name,
|
K2JSCompilerArguments::sourceMapEmbedSources.name,
|
||||||
K2JSCompilerArguments::outputPostfix.name,
|
K2JSCompilerArguments::outputPrefix.name,
|
||||||
K2JSCompilerArguments::moduleKind.name)
|
K2JSCompilerArguments::outputPostfix.name,
|
||||||
|
K2JSCompilerArguments::moduleKind.name
|
||||||
|
)
|
||||||
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
|
||||||
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
|
||||||
|
|
||||||
private val metadataSpecificUIExposedFields = listOf(K2MetadataCompilerArguments::destination.name,
|
private val metadataSpecificUIExposedFields = listOf(
|
||||||
K2MetadataCompilerArguments::classpath.name)
|
K2MetadataCompilerArguments::destination.name,
|
||||||
|
K2MetadataCompilerArguments::classpath.name
|
||||||
|
)
|
||||||
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
|
||||||
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
|
||||||
|
|
||||||
@@ -223,23 +232,23 @@ private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArgum
|
|||||||
allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 } ?: return
|
allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 } ?: return
|
||||||
} else {
|
} else {
|
||||||
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
|
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
|
||||||
?: modelsProvider
|
?: modelsProvider
|
||||||
.modifiableModuleModel
|
.modifiableModuleModel
|
||||||
.modules
|
.modules
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
|
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
|
||||||
.firstOrNull { it.sdkType is KotlinSdkType }
|
.firstOrNull { it.sdkType is KotlinSdkType }
|
||||||
?: KotlinSdkType.INSTANCE.createSdkWithUniqueName(allSdks.toList())
|
?: KotlinSdkType.INSTANCE.createSdkWithUniqueName(allSdks.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
modelsProvider.getModifiableRootModel(this).sdk = sdk
|
modelsProvider.getModifiableRootModel(this).sdk = sdk
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseCompilerArgumentsToFacet(
|
fun parseCompilerArgumentsToFacet(
|
||||||
arguments: List<String>,
|
arguments: List<String>,
|
||||||
defaultArguments: List<String>,
|
defaultArguments: List<String>,
|
||||||
kotlinFacet: KotlinFacet,
|
kotlinFacet: KotlinFacet,
|
||||||
modelsProvider: IdeModifiableModelsProvider?
|
modelsProvider: IdeModifiableModelsProvider?
|
||||||
) {
|
) {
|
||||||
with(kotlinFacet.configuration.settings) {
|
with(kotlinFacet.configuration.settings) {
|
||||||
val compilerArguments = this.compilerArguments ?: return
|
val compilerArguments = this.compilerArguments ?: return
|
||||||
@@ -262,7 +271,7 @@ fun parseCompilerArgumentsToFacet(
|
|||||||
val ignoredFields = compilerArguments.ignoredFields
|
val ignoredFields = compilerArguments.ignoredFields
|
||||||
|
|
||||||
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
|
||||||
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
|
||||||
|
|
||||||
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
|
||||||
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
|
||||||
|
|||||||
Reference in New Issue
Block a user