MPP: Refactoring, extract IDE platform kinds, allow to add custom platforms
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
||||
|
||||
class CommonPlatformKindResolution : IdePlatformKindResolution {
|
||||
override val kind get() = CommonIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = CommonAnalyzerFacade
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return DefaultBuiltIns.Instance
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
|
||||
interface IdePlatformKindResolution {
|
||||
val kind: IdePlatformKind<*>
|
||||
|
||||
val resolverForModuleFactory: ResolverForModuleFactory
|
||||
|
||||
fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns
|
||||
|
||||
companion object : ApplicationExtensionDescriptor<IdePlatformKindResolution>(
|
||||
"org.jetbrains.kotlin.idePlatformKindResolution", IdePlatformKindResolution::class.java
|
||||
) {
|
||||
private val CACHED_RESOLUTION_SUPPORT by lazy {
|
||||
val allPlatformKinds = IdePlatformKind.ALL_KINDS
|
||||
val groupedResolution = IdePlatformKindResolution.getInstances().groupBy { it.kind }.mapValues { it.value.single() }
|
||||
|
||||
for (kind in allPlatformKinds) {
|
||||
if (kind !in groupedResolution) {
|
||||
throw IllegalStateException(
|
||||
"Resolution support for the platform '$kind' is missing. " +
|
||||
"Implement 'IdePlatformKindResolution' for it."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
groupedResolution
|
||||
}
|
||||
|
||||
fun getResolution(kind: IdePlatformKind<*>): IdePlatformKindResolution {
|
||||
return CACHED_RESOLUTION_SUPPORT[kind] ?: error("Unknown platform $this")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val IdePlatformKind<*>.resolution: IdePlatformKindResolution
|
||||
get() = IdePlatformKindResolution.getResolution(this)
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
|
||||
abstract class IdePlatformSupport {
|
||||
abstract val platform: TargetPlatform
|
||||
abstract val resolverForModuleFactory: ResolverForModuleFactory
|
||||
abstract val libraryKind: PersistentLibraryKind<*>?
|
||||
|
||||
abstract fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns
|
||||
|
||||
abstract fun isModuleForPlatform(module: Module): Boolean
|
||||
|
||||
companion object {
|
||||
val EP_NAME = ExtensionPointName.create<IdePlatformSupport>("org.jetbrains.kotlin.idePlatformSupport")
|
||||
|
||||
val platformSupport by lazy {
|
||||
Extensions.getExtensions(EP_NAME).associateBy { it.platform }
|
||||
}
|
||||
|
||||
val facades by lazy {
|
||||
Extensions.getExtensions(EP_NAME).map { it.platform to it.resolverForModuleFactory }.toMap()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getPlatformForModule(module: Module): TargetPlatform {
|
||||
return Extensions.getExtensions(EP_NAME).find { it.isModuleForPlatform(module) }?.platform ?: JvmPlatform
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JvmPlatformSupport : IdePlatformSupport() {
|
||||
override val platform: TargetPlatform
|
||||
get() = JvmPlatform
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = JvmAnalyzerFacade
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = null
|
||||
|
||||
override fun isModuleForPlatform(module: Module): Boolean {
|
||||
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
|
||||
return settings.targetPlatformKind is TargetPlatformKind.Jvm
|
||||
}
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return if (settings.sdk != null) JvmBuiltIns(sdkContext.storageManager) else DefaultBuiltIns.Instance
|
||||
}
|
||||
}
|
||||
|
||||
class JsPlatformSupport : IdePlatformSupport() {
|
||||
override val platform: TargetPlatform
|
||||
get() = JsPlatform
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = JsAnalyzerFacade
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = JSLibraryKind
|
||||
|
||||
override fun isModuleForPlatform(module: Module): Boolean {
|
||||
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
|
||||
return settings.targetPlatformKind is TargetPlatformKind.JavaScript
|
||||
}
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return JsPlatform.builtIns
|
||||
}
|
||||
}
|
||||
|
||||
class CommonPlatformSupport : IdePlatformSupport() {
|
||||
override val platform: TargetPlatform
|
||||
get() = TargetPlatform.Common
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = CommonAnalyzerFacade
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = CommonLibraryKind
|
||||
|
||||
override fun isModuleForPlatform(module: Module): Boolean {
|
||||
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
|
||||
return settings.targetPlatformKind is TargetPlatformKind.Common
|
||||
}
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return DefaultBuiltIns.Instance
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||
|
||||
class JsPlatformKindResolution : IdePlatformKindResolution {
|
||||
override val kind get() = JsIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = JsAnalyzerFacade
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return JsPlatform.builtIns
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
|
||||
|
||||
class JvmPlatformKindResolution : IdePlatformKindResolution {
|
||||
override val kind get() = JvmIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
get() = JvmAnalyzerFacade
|
||||
|
||||
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
return if (settings.sdk != null) JvmBuiltIns(sdkContext.storageManager) else DefaultBuiltIns.Instance
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -25,10 +25,9 @@ import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.util.containers.SLRUCache
|
||||
import org.jetbrains.kotlin.analyzer.*
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonAnalysisParameters
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.caches.resolve.IdePlatformSupport
|
||||
import org.jetbrains.kotlin.caches.resolve.resolution
|
||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||
import org.jetbrains.kotlin.context.withProject
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
@@ -39,6 +38,7 @@ import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
|
||||
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||
import org.jetbrains.kotlin.platform.idePlatformKind
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.CompositeBindingContext
|
||||
@@ -140,7 +140,7 @@ internal class ProjectResolutionFacade(
|
||||
moduleLanguageSettingsProvider = IDELanguageSettingsProvider,
|
||||
resolverForModuleFactoryByPlatform = { modulePlatform ->
|
||||
val platform = modulePlatform ?: settings.platform
|
||||
IdePlatformSupport.facades[platform] ?: throw UnsupportedOperationException("Unsupported platform $platform")
|
||||
platform.idePlatformKind.resolution.resolverForModuleFactory
|
||||
},
|
||||
platformParameters = { platform ->
|
||||
when (platform) {
|
||||
@@ -212,8 +212,7 @@ internal class ProjectResolutionFacade(
|
||||
|
||||
private companion object {
|
||||
private fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
val supportInstance = IdePlatformSupport.platformSupport[settings.platform] ?: return DefaultBuiltIns.Instance
|
||||
return supportInstance.createBuiltIns(settings, sdkContext)
|
||||
return settings.platform.idePlatformKind.resolution.createBuiltIns(settings, sdkContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.idea.caches.project.*
|
||||
import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.project.targetPlatform
|
||||
import org.jetbrains.kotlin.idea.project.platform
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||
import org.jetbrains.kotlin.utils.Jsr305State
|
||||
|
||||
@@ -74,7 +74,7 @@ object IDELanguageSettingsProvider : LanguageSettingsProvider {
|
||||
|
||||
override fun getTargetPlatform(moduleInfo: ModuleInfo, project: Project): TargetPlatformVersion =
|
||||
when (moduleInfo) {
|
||||
is ModuleSourceInfo -> moduleInfo.module.targetPlatform?.version ?: TargetPlatformVersion.NoVersion
|
||||
is ModuleSourceInfo -> moduleInfo.module.platform?.version ?: TargetPlatformVersion.NoVersion
|
||||
is ScriptModuleInfo -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion
|
||||
is ScriptDependenciesInfo.ForFile -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion
|
||||
else -> TargetPlatformVersion.NoVersion
|
||||
|
||||
+14
-14
@@ -20,9 +20,9 @@ import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ModuleRootModel
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.orDefault
|
||||
import org.jetbrains.kotlin.config.VersionView
|
||||
|
||||
interface KotlinVersionInfoProvider {
|
||||
@@ -32,30 +32,30 @@ interface KotlinVersionInfoProvider {
|
||||
|
||||
fun getCompilerVersion(module: Module): String?
|
||||
fun getLibraryVersions(
|
||||
module: Module,
|
||||
targetPlatform: TargetPlatformKind<*>,
|
||||
rootModel: ModuleRootModel?
|
||||
module: Module,
|
||||
platformKind: IdePlatformKind<*>,
|
||||
rootModel: ModuleRootModel?
|
||||
): Collection<String>
|
||||
}
|
||||
|
||||
fun getRuntimeLibraryVersions(
|
||||
module: Module,
|
||||
rootModel: ModuleRootModel?,
|
||||
targetPlatform: TargetPlatformKind<*>
|
||||
module: Module,
|
||||
rootModel: ModuleRootModel?,
|
||||
platformKind: IdePlatformKind<*>
|
||||
): Collection<String> {
|
||||
return KotlinVersionInfoProvider.EP_NAME
|
||||
.extensions
|
||||
.map { it.getLibraryVersions(module, targetPlatform, rootModel) }
|
||||
.map { it.getLibraryVersions(module, platformKind, rootModel) }
|
||||
.firstOrNull { it.isNotEmpty() } ?: emptyList()
|
||||
}
|
||||
|
||||
fun getLibraryLanguageLevel(
|
||||
module: Module,
|
||||
rootModel: ModuleRootModel?,
|
||||
targetPlatform: TargetPlatformKind<*>?,
|
||||
platformKind: IdePlatformKind<*>?,
|
||||
coerceRuntimeLibraryVersionToReleased: Boolean = true
|
||||
): LanguageVersion {
|
||||
val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM)
|
||||
val minVersion = getRuntimeLibraryVersions(module, rootModel, platformKind.orDefault())
|
||||
.addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased)
|
||||
.minWith(VersionComparatorUtil.COMPARATOR)
|
||||
return getDefaultLanguageLevel(module, minVersion, coerceRuntimeLibraryVersionToReleased)
|
||||
@@ -85,8 +85,8 @@ private fun Iterable<String>.addReleaseVersionIfNecessary(shouldAdd: Boolean): I
|
||||
if (shouldAdd) this + VersionView.RELEASED_VERSION.versionString else this
|
||||
|
||||
fun getRuntimeLibraryVersion(module: Module): String? {
|
||||
val targetPlatform = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module).targetPlatformKind
|
||||
val versions = getRuntimeLibraryVersions(module, null, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM)
|
||||
val targetPlatform = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module).platform
|
||||
val versions = getRuntimeLibraryVersions(module, null, targetPlatform.orDefault().kind)
|
||||
return versions.toSet().singleOrNull()
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgu
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||
import org.jetbrains.kotlin.idea.facet.getLibraryLanguageLevel
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
|
||||
import org.jetbrains.kotlin.platform.IdePlatform
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.isCommon
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.UserDataProperty
|
||||
@@ -56,7 +61,7 @@ var KtFile.forcedTargetPlatform: TargetPlatform? by UserDataProperty(Key.create(
|
||||
|
||||
fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion {
|
||||
val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this)
|
||||
val languageLevel = getLibraryLanguageLevel(this, null, facetSettings.targetPlatformKind)
|
||||
val languageLevel = getLibraryLanguageLevel(this, null, facetSettings.platform?.kind)
|
||||
|
||||
// Preserve inferred version in facet/project settings
|
||||
if (facetSettings.useProjectSettings) {
|
||||
@@ -123,7 +128,7 @@ fun Project.getLanguageVersionSettings(
|
||||
val compilerSettings = KotlinCompilerSettings.getInstance(this).settings
|
||||
|
||||
val additionalArguments: CommonCompilerArguments = parseArguments(
|
||||
TargetPlatformKind.DEFAULT_PLATFORM,
|
||||
DefaultIdeTargetPlatformKindProvider.defaultPlatform,
|
||||
compilerSettings.additionalArgumentsAsList
|
||||
)
|
||||
|
||||
@@ -187,7 +192,7 @@ private fun Module.computeLanguageVersionSettings(): LanguageVersionSettings {
|
||||
|
||||
val languageFeatures = facetSettings.mergedCompilerArguments?.configureLanguageFeatures(MessageCollector.NONE)?.apply {
|
||||
configureCoroutinesSupport(facetSettings.coroutineSupport, languageVersion)
|
||||
configureMultiplatformSupport(facetSettings.targetPlatformKind, this@computeLanguageVersionSettings)
|
||||
configureMultiplatformSupport(facetSettings.platform?.kind, this@computeLanguageVersionSettings)
|
||||
}.orEmpty()
|
||||
|
||||
val analysisFlags = facetSettings.mergedCompilerArguments?.configureAnalysisFlags(MessageCollector.NONE).orEmpty()
|
||||
@@ -200,33 +205,25 @@ private fun Module.computeLanguageVersionSettings(): LanguageVersionSettings {
|
||||
)
|
||||
}
|
||||
|
||||
val Module.targetPlatform: TargetPlatformKind<*>?
|
||||
get() = KotlinFacetSettingsProvider.getInstance(project).getSettings(this)?.targetPlatformKind ?: project.targetPlatform
|
||||
val Module.platform: IdePlatform<*, *>?
|
||||
get() = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this).platform ?: project.platform
|
||||
|
||||
val Project.targetPlatform: TargetPlatformKind<*>?
|
||||
val Project.platform: IdePlatform<*, *>?
|
||||
get() {
|
||||
val jvmTarget = Kotlin2JvmCompilerArgumentsHolder.getInstance(this).settings.jvmTarget ?: return null
|
||||
val version = JvmTarget.fromString(jvmTarget) ?: return null
|
||||
return TargetPlatformKind.Jvm[version]
|
||||
return JvmIdePlatformKind.Platform(version)
|
||||
}
|
||||
|
||||
private val Module.implementsCommonModule: Boolean
|
||||
get() = targetPlatform != TargetPlatformKind.Common
|
||||
&& ModuleRootManager.getInstance(this).dependencies.any { it.targetPlatform == TargetPlatformKind.Common }
|
||||
get() = !platform.isCommon
|
||||
&& ModuleRootManager.getInstance(this).dependencies.any { it.platform.isCommon }
|
||||
|
||||
private fun parseArguments(
|
||||
targetPlatformKind: TargetPlatformKind<*>,
|
||||
platformKind: IdePlatform<*, *>,
|
||||
additionalArguments: List<String>
|
||||
): CommonCompilerArguments {
|
||||
val arguments = when (targetPlatformKind) {
|
||||
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
|
||||
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
|
||||
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
|
||||
}
|
||||
|
||||
parseCommandLineArguments(additionalArguments, arguments)
|
||||
|
||||
return arguments
|
||||
return platformKind.createArguments().also { parseCommandLineArguments(additionalArguments, it) }
|
||||
}
|
||||
|
||||
fun MutableMap<LanguageFeature, LanguageFeature.State>.configureCoroutinesSupport(
|
||||
@@ -242,10 +239,10 @@ fun MutableMap<LanguageFeature, LanguageFeature.State>.configureCoroutinesSuppor
|
||||
}
|
||||
|
||||
fun MutableMap<LanguageFeature, LanguageFeature.State>.configureMultiplatformSupport(
|
||||
targetPlatformKind: TargetPlatformKind<*>?,
|
||||
platformKind: IdePlatformKind<*>?,
|
||||
module: Module?
|
||||
) {
|
||||
if (targetPlatformKind == TargetPlatformKind.Common || module?.implementsCommonModule == true) {
|
||||
if (platformKind.isCommon || module?.implementsCommonModule == true) {
|
||||
put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.caches.resolve.IdePlatformSupport;
|
||||
import org.jetbrains.kotlin.platform.IdePlatform;
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKindUtil;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform;
|
||||
|
||||
public class ProjectStructureUtil {
|
||||
@@ -36,12 +37,10 @@ public class ProjectStructureUtil {
|
||||
/* package */ static TargetPlatform getCachedPlatformForModule(@NotNull final Module module) {
|
||||
CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE);
|
||||
if (result == null) {
|
||||
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(new CachedValueProvider<TargetPlatform>() {
|
||||
@Override
|
||||
public Result<TargetPlatform> compute() {
|
||||
return Result.create(IdePlatformSupport.getPlatformForModule(module),
|
||||
ProjectRootModificationTracker.getInstance(module.getProject()));
|
||||
}
|
||||
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(() -> {
|
||||
IdePlatform<?, ?> platform = IdePlatformKindUtil.orDefault(PlatformKt.getPlatform(module));
|
||||
return CachedValueProvider.Result.create(platform.getKind().getCompilerPlatform(),
|
||||
ProjectRootModificationTracker.getInstance(module.getProject()));
|
||||
}, false);
|
||||
|
||||
module.putUserData(PLATFORM_FOR_MODULE, result);
|
||||
|
||||
Reference in New Issue
Block a user