Support mutable/immutable compiler arguments

This commit is contained in:
Alexey Sedunov
2017-07-27 15:21:53 +03:00
parent 2984a5a19f
commit 40163868af
14 changed files with 157 additions and 107 deletions
@@ -37,7 +37,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>", valueDescription = "<version>",
description = "Provide source compatibility with specified language version" description = "Provide source compatibility with specified language version"
) )
var languageVersion: String? = null var languageVersion: String? by FreezableVar(null)
@GradleOption(DefaultValues.LanguageVersions::class) @GradleOption(DefaultValues.LanguageVersions::class)
@Argument( @Argument(
@@ -45,22 +45,22 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>", valueDescription = "<version>",
description = "Allow to use declarations only from the specified version of bundled libraries" description = "Allow to use declarations only from the specified version of bundled libraries"
) )
var apiVersion: String? = null var apiVersion: String? by FreezableVar(null)
@Argument( @Argument(
value = "-kotlin-home", value = "-kotlin-home",
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to Kotlin compiler home directory, used for runtime libraries discovery" 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") @Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin")
var pluginOptions: Array<String>? = null var pluginOptions: Array<String>? by FreezableVar(null)
// Advanced options // Advanced options
@Argument(value = "-Xno-inline", description = "Disable method inlining") @Argument(value = "-Xno-inline", description = "Disable method inlining")
var noInline: Boolean = false var noInline: Boolean by FreezableVar(false)
// TODO Remove in 1.0 // TODO Remove in 1.0
@Argument( @Argument(
@@ -68,42 +68,42 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<count>", valueDescription = "<count>",
description = "Repeat compilation (for performance analysis)" description = "Repeat compilation (for performance analysis)"
) )
var repeat: String? = null var repeat: String? by FreezableVar(null)
@Argument( @Argument(
value = "-Xskip-metadata-version-check", value = "-Xskip-metadata-version-check",
description = "Load classes with bad metadata version anyway (incl. pre-release classes)" 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'") @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") @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 = "<path>", description = "Load plugins from the given classpath") @Argument(value = "-Xplugin", valueDescription = "<path>", description = "Load plugins from the given classpath")
var pluginClasspaths: Array<String>? = null var pluginClasspaths: Array<String>? by FreezableVar(null)
@Argument(value = "-Xmulti-platform", description = "Enable experimental language support for multi-platform projects") @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") @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( @Argument(
value = "-Xintellij-plugin-root", value = "-Xintellij-plugin-root",
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found" 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( @Argument(
value = "-Xcoroutines", value = "-Xcoroutines",
valueDescription = "{enable|warn|error}", valueDescription = "{enable|warn|error}",
description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier" 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<AnalysisFlag<*>, Any> { open fun configureAnalysisFlags(): MutableMap<AnalysisFlag<*>, Any> {
return HashMap<AnalysisFlag<*>, Any>().apply { return HashMap<AnalysisFlag<*>, Any>().apply {
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cli.common.arguments
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
import java.io.Serializable import java.io.Serializable
abstract class CommonToolArguments : Serializable { abstract class CommonToolArguments : Freezable(), Serializable {
companion object { companion object {
@JvmStatic private val serialVersionUID = 0L @JvmStatic private val serialVersionUID = 0L
} }
@@ -29,19 +29,19 @@ abstract class CommonToolArguments : Serializable {
@Transient var errors: ArgumentParseErrors = ArgumentParseErrors() @Transient var errors: ArgumentParseErrors = ArgumentParseErrors()
@Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options") @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") @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") @Argument(value = "-version", description = "Display compiler version")
var version: Boolean = false var version: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-verbose", description = "Enable verbose logging output") @Argument(value = "-verbose", description = "Enable verbose logging output")
var verbose: Boolean = false var verbose: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-nowarn", description = "Generate no warnings") @Argument(value = "-nowarn", description = "Generate no warnings")
var suppressWarnings: Boolean = false var suppressWarnings: Boolean by FreezableVar(false)
} }
@@ -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<T>(private var value: T) : ReadWriteProperty<Any, T> {
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)
}
@@ -26,33 +26,33 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@GradleOption(DefaultValues.StringNullDefault::class) @GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-output", valueDescription = "<path>", description = "Output file path") @Argument(value = "-output", valueDescription = "<path>", description = "Output file path")
var outputFile: String? = null var outputFile: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanTrueDefault::class) @GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't use bundled Kotlin stdlib") @Argument(value = "-no-stdlib", description = "Don't use bundled Kotlin stdlib")
var noStdlib: Boolean = false var noStdlib: Boolean by FreezableVar(false)
@Argument( @Argument(
value = "-libraries", value = "-libraries",
valueDescription = "<path>", valueDescription = "<path>",
description = "Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator" 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) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-source-map", description = "Generate source map") @Argument(value = "-source-map", description = "Generate source map")
var sourceMap: Boolean = false var sourceMap: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.StringNullDefault::class) @GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map") @Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map")
var sourceMapPrefix: String? = null var sourceMapPrefix: String? by FreezableVar(null)
@Argument( @Argument(
value = "-source-map-source-roots", value = "-source-map-source-roots",
valueDescription = "<path>", valueDescription = "<path>",
description = "Base directories which are used to calculate relative paths to source files in source map" 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) @GradleOption(DefaultValues.JsSourceMapContentModes::class)
@Argument( @Argument(
@@ -60,15 +60,15 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ always, never, inlining }", valueDescription = "{ always, never, inlining }",
description = "Embed source files into source map" description = "Embed source files into source map"
) )
var sourceMapEmbedSources: String? = null var sourceMapEmbedSources: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanTrueDefault::class) @GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library") @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) @GradleOption(DefaultValues.JsEcmaVersions::class)
@Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version") @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) @GradleOption(DefaultValues.JsModuleKinds::class)
@Argument( @Argument(
@@ -76,40 +76,40 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ plain, amd, commonjs, umd }", valueDescription = "{ plain, amd, commonjs, umd }",
description = "Kind of a module generated by compiler" 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) @GradleOption(DefaultValues.JsMain::class)
@Argument(value = "-main", valueDescription = "{$CALL,$NO_CALL}", description = "Whether a main function should be called") @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( @Argument(
value = "-output-prefix", value = "-output-prefix",
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to file which will be added to the beginning of output file" 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( @Argument(
value = "-output-postfix", value = "-output-postfix",
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to file which will be added to the end of output file" 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 // Advanced options
@GradleOption(DefaultValues.BooleanFalseDefault::class) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays") @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) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export") @Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export")
var friendModulesDisabled: Boolean = false var friendModulesDisabled: Boolean by FreezableVar(false)
@Argument( @Argument(
value = "-Xfriend-modules", value = "-Xfriend-modules",
valueDescription = "<path>", valueDescription = "<path>",
description = "Paths to friend modules" description = "Paths to friend modules"
) )
var friendModules: String? = null var friendModules: String? by FreezableVar(null)
} }
@@ -26,18 +26,18 @@ class K2JSDceArguments : CommonToolArguments() {
valueDescription = "<path>", valueDescription = "<path>",
description = "Output directory" description = "Output directory"
) )
var outputDirectory: String? = null var outputDirectory: String? by FreezableVar(null)
@Argument( @Argument(
value = "-keep", value = "-keep",
valueDescription = "<fully.qualified.name[,]>", valueDescription = "<fully.qualified.name[,]>",
description = "List of fully-qualified names of declarations that shouldn't be eliminated" description = "List of fully-qualified names of declarations that shouldn't be eliminated"
) )
var declarationsToKeep: Array<String>? = null var declarationsToKeep: Array<String>? by FreezableVar(null)
@Argument( @Argument(
value = "-Xprint-reachability-info", value = "-Xprint-reachability-info",
description = "Print declarations marked as reachable" description = "Print declarations marked as reachable"
) )
var printReachabilityInfo: Boolean = false var printReachabilityInfo: Boolean by FreezableVar(false)
} }
@@ -26,14 +26,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
} }
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated class files") @Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated class files")
var destination: String? = null var destination: String? by FreezableVar(null)
@Argument(value = "-classpath", shortName = "-cp", valueDescription = "<path>", description = "Paths where to find user class files") @Argument(value = "-classpath", shortName = "-cp", valueDescription = "<path>", description = "Paths where to find user class files")
var classpath: String? = null var classpath: String? by FreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-include-runtime", description = "Include Kotlin runtime in to resulting .jar") @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) @GradleOption(DefaultValues.StringNullDefault::class)
@Argument( @Argument(
@@ -41,32 +41,32 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME" 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) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-no-jdk", description = "Don't include Java runtime into classpath") @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) @GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't include Kotlin runtime into classpath") @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) @GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath") @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") @Argument(value = "-script", description = "Evaluate the script file")
var script: Boolean = false var script: Boolean by FreezableVar(false)
@Argument( @Argument(
value = "-script-templates", value = "-script-templates",
valueDescription = "<fully qualified class name[,]>", valueDescription = "<fully qualified class name[,]>",
description = "Script definition template classes" description = "Script definition template classes"
) )
var scriptTemplates: Array<String>? = null var scriptTemplates: Array<String>? by FreezableVar(null)
@Argument(value = "-module-name", description = "Module name") @Argument(value = "-module-name", description = "Module name")
var moduleName: String? = null var moduleName: String? by FreezableVar(null)
@GradleOption(DefaultValues.JvmTargetVersions::class) @GradleOption(DefaultValues.JvmTargetVersions::class)
@Argument( @Argument(
@@ -74,16 +74,16 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<version>", valueDescription = "<version>",
description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6" 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) @GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters") @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 // Advanced options
@Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules") @Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules")
var javaModulePath: String? = null var javaModulePath: String? by FreezableVar(null)
@Argument( @Argument(
value = "-Xadd-modules", value = "-Xadd-modules",
@@ -91,78 +91,78 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
description = "Root modules to resolve in addition to the initial modules,\n" + description = "Root modules to resolve in addition to the initial modules,\n" +
"or all modules on the module path if <module> is ALL-MODULE-PATH" "or all modules on the module path if <module> is ALL-MODULE-PATH"
) )
var additionalJavaModules: Array<String>? = null var additionalJavaModules: Array<String>? by FreezableVar(null)
@Argument(value = "-Xno-call-assertions", description = "Don't generate not-null assertion after each invocation of method returning not-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") @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") @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") @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 = "<path>", description = "Path to the .xml build file to compile") @Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "<path>", 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") @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") @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( @Argument(
value = "-Xuse-old-class-files-reading", value = "-Xuse-old-class-files-reading",
description = "Use old class files reading implementation " + description = "Use old class files reading implementation " +
"(may slow down the build and should be used in case of problems with the new 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( @Argument(
value = "-Xdump-declarations-to", value = "-Xdump-declarations-to",
valueDescription = "<path>", valueDescription = "<path>",
description = "Path to JSON file to dump Java to Kotlin declaration mappings" 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") @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)") @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") @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( @Argument(
value = "-Xscript-resolver-environment", value = "-Xscript-resolver-environment",
valueDescription = "<key=value[,]>", valueDescription = "<key=value[,]>",
description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)" description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)"
) )
var scriptResolverEnvironment: Array<String>? = null var scriptResolverEnvironment: Array<String>? by FreezableVar(null)
// Javac options // Javac options
@Argument(value = "-Xuse-javac", description = "Use javac for Java source and class files analysis") @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( @Argument(
value = "-Xjavac-arguments", value = "-Xjavac-arguments",
valueDescription = "<option[,]>", valueDescription = "<option[,]>",
description = "Java compiler arguments") description = "Java compiler arguments")
var javacArguments: Array<String>? = null var javacArguments: Array<String>? by FreezableVar(null)
@Argument( @Argument(
value = "-Xjsr305-annotations", value = "-Xjsr305-annotations",
valueDescription = "{ignore|enable}", valueDescription = "{ignore|enable}",
description = "Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations" 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. // Paths to output directories for friend modules.
var friendPaths: Array<String>? = null var friendPaths: Array<String>? by FreezableVar(null)
override fun configureAnalysisFlags(): MutableMap<AnalysisFlag<*>, Any> { override fun configureAnalysisFlags(): MutableMap<AnalysisFlag<*>, Any> {
val result = super.configureAnalysisFlags() val result = super.configureAnalysisFlags()
@@ -22,7 +22,7 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
} }
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated .kotlin_metadata files") @Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated .kotlin_metadata files")
var destination: String? = null var destination: String? by FreezableVar(null)
@Argument( @Argument(
value = "-classpath", value = "-classpath",
@@ -30,5 +30,5 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>", valueDescription = "<path>",
description = "Paths where to find library .kotlin_metadata files" description = "Paths where to find library .kotlin_metadata files"
) )
var classpath: String? = null var classpath: String? by FreezableVar(null)
} }
@@ -25,19 +25,24 @@ import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.config.SettingConstants import org.jetbrains.kotlin.config.SettingConstants
import kotlin.reflect.KClass import kotlin.reflect.KClass
abstract class BaseKotlinCompilerSettings<T : Any> protected constructor() : PersistentStateComponent<Element>, Cloneable { abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor() : PersistentStateComponent<Element>, Cloneable {
@Suppress("LeakingThis") @Suppress("LeakingThis", "UNCHECKED_CAST")
private var _settings: T = createSettings() private var _settings: T = createSettings().frozen() as T
private set(value) {
field = value.frozen() as T
}
var settings: T var settings: T
get() = copyBean(_settings) get() = _settings
set(value) { set(value) {
validateNewSettings(value) validateNewSettings(value)
_settings = copyBean(value) @Suppress("UNCHECKED_CAST")
_settings = value
} }
fun update(changer: T.() -> Unit) { fun update(changer: T.() -> Unit) {
settings = settings.apply { changer() } @Suppress("UNCHECKED_CAST")
settings = (settings.unfrozen() as T).apply { changer() }
} }
protected fun validateInheritedFieldsUnchanged(settings: T) { protected fun validateInheritedFieldsUnchanged(settings: T) {
@@ -17,13 +17,14 @@
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.arguments.Freezable
class CompilerSettings { class CompilerSettings : Freezable() {
@JvmField var additionalArguments: String = DEFAULT_ADDITIONAL_ARGUMENTS var additionalArguments: String by FreezableVar(DEFAULT_ADDITIONAL_ARGUMENTS)
@JvmField var scriptTemplates: String = "" var scriptTemplates: String by FreezableVar("")
@JvmField var scriptTemplatesClasspath: String = "" var scriptTemplatesClasspath: String by FreezableVar("")
@JvmField var copyJsLibraryFiles: Boolean = true var copyJsLibraryFiles: Boolean by FreezableVar(true)
@JvmField var outputDirectoryForJsLibraryFiles: String = DEFAULT_OUTPUT_DIRECTORY var outputDirectoryForJsLibraryFiles: String by FreezableVar(DEFAULT_OUTPUT_DIRECTORY)
companion object { companion object {
val DEFAULT_ADDITIONAL_ARGUMENTS = "-version" val DEFAULT_ADDITIONAL_ARGUMENTS = "-version"
@@ -84,7 +84,13 @@ class KotlinFacetSettings {
var useProjectSettings: Boolean = true var useProjectSettings: Boolean = true
var compilerArguments: CommonCompilerArguments? = null var compilerArguments: CommonCompilerArguments? = null
set(value) {
field = value?.unfrozen() as CommonCompilerArguments?
}
var compilerSettings: CompilerSettings? = null var compilerSettings: CompilerSettings? = null
set(value) {
field = value?.unfrozen() as CompilerSettings?
}
var languageLevel: LanguageVersion? var languageLevel: LanguageVersion?
get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) } get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) }
@@ -196,7 +196,7 @@ private fun Class<*>.computeNormalPropertyOrdering(): Map<String, Int> {
private val allNormalOrderings = HashMap<Class<*>, Map<String, Int>>() private val allNormalOrderings = HashMap<Class<*>, Map<String, Int>>()
private val Class<*>.normalOrdering 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 // 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 // It happens due to XmlSerializer using different orderings for field- and method-based accessors
@@ -588,7 +588,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("commonjs", moduleKind) Assert.assertEquals("commonjs", moduleKind)
} }
Assert.assertEquals("-output test.js -meta-info -Xmulti-platform", Assert.assertEquals("-meta-info -output test.js -Xmulti-platform",
compilerSettings!!.additionalArguments) compilerSettings!!.additionalArguments)
} }
@@ -1645,7 +1645,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
listOf("-kotlin-home", "temp2", "-java-parameters", "-Xdump-declarations-to=dumpDir"), listOf("-Xdump-declarations-to=dumpDir", "-java-parameters", "-kotlin-home", "temp2"),
compilerSettings!!.additionalArgumentsAsList compilerSettings!!.additionalArgumentsAsList
) )
} }
@@ -432,11 +432,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
!getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.getLanguageVersion())) || !getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.getLanguageVersion())) ||
!getSelectedAPIVersion().equals(getApiVersionOrDefault(commonCompilerArguments.getApiVersion())) || !getSelectedAPIVersion().equals(getApiVersionOrDefault(commonCompilerArguments.getApiVersion())) ||
!coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) || !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) ||
ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.additionalArguments) || ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.getAdditionalArguments()) ||
ComparingUtils.isModified(scriptTemplatesField, compilerSettings.scriptTemplates) || ComparingUtils.isModified(scriptTemplatesField, compilerSettings.getScriptTemplates()) ||
ComparingUtils.isModified(scriptTemplatesClasspathField, compilerSettings.scriptTemplatesClasspath) || ComparingUtils.isModified(scriptTemplatesClasspathField, compilerSettings.getScriptTemplatesClasspath()) ||
ComparingUtils.isModified(copyRuntimeFilesCheckBox, compilerSettings.copyJsLibraryFiles) || ComparingUtils.isModified(copyRuntimeFilesCheckBox, compilerSettings.getCopyJsLibraryFiles()) ||
isModified(outputDirectory, compilerSettings.outputDirectoryForJsLibraryFiles) || isModified(outputDirectory, compilerSettings.getOutputDirectoryForJsLibraryFiles()) ||
(compilerWorkspaceSettings != null && (compilerWorkspaceSettings != null &&
(ComparingUtils.isModified(enablePreciseIncrementalCheckBox, compilerWorkspaceSettings.getPreciseIncrementalEnabled()) || (ComparingUtils.isModified(enablePreciseIncrementalCheckBox, compilerWorkspaceSettings.getPreciseIncrementalEnabled()) ||
@@ -520,11 +520,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
break; break;
} }
compilerSettings.additionalArguments = additionalArgsOptionsField.getText(); compilerSettings.setAdditionalArguments(additionalArgsOptionsField.getText());
compilerSettings.scriptTemplates = scriptTemplatesField.getText(); compilerSettings.setScriptTemplates(scriptTemplatesField.getText());
compilerSettings.scriptTemplatesClasspath = scriptTemplatesClasspathField.getText(); compilerSettings.setScriptTemplatesClasspath(scriptTemplatesClasspathField.getText());
compilerSettings.copyJsLibraryFiles = copyRuntimeFilesCheckBox.isSelected(); compilerSettings.setCopyJsLibraryFiles(copyRuntimeFilesCheckBox.isSelected());
compilerSettings.outputDirectoryForJsLibraryFiles = outputDirectory.getText(); compilerSettings.setOutputDirectoryForJsLibraryFiles(outputDirectory.getText());
if (compilerWorkspaceSettings != null) { if (compilerWorkspaceSettings != null) {
compilerWorkspaceSettings.setPreciseIncrementalEnabled(enablePreciseIncrementalCheckBox.isSelected()); compilerWorkspaceSettings.setPreciseIncrementalEnabled(enablePreciseIncrementalCheckBox.isSelected());
@@ -568,11 +568,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.getApiVersion())); apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.getApiVersion()));
restrictAPIVersions(getSelectedLanguageVersion()); restrictAPIVersions(getSelectedLanguageVersion());
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments)); coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
additionalArgsOptionsField.setText(compilerSettings.additionalArguments); additionalArgsOptionsField.setText(compilerSettings.getAdditionalArguments());
scriptTemplatesField.setText(compilerSettings.scriptTemplates); scriptTemplatesField.setText(compilerSettings.getScriptTemplates());
scriptTemplatesClasspathField.setText(compilerSettings.scriptTemplatesClasspath); scriptTemplatesClasspathField.setText(compilerSettings.getScriptTemplatesClasspath());
copyRuntimeFilesCheckBox.setSelected(compilerSettings.copyJsLibraryFiles); copyRuntimeFilesCheckBox.setSelected(compilerSettings.getCopyJsLibraryFiles());
outputDirectory.setText(compilerSettings.outputDirectoryForJsLibraryFiles); outputDirectory.setText(compilerSettings.getOutputDirectoryForJsLibraryFiles());
if (compilerWorkspaceSettings != null) { if (compilerWorkspaceSettings != null) {
enablePreciseIncrementalCheckBox.setSelected(compilerWorkspaceSettings.getPreciseIncrementalEnabled()); enablePreciseIncrementalCheckBox.setSelected(compilerWorkspaceSettings.getPreciseIncrementalEnabled());
@@ -173,7 +173,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget()); 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") @SuppressWarnings("ConstantConditions")
@@ -188,7 +188,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("amd", arguments.getModuleKind()); assertEquals("amd", arguments.getModuleKind());
assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments); assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
} }
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@@ -203,7 +203,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget()); 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") @SuppressWarnings("ConstantConditions")
@@ -218,7 +218,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("amd", arguments.getModuleKind()); assertEquals("amd", arguments.getModuleKind());
assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments); assertEquals("-version -meta-info", settings.getCompilerSettings().getAdditionalArguments());
} }
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@@ -233,7 +233,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.getJvmTarget()); 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) { private void configureFacetAndCheckJvm(JvmTarget jvmTarget) {