From 78b1fb2e933eb68b7f665cb672bbe36ed17472ea Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 15 Aug 2017 16:09:21 +0300 Subject: [PATCH] Kotlin Facet: Avoid reparse of additional arguments during analysis --- .../jetbrains/kotlin/idea/project/Platform.kt | 10 +------ .../kotlin/config/KotlinFacetSettings.kt | 27 ++++++++++++++++--- .../idea/facet/KotlinFacetEditorGeneralTab.kt | 1 + .../jetbrains/kotlin/idea/facet/facetUtils.kt | 2 ++ 4 files changed, 27 insertions(+), 13 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 feac82957f3..b5ed94666b1 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 @@ -25,7 +25,6 @@ import com.intellij.openapi.roots.ProjectFileIndex import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.cli.common.arguments.Argument import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder @@ -111,17 +110,10 @@ val Module.languageVersionSettings: LanguageVersionSettings this ) - val arguments = facetSettings.compilerArguments - if (arguments != null) { - facetSettings.compilerSettings?.let { compilerSettings -> - parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, arguments) - } - } - return LanguageVersionSettingsImpl( languageVersion, ApiVersion.createByLanguageVersion(apiVersion), - arguments?.configureAnalysisFlags().orEmpty(), + facetSettings.mergedCompilerArguments?.configureAnalysisFlags().orEmpty(), extraLanguageFeatures ) } diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index a63e6412787..d3a23e559eb 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -19,10 +19,7 @@ package org.jetbrains.kotlin.config import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.utils.DescriptionAware sealed class TargetPlatformKind( @@ -83,13 +80,35 @@ class KotlinFacetSettings { var version = CURRENT_VERSION var useProjectSettings: Boolean = true + var mergedCompilerArguments: CommonCompilerArguments? = null + private set + + // TODO: Workaround for unwanted facet settings modification on code analysis + // To be replaced with proper API for settings update (see BaseKotlinCompilerSettings as an example) + fun updateMergedArguments() { + val compilerArguments = compilerArguments + val compilerSettings = compilerSettings + + mergedCompilerArguments = if (compilerArguments != null) { + copyBean(compilerArguments).apply { + if (compilerSettings != null) { + parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this) + } + } + } + else null + } + var compilerArguments: CommonCompilerArguments? = null set(value) { field = value?.unfrozen() as CommonCompilerArguments? + updateMergedArguments() } + var compilerSettings: CompilerSettings? = null set(value) { field = value?.unfrozen() as CompilerSettings? + updateMergedArguments() } var languageLevel: LanguageVersion? diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt index 9a729262755..e5794f3c677 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt @@ -316,6 +316,7 @@ class KotlinFacetEditorGeneralTab( } } } + updateMergedArguments() } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index a520588029b..a0c67031c0d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -238,5 +238,7 @@ fun parseCompilerArgumentsToFacet( with(compilerArguments::class.java.newInstance()) { copyFieldsSatisfying(this, compilerArguments) { exposeAsAdditionalArgument(it) || it.name in ignoredFields } } + + updateMergedArguments() } }