diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index c7f74fa0a2a..da8881921f0 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -37,7 +37,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { valueDescription = "", description = "Provide source compatibility with specified language version" ) - var languageVersion: String? = null + var languageVersion: String? by FreezableVar(null) @GradleOption(DefaultValues.LanguageVersions::class) @Argument( @@ -45,22 +45,22 @@ abstract class CommonCompilerArguments : CommonToolArguments() { valueDescription = "", description = "Allow to use declarations only from the specified version of bundled libraries" ) - var apiVersion: String? = null + var apiVersion: String? by FreezableVar(null) @Argument( value = "-kotlin-home", valueDescription = "", description = "Path to Kotlin compiler home directory, used for runtime libraries discovery" ) - var kotlinHome: String? = null + var kotlinHome: String? by FreezableVar(null) @Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin") - var pluginOptions: Array? = null + var pluginOptions: Array? by FreezableVar(null) // Advanced options @Argument(value = "-Xno-inline", description = "Disable method inlining") - var noInline: Boolean = false + var noInline: Boolean by FreezableVar(false) // TODO Remove in 1.0 @Argument( @@ -68,42 +68,42 @@ abstract class CommonCompilerArguments : CommonToolArguments() { valueDescription = "", description = "Repeat compilation (for performance analysis)" ) - var repeat: String? = null + var repeat: String? by FreezableVar(null) @Argument( value = "-Xskip-metadata-version-check", description = "Load classes with bad metadata version anyway (incl. pre-release classes)" ) - var skipMetadataVersionCheck: Boolean = false + var skipMetadataVersionCheck: Boolean by FreezableVar(false) @Argument(value = "-Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'") - var allowKotlinPackage: Boolean = false + var allowKotlinPackage: Boolean by FreezableVar(false) @Argument(value = "-Xreport-output-files", description = "Report source to output files mapping") - var reportOutputFiles: Boolean = false + var reportOutputFiles: Boolean by FreezableVar(false) @Argument(value = "-Xplugin", valueDescription = "", description = "Load plugins from the given classpath") - var pluginClasspaths: Array? = null + var pluginClasspaths: Array? by FreezableVar(null) @Argument(value = "-Xmulti-platform", description = "Enable experimental language support for multi-platform projects") - var multiPlatform: Boolean = false + var multiPlatform: Boolean by FreezableVar(false) @Argument(value = "-Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects") - var noCheckImpl: Boolean = false + var noCheckImpl: Boolean by FreezableVar(false) @Argument( value = "-Xintellij-plugin-root", valueDescription = "", description = "Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found" ) - var intellijPluginRoot: String? = null + var intellijPluginRoot: String? by FreezableVar(null) @Argument( value = "-Xcoroutines", valueDescription = "{enable|warn|error}", description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier" ) - var coroutinesState: String? = WARN + var coroutinesState: String? by FreezableVar(WARN) open fun configureAnalysisFlags(): MutableMap, Any> { return HashMap, Any>().apply { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt index a12c000f712..b32e0ea4b9f 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cli.common.arguments import org.jetbrains.kotlin.utils.SmartList import java.io.Serializable -abstract class CommonToolArguments : Serializable { +abstract class CommonToolArguments : Freezable(), Serializable { companion object { @JvmStatic private val serialVersionUID = 0L } @@ -29,19 +29,19 @@ abstract class CommonToolArguments : Serializable { @Transient var errors: ArgumentParseErrors = ArgumentParseErrors() @Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options") - var help: Boolean = false + var help: Boolean by FreezableVar(false) @Argument(value = "-X", description = "Print a synopsis of advanced options") - var extraHelp: Boolean = false + var extraHelp: Boolean by FreezableVar(false) @Argument(value = "-version", description = "Display compiler version") - var version: Boolean = false + var version: Boolean by FreezableVar(false) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-verbose", description = "Enable verbose logging output") - var verbose: Boolean = false + var verbose: Boolean by FreezableVar(false) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-nowarn", description = "Generate no warnings") - var suppressWarnings: Boolean = false + var suppressWarnings: Boolean by FreezableVar(false) } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/Freezable.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/Freezable.kt new file mode 100644 index 00000000000..51786ddbd08 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/Freezable.kt @@ -0,0 +1,38 @@ +/* + * 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.cli.common.arguments + +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty + +abstract class Freezable { + protected inner class FreezableVar(private var value: T) : ReadWriteProperty { + override fun getValue(thisRef: Any, property: KProperty<*>) = value + + override fun setValue(thisRef: Any, property: KProperty<*>, value: T) { + if (frozen) throw IllegalStateException("Instance of ${this::class} is frozen") + this.value = value + } + } + + private var frozen: Boolean = false + + private fun getInstanceWithFreezeStatus(value: Boolean) = if (value == frozen) this else copyBean(this).apply { frozen = value } + + fun frozen() = getInstanceWithFreezeStatus(true) + fun unfrozen() = getInstanceWithFreezeStatus(false) +} \ No newline at end of file diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index 7e96346cf86..7301fde3fe2 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -26,33 +26,33 @@ class K2JSCompilerArguments : CommonCompilerArguments() { @GradleOption(DefaultValues.StringNullDefault::class) @Argument(value = "-output", valueDescription = "", description = "Output file path") - var outputFile: String? = null + var outputFile: String? by FreezableVar(null) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-no-stdlib", description = "Don't use bundled Kotlin stdlib") - var noStdlib: Boolean = false + var noStdlib: Boolean by FreezableVar(false) @Argument( value = "-libraries", valueDescription = "", description = "Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator" ) - var libraries: String? = null + var libraries: String? by FreezableVar(null) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-source-map", description = "Generate source map") - var sourceMap: Boolean = false + var sourceMap: Boolean by FreezableVar(false) @GradleOption(DefaultValues.StringNullDefault::class) @Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map") - var sourceMapPrefix: String? = null + var sourceMapPrefix: String? by FreezableVar(null) @Argument( value = "-source-map-source-roots", valueDescription = "", description = "Base directories which are used to calculate relative paths to source files in source map" ) - var sourceMapSourceRoots: String? = null + var sourceMapSourceRoots: String? by FreezableVar(null) @GradleOption(DefaultValues.JsSourceMapContentModes::class) @Argument( @@ -60,15 +60,15 @@ class K2JSCompilerArguments : CommonCompilerArguments() { valueDescription = "{ always, never, inlining }", description = "Embed source files into source map" ) - var sourceMapEmbedSources: String? = null + var sourceMapEmbedSources: String? by FreezableVar(null) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library") - var metaInfo: Boolean = false + var metaInfo: Boolean by FreezableVar(false) @GradleOption(DefaultValues.JsEcmaVersions::class) @Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version") - var target: String? = null + var target: String? by FreezableVar(null) @GradleOption(DefaultValues.JsModuleKinds::class) @Argument( @@ -76,40 +76,40 @@ class K2JSCompilerArguments : CommonCompilerArguments() { valueDescription = "{ plain, amd, commonjs, umd }", description = "Kind of a module generated by compiler" ) - var moduleKind: String? = K2JsArgumentConstants.MODULE_PLAIN + var moduleKind: String? by FreezableVar(K2JsArgumentConstants.MODULE_PLAIN) @GradleOption(DefaultValues.JsMain::class) @Argument(value = "-main", valueDescription = "{$CALL,$NO_CALL}", description = "Whether a main function should be called") - var main: String? = null + var main: String? by FreezableVar(null) @Argument( value = "-output-prefix", valueDescription = "", description = "Path to file which will be added to the beginning of output file" ) - var outputPrefix: String? = null + var outputPrefix: String? by FreezableVar(null) @Argument( value = "-output-postfix", valueDescription = "", description = "Path to file which will be added to the end of output file" ) - var outputPostfix: String? = null + var outputPostfix: String? by FreezableVar(null) // Advanced options @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays") - var typedArrays: Boolean = false + var typedArrays: Boolean by FreezableVar(false) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export") - var friendModulesDisabled: Boolean = false + var friendModulesDisabled: Boolean by FreezableVar(false) @Argument( value = "-Xfriend-modules", valueDescription = "", description = "Paths to friend modules" ) - var friendModules: String? = null + var friendModules: String? by FreezableVar(null) } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt index 285aa29a4cc..53ca5a52444 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSDceArguments.kt @@ -26,18 +26,18 @@ class K2JSDceArguments : CommonToolArguments() { valueDescription = "", description = "Output directory" ) - var outputDirectory: String? = null + var outputDirectory: String? by FreezableVar(null) @Argument( value = "-keep", valueDescription = "", description = "List of fully-qualified names of declarations that shouldn't be eliminated" ) - var declarationsToKeep: Array? = null + var declarationsToKeep: Array? by FreezableVar(null) @Argument( value = "-Xprint-reachability-info", description = "Print declarations marked as reachable" ) - var printReachabilityInfo: Boolean = false + var printReachabilityInfo: Boolean by FreezableVar(false) } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 07bf9bcdcb8..c1db8b3d5c7 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -26,14 +26,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { } @Argument(value = "-d", valueDescription = "", description = "Destination for generated class files") - var destination: String? = null + var destination: String? by FreezableVar(null) @Argument(value = "-classpath", shortName = "-cp", valueDescription = "", description = "Paths where to find user class files") - var classpath: String? = null + var classpath: String? by FreezableVar(null) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-include-runtime", description = "Include Kotlin runtime in to resulting .jar") - var includeRuntime: Boolean = false + var includeRuntime: Boolean by FreezableVar(false) @GradleOption(DefaultValues.StringNullDefault::class) @Argument( @@ -41,32 +41,32 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { valueDescription = "", description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME" ) - var jdkHome: String? = null + var jdkHome: String? by FreezableVar(null) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-no-jdk", description = "Don't include Java runtime into classpath") - var noJdk: Boolean = false + var noJdk: Boolean by FreezableVar(false) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-no-stdlib", description = "Don't include Kotlin runtime into classpath") - var noStdlib: Boolean = false + var noStdlib: Boolean by FreezableVar(false) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath") - var noReflect: Boolean = false + var noReflect: Boolean by FreezableVar(false) @Argument(value = "-script", description = "Evaluate the script file") - var script: Boolean = false + var script: Boolean by FreezableVar(false) @Argument( value = "-script-templates", valueDescription = "", description = "Script definition template classes" ) - var scriptTemplates: Array? = null + var scriptTemplates: Array? by FreezableVar(null) @Argument(value = "-module-name", description = "Module name") - var moduleName: String? = null + var moduleName: String? by FreezableVar(null) @GradleOption(DefaultValues.JvmTargetVersions::class) @Argument( @@ -74,16 +74,16 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { valueDescription = "", description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6" ) - var jvmTarget: String? = JvmTarget.DEFAULT.description + var jvmTarget: String? by FreezableVar(JvmTarget.DEFAULT.description) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters") - var javaParameters: Boolean = false + var javaParameters: Boolean by FreezableVar(false) // Advanced options @Argument(value = "-Xmodule-path", valueDescription = "", description = "Paths where to find Java 9+ modules") - var javaModulePath: String? = null + var javaModulePath: String? by FreezableVar(null) @Argument( value = "-Xadd-modules", @@ -91,78 +91,78 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { description = "Root modules to resolve in addition to the initial modules,\n" + "or all modules on the module path if is ALL-MODULE-PATH" ) - var additionalJavaModules: Array? = null + var additionalJavaModules: Array? by FreezableVar(null) @Argument(value = "-Xno-call-assertions", description = "Don't generate not-null assertion after each invocation of method returning not-null") - var noCallAssertions: Boolean = false + var noCallAssertions: Boolean by FreezableVar(false) @Argument(value = "-Xno-param-assertions", description = "Don't generate not-null assertions on parameters of methods accessible from Java") - var noParamAssertions: Boolean = false + var noParamAssertions: Boolean by FreezableVar(false) @Argument(value = "-Xno-optimize", description = "Disable optimizations") - var noOptimize: Boolean = false + var noOptimize: Boolean by FreezableVar(false) @Argument(value = "-Xreport-perf", description = "Report detailed performance statistics") - var reportPerf: Boolean = false + var reportPerf: Boolean by FreezableVar(false) @Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "", description = "Path to the .xml build file to compile") - var buildFile: String? = null + var buildFile: String? by FreezableVar(null) @Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade") - var inheritMultifileParts: Boolean = false + var inheritMultifileParts: Boolean by FreezableVar(false) @Argument(value = "-Xskip-runtime-version-check", description = "Allow Kotlin runtime libraries of incompatible versions in the classpath") - var skipRuntimeVersionCheck: Boolean = false + var skipRuntimeVersionCheck: Boolean by FreezableVar(false) @Argument( value = "-Xuse-old-class-files-reading", description = "Use old class files reading implementation " + "(may slow down the build and should be used in case of problems with the new implementation)" ) - var useOldClassFilesReading: Boolean = false + var useOldClassFilesReading: Boolean by FreezableVar(false) @Argument( value = "-Xdump-declarations-to", valueDescription = "", description = "Path to JSON file to dump Java to Kotlin declaration mappings" ) - var declarationsOutputPath: String? = null + var declarationsOutputPath: String? by FreezableVar(null) @Argument(value = "-Xsingle-module", description = "Combine modules for source files and binary dependencies into a single module") - var singleModule: Boolean = false + var singleModule: Boolean by FreezableVar(false) @Argument(value = "-Xadd-compiler-builtins", description = "Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)") - var addCompilerBuiltIns: Boolean = false + var addCompilerBuiltIns: Boolean by FreezableVar(false) @Argument(value = "-Xload-builtins-from-dependencies", description = "Load definitions of built-in declarations from module dependencies, instead of from the compiler") - var loadBuiltInsFromDependencies: Boolean = false + var loadBuiltInsFromDependencies: Boolean by FreezableVar(false) @Argument( value = "-Xscript-resolver-environment", valueDescription = "", description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)" ) - var scriptResolverEnvironment: Array? = null + var scriptResolverEnvironment: Array? by FreezableVar(null) // Javac options @Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis") - var useJavac: Boolean = false + var useJavac: Boolean by FreezableVar(false) @Argument( value = "-Xjavac-arguments", valueDescription = "", description = "Java compiler arguments") - var javacArguments: Array? = null + var javacArguments: Array? by FreezableVar(null) @Argument( value = "-Xjsr305-annotations", valueDescription = "{ignore|enable}", description = "Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations" ) - var jsr305GlobalReportLevel: String? = Jsr305State.DEFAULT.description + var jsr305GlobalReportLevel: String? by FreezableVar(Jsr305State.DEFAULT.description) // Paths to output directories for friend modules. - var friendPaths: Array? = null + var friendPaths: Array? by FreezableVar(null) override fun configureAnalysisFlags(): MutableMap, Any> { val result = super.configureAnalysisFlags() diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt index 19d0c43e6b2..6838cb065b5 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt @@ -22,7 +22,7 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() { } @Argument(value = "-d", valueDescription = "", description = "Destination for generated .kotlin_metadata files") - var destination: String? = null + var destination: String? by FreezableVar(null) @Argument( value = "-classpath", @@ -30,5 +30,5 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() { valueDescription = "", description = "Paths where to find library .kotlin_metadata files" ) - var classpath: String? = null + var classpath: String? by FreezableVar(null) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/BaseKotlinCompilerSettings.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/BaseKotlinCompilerSettings.kt index 3b7cf2e7bc6..08a7d9b9f0c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/BaseKotlinCompilerSettings.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/BaseKotlinCompilerSettings.kt @@ -25,19 +25,24 @@ import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.config.SettingConstants import kotlin.reflect.KClass -abstract class BaseKotlinCompilerSettings protected constructor() : PersistentStateComponent, Cloneable { - @Suppress("LeakingThis") - private var _settings: T = createSettings() +abstract class BaseKotlinCompilerSettings protected constructor() : PersistentStateComponent, Cloneable { + @Suppress("LeakingThis", "UNCHECKED_CAST") + private var _settings: T = createSettings().frozen() as T + private set(value) { + field = value.frozen() as T + } var settings: T - get() = copyBean(_settings) + get() = _settings set(value) { validateNewSettings(value) - _settings = copyBean(value) + @Suppress("UNCHECKED_CAST") + _settings = value } fun update(changer: T.() -> Unit) { - settings = settings.apply { changer() } + @Suppress("UNCHECKED_CAST") + settings = (settings.unfrozen() as T).apply { changer() } } protected fun validateInheritedFieldsUnchanged(settings: T) { diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt index a25232cf9d9..89abfd326c0 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt @@ -17,13 +17,14 @@ package org.jetbrains.kotlin.config import com.intellij.openapi.util.text.StringUtil +import org.jetbrains.kotlin.cli.common.arguments.Freezable -class CompilerSettings { - @JvmField var additionalArguments: String = DEFAULT_ADDITIONAL_ARGUMENTS - @JvmField var scriptTemplates: String = "" - @JvmField var scriptTemplatesClasspath: String = "" - @JvmField var copyJsLibraryFiles: Boolean = true - @JvmField var outputDirectoryForJsLibraryFiles: String = DEFAULT_OUTPUT_DIRECTORY +class CompilerSettings : Freezable() { + var additionalArguments: String by FreezableVar(DEFAULT_ADDITIONAL_ARGUMENTS) + var scriptTemplates: String by FreezableVar("") + var scriptTemplatesClasspath: String by FreezableVar("") + var copyJsLibraryFiles: Boolean by FreezableVar(true) + var outputDirectoryForJsLibraryFiles: String by FreezableVar(DEFAULT_OUTPUT_DIRECTORY) companion object { val DEFAULT_ADDITIONAL_ARGUMENTS = "-version" 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 0cb3d2ef86e..a63e6412787 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 @@ -84,7 +84,13 @@ class KotlinFacetSettings { var useProjectSettings: Boolean = true var compilerArguments: CommonCompilerArguments? = null + set(value) { + field = value?.unfrozen() as CommonCompilerArguments? + } var compilerSettings: CompilerSettings? = null + set(value) { + field = value?.unfrozen() as CompilerSettings? + } var languageLevel: LanguageVersion? get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) } diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index b542815b054..d6d4cd90c22 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -196,7 +196,7 @@ private fun Class<*>.computeNormalPropertyOrdering(): Map { private val allNormalOrderings = HashMap, Map>() private val Class<*>.normalOrdering - get() = allNormalOrderings.getOrPut(this) { computeNormalPropertyOrdering() } + get() = synchronized(allNormalOrderings) { allNormalOrderings.getOrPut(this) { computeNormalPropertyOrdering() } } // Replacing fields with delegated properties leads to unexpected reordering of entries in facet configuration XML // It happens due to XmlSerializer using different orderings for field- and method-based accessors diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt index 91bad0dad19..3baeb7cc179 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt @@ -588,7 +588,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertEquals(true, sourceMap) Assert.assertEquals("commonjs", moduleKind) } - Assert.assertEquals("-output test.js -meta-info -Xmulti-platform", + Assert.assertEquals("-meta-info -output test.js -Xmulti-platform", compilerSettings!!.additionalArguments) } @@ -1645,7 +1645,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() { Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals( - listOf("-kotlin-home", "temp2", "-java-parameters", "-Xdump-declarations-to=dumpDir"), + listOf("-Xdump-declarations-to=dumpDir", "-java-parameters", "-kotlin-home", "temp2"), compilerSettings!!.additionalArgumentsAsList ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index e10b7fa3ae3..b21ab3b400d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -432,11 +432,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co !getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.getLanguageVersion())) || !getSelectedAPIVersion().equals(getApiVersionOrDefault(commonCompilerArguments.getApiVersion())) || !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) || - ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.additionalArguments) || - ComparingUtils.isModified(scriptTemplatesField, compilerSettings.scriptTemplates) || - ComparingUtils.isModified(scriptTemplatesClasspathField, compilerSettings.scriptTemplatesClasspath) || - ComparingUtils.isModified(copyRuntimeFilesCheckBox, compilerSettings.copyJsLibraryFiles) || - isModified(outputDirectory, compilerSettings.outputDirectoryForJsLibraryFiles) || + ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.getAdditionalArguments()) || + ComparingUtils.isModified(scriptTemplatesField, compilerSettings.getScriptTemplates()) || + ComparingUtils.isModified(scriptTemplatesClasspathField, compilerSettings.getScriptTemplatesClasspath()) || + ComparingUtils.isModified(copyRuntimeFilesCheckBox, compilerSettings.getCopyJsLibraryFiles()) || + isModified(outputDirectory, compilerSettings.getOutputDirectoryForJsLibraryFiles()) || (compilerWorkspaceSettings != null && (ComparingUtils.isModified(enablePreciseIncrementalCheckBox, compilerWorkspaceSettings.getPreciseIncrementalEnabled()) || @@ -520,11 +520,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co break; } - compilerSettings.additionalArguments = additionalArgsOptionsField.getText(); - compilerSettings.scriptTemplates = scriptTemplatesField.getText(); - compilerSettings.scriptTemplatesClasspath = scriptTemplatesClasspathField.getText(); - compilerSettings.copyJsLibraryFiles = copyRuntimeFilesCheckBox.isSelected(); - compilerSettings.outputDirectoryForJsLibraryFiles = outputDirectory.getText(); + compilerSettings.setAdditionalArguments(additionalArgsOptionsField.getText()); + compilerSettings.setScriptTemplates(scriptTemplatesField.getText()); + compilerSettings.setScriptTemplatesClasspath(scriptTemplatesClasspathField.getText()); + compilerSettings.setCopyJsLibraryFiles(copyRuntimeFilesCheckBox.isSelected()); + compilerSettings.setOutputDirectoryForJsLibraryFiles(outputDirectory.getText()); if (compilerWorkspaceSettings != null) { compilerWorkspaceSettings.setPreciseIncrementalEnabled(enablePreciseIncrementalCheckBox.isSelected()); @@ -568,11 +568,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.getApiVersion())); restrictAPIVersions(getSelectedLanguageVersion()); coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments)); - additionalArgsOptionsField.setText(compilerSettings.additionalArguments); - scriptTemplatesField.setText(compilerSettings.scriptTemplates); - scriptTemplatesClasspathField.setText(compilerSettings.scriptTemplatesClasspath); - copyRuntimeFilesCheckBox.setSelected(compilerSettings.copyJsLibraryFiles); - outputDirectory.setText(compilerSettings.outputDirectoryForJsLibraryFiles); + additionalArgsOptionsField.setText(compilerSettings.getAdditionalArguments()); + scriptTemplatesField.setText(compilerSettings.getScriptTemplates()); + scriptTemplatesClasspathField.setText(compilerSettings.getScriptTemplatesClasspath()); + copyRuntimeFilesCheckBox.setSelected(compilerSettings.getCopyJsLibraryFiles()); + outputDirectory.setText(compilerSettings.getOutputDirectoryForJsLibraryFiles()); if (compilerWorkspaceSettings != null) { enablePreciseIncrementalCheckBox.setSelected(compilerWorkspaceSettings.getPreciseIncrementalEnabled()); diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java index d198f277383..1672f2469c9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java @@ -173,7 +173,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { assertEquals("1.0", arguments.getApiVersion()); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals("1.7", arguments.getJvmTarget()); - assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments); + assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments()); } @SuppressWarnings("ConstantConditions") @@ -188,7 +188,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { assertEquals("1.0", arguments.getApiVersion()); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals("amd", arguments.getModuleKind()); - assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments); + assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments()); } @SuppressWarnings("ConstantConditions") @@ -203,7 +203,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { assertEquals("1.0", arguments.getApiVersion()); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals("1.7", arguments.getJvmTarget()); - assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments); + assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments()); } @SuppressWarnings("ConstantConditions") @@ -218,7 +218,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { assertEquals("1.0", arguments.getApiVersion()); assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments)); assertEquals("amd", arguments.getModuleKind()); - assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments); + assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments()); } @SuppressWarnings("ConstantConditions") @@ -233,7 +233,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { assertEquals("1.0", arguments.getApiVersion()); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals("1.7", arguments.getJvmTarget()); - assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments); + assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().getAdditionalArguments()); } private void configureFacetAndCheckJvm(JvmTarget jvmTarget) {