Configuration: Collapse empty nullable strings to null

This commit is contained in:
Alexey Sedunov
2018-08-03 15:40:35 +03:00
parent db556d6551
commit abbac067b8
16 changed files with 124 additions and 33 deletions
@@ -44,7 +44,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>",
description = "Provide source compatibility with specified language version"
)
var languageVersion: String? by FreezableVar(null)
var languageVersion: String? by NullableStringFreezableVar(null)
@get:Transient
var autoAdvanceApiVersion: Boolean by FreezableVar(true)
@@ -55,14 +55,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<version>",
description = "Allow to use declarations only from the specified version of bundled libraries"
)
var apiVersion: String? by FreezableVar(null)
var apiVersion: String? by NullableStringFreezableVar(null)
@Argument(
value = "-kotlin-home",
valueDescription = "<path>",
description = "Path to Kotlin compiler home directory, used for runtime libraries discovery"
)
var kotlinHome: String? by FreezableVar(null)
var kotlinHome: String? by NullableStringFreezableVar(null)
@Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin")
var pluginOptions: Array<String>? by FreezableVar(null)
@@ -101,14 +101,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<path>",
description = "Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found"
)
var intellijPluginRoot: String? by FreezableVar(null)
var intellijPluginRoot: String? by NullableStringFreezableVar(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? by FreezableVar(WARN)
var coroutinesState: String? by NullableStringFreezableVar(WARN)
@Argument(
value = "-Xnew-inference",
@@ -162,7 +162,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "<path>",
description = "Dump detailed performance statistics to the specified file"
)
var dumpPerf: String? by FreezableVar(null)
var dumpPerf: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xprogressive",
@@ -20,7 +20,7 @@ import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
abstract class Freezable {
protected inner class FreezableVar<T>(private var value: T) : ReadWriteProperty<Any, T> {
protected open 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) {
@@ -29,6 +29,14 @@ abstract class Freezable {
}
}
protected inner class NullableStringFreezableVar(value: String?) : FreezableVar<String?>(value) {
private val defaultValue = value
override fun setValue(thisRef: Any, property: KProperty<*>, value: String?) {
super.setValue(thisRef, property, if (value.isNullOrEmpty()) defaultValue else value)
}
}
private var frozen: Boolean = false
private fun getInstanceWithFreezeStatus(value: Boolean) = if (value == frozen) this else copyBean(this).apply { frozen = value }
@@ -26,7 +26,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-output", valueDescription = "<path>", description = "Output file path")
var outputFile: String? by FreezableVar(null)
var outputFile: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't use bundled Kotlin stdlib")
@@ -37,7 +37,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Paths to Kotlin libraries with .meta.js and .kjsm files, separated by system path separator"
)
var libraries: String? by FreezableVar(null)
var libraries: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-source-map", description = "Generate source map")
@@ -45,7 +45,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@GradleOption(DefaultValues.StringNullDefault::class)
@Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map")
var sourceMapPrefix: String? by FreezableVar(null)
var sourceMapPrefix: String? by NullableStringFreezableVar(null)
@Argument(
value = "-source-map-base-dirs",
@@ -53,7 +53,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Base directories which are used to calculate relative paths to source files in source map"
)
var sourceMapBaseDirs: String? by FreezableVar(null)
var sourceMapBaseDirs: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.JsSourceMapContentModes::class)
@Argument(
@@ -61,7 +61,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ always, never, inlining }",
description = "Embed source files into source map"
)
var sourceMapEmbedSources: String? by FreezableVar(null)
var sourceMapEmbedSources: String? by NullableStringFreezableVar(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library")
@@ -69,7 +69,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@GradleOption(DefaultValues.JsEcmaVersions::class)
@Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version")
var target: String? by FreezableVar(null)
var target: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.JsModuleKinds::class)
@Argument(
@@ -77,25 +77,25 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "{ plain, amd, commonjs, umd }",
description = "Kind of a module generated by compiler"
)
var moduleKind: String? by FreezableVar(K2JsArgumentConstants.MODULE_PLAIN)
var moduleKind: String? by NullableStringFreezableVar(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? by FreezableVar(null)
var main: String? by NullableStringFreezableVar(null)
@Argument(
value = "-output-prefix",
valueDescription = "<path>",
description = "Path to file which will be added to the beginning of output file"
)
var outputPrefix: String? by FreezableVar(null)
var outputPrefix: String? by NullableStringFreezableVar(null)
@Argument(
value = "-output-postfix",
valueDescription = "<path>",
description = "Path to file which will be added to the end of output file"
)
var outputPostfix: String? by FreezableVar(null)
var outputPostfix: String? by NullableStringFreezableVar(null)
// Advanced options
@@ -112,5 +112,5 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Paths to friend modules"
)
var friendModules: String? by FreezableVar(null)
var friendModules: String? by NullableStringFreezableVar(null)
}
@@ -27,7 +27,7 @@ class K2JSDceArguments : CommonToolArguments() {
description = "Output directory"
)
@GradleOption(DefaultValues.StringNullDefault::class)
var outputDirectory: String? by FreezableVar(null)
var outputDirectory: String? by NullableStringFreezableVar(null)
@Argument(
value = "-keep",
@@ -16,10 +16,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
}
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated class files")
var destination: String? by FreezableVar(null)
var destination: String? by NullableStringFreezableVar(null)
@Argument(value = "-classpath", shortName = "-cp", valueDescription = "<path>", description = "Paths where to find user class files")
var classpath: String? by FreezableVar(null)
var classpath: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-include-runtime", description = "Include Kotlin runtime in to resulting .jar")
@@ -31,7 +31,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME"
)
var jdkHome: String? by FreezableVar(null)
var jdkHome: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-no-jdk", description = "Don't include Java runtime into classpath")
@@ -56,7 +56,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
var scriptTemplates: Array<String>? by FreezableVar(null)
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
var moduleName: String? by FreezableVar(null)
var moduleName: String? by NullableStringFreezableVar(null)
@GradleOption(DefaultValues.JvmTargetVersions::class)
@Argument(
@@ -64,7 +64,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<version>",
description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6"
)
var jvmTarget: String? by FreezableVar(JvmTarget.DEFAULT.description)
var jvmTarget: String? by NullableStringFreezableVar(JvmTarget.DEFAULT.description)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters")
@@ -76,7 +76,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
var useIR: Boolean by FreezableVar(false)
@Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules")
var javaModulePath: String? by FreezableVar(null)
var javaModulePath: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xadd-modules",
@@ -112,7 +112,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "{disable|enable}",
description = "Normalize constructor calls (disable: don't normalize; enable: normalize), default is disable"
)
var constructorCallNormalizationMode: String? by FreezableVar(null)
var constructorCallNormalizationMode: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xassertions", valueDescription = "{always-enable|always-disable|jvm|legacy}",
@@ -123,7 +123,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
"-Xassertions=legacy: calculate condition on each call, check depends on jvm assertion settings in the kotlin package;\n" +
"default: legacy"
)
var assertionsMode: String? by FreezableVar(JVMAssertionsMode.DEFAULT.description)
var assertionsMode: String? by NullableStringFreezableVar(JVMAssertionsMode.DEFAULT.description)
@Argument(
value = "-Xbuild-file",
@@ -131,7 +131,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Path to the .xml build file to compile"
)
var buildFile: String? by FreezableVar(null)
var buildFile: String? by NullableStringFreezableVar(null)
@Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade")
var inheritMultifileParts: Boolean by FreezableVar(false)
@@ -157,7 +157,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Path to JSON file to dump Java to Kotlin declaration mappings"
)
var declarationsOutputPath: String? by FreezableVar(null)
var declarationsOutputPath: String? by NullableStringFreezableVar(null)
@Argument(value = "-Xsingle-module", description = "Combine modules for source files and binary dependencies into a single module")
var singleModule: Boolean by FreezableVar(false)
@@ -218,7 +218,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
description = "Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl).\n" +
"Default value is 'enable'"
)
var supportCompatqualCheckerFrameworkAnnotations: String? by FreezableVar(null)
var supportCompatqualCheckerFrameworkAnnotations: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xno-exception-on-explicit-equals-for-boxed-null",
@@ -22,7 +22,7 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
}
@Argument(value = "-d", valueDescription = "<directory|jar>", description = "Destination for generated .kotlin_metadata files")
var destination: String? by FreezableVar(null)
var destination: String? by NullableStringFreezableVar(null)
@Argument(
value = "-classpath",
@@ -30,10 +30,10 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
valueDescription = "<path>",
description = "Paths where to find library .kotlin_metadata files"
)
var classpath: String? by FreezableVar(null)
var classpath: String? by NullableStringFreezableVar(null)
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
var moduleName: String? by FreezableVar(null)
var moduleName: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xjps",