From 5f819b589c27e6b70ca1c6f9f52485b28388ddbe Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Tue, 29 May 2018 15:15:39 +0300 Subject: [PATCH] Minor: refactor Platform.kt --- .../jetbrains/kotlin/idea/project/Platform.kt | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt index 459503e611e..fa128556bc5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt @@ -76,8 +76,7 @@ fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion { apiVersion = languageLevel.versionString } } - } - else { + } else { with(facetSettings) { if (this.languageLevel == null) { this.languageLevel = languageLevel @@ -92,24 +91,28 @@ fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion { } @JvmOverloads -fun Project.getLanguageVersionSettings(contextModule: Module? = null, - extraAnalysisFlags: Map, Any?> = emptyMap()): LanguageVersionSettings { +fun Project.getLanguageVersionSettings( + contextModule: Module? = null, + extraAnalysisFlags: Map, Any?> = emptyMap() +): LanguageVersionSettings { val arguments = KotlinCommonCompilerArgumentsHolder.getInstance(this).settings val languageVersion = - LanguageVersion.fromVersionString(arguments.languageVersion) - ?: contextModule?.getAndCacheLanguageLevelByDependencies() - ?: LanguageVersion.LATEST_STABLE + LanguageVersion.fromVersionString(arguments.languageVersion) + ?: contextModule?.getAndCacheLanguageLevelByDependencies() + ?: LanguageVersion.LATEST_STABLE val apiVersion = ApiVersion.createByLanguageVersion(LanguageVersion.fromVersionString(arguments.apiVersion) ?: languageVersion) val compilerSettings = KotlinCompilerSettings.getInstance(this).settings val extraLanguageFeatures = getExtraLanguageFeatures( - null, - CoroutineSupport.byCompilerArguments(KotlinCommonCompilerArgumentsHolder.getInstance(this).settings), - compilerSettings, - null + null, + CoroutineSupport.byCompilerArguments(KotlinCommonCompilerArgumentsHolder.getInstance(this).settings), + compilerSettings, + null + ) + return LanguageVersionSettingsImpl( + languageVersion, apiVersion, + arguments.configureAnalysisFlags(MessageCollector.NONE) + extraAnalysisFlags, + extraLanguageFeatures ) - return LanguageVersionSettingsImpl(languageVersion, apiVersion, - arguments.configureAnalysisFlags(MessageCollector.NONE) + extraAnalysisFlags, - extraLanguageFeatures) } private val LANGUAGE_VERSION_SETTINGS = Key.create>("LANGUAGE_VERSION_SETTINGS") @@ -172,17 +175,18 @@ private val Module.implementsCommonModule: Boolean && ModuleRootManager.getInstance(this).dependencies.any { it.targetPlatform == TargetPlatformKind.Common } private fun getExtraLanguageFeatures( - targetPlatformKind: TargetPlatformKind<*>?, - coroutineSupport: LanguageFeature.State, - compilerSettings: CompilerSettings?, - module: Module? + targetPlatformKind: TargetPlatformKind<*>?, + coroutineSupport: LanguageFeature.State, + compilerSettings: CompilerSettings?, + module: Module? ): Map { return mutableMapOf().apply { put(LanguageFeature.Coroutines, coroutineSupport) if (targetPlatformKind == TargetPlatformKind.Common || // TODO: this is a dirty hack, parse arguments correctly here compilerSettings?.additionalArguments?.contains(multiPlatformProjectsArg) == true || - (module != null && module.implementsCommonModule)) { + (module != null && module.implementsCommonModule) + ) { put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED) }