Cleanup: apply "Convert lambda to reference"

This commit is contained in:
Mikhail Glukhikh
2017-02-22 16:12:01 +03:00
parent b121bf8802
commit 045a23ae10
82 changed files with 117 additions and 135 deletions
@@ -89,8 +89,8 @@ class StringPropMapper<C, out P : KMutableProperty1<C, String>>(dest: C,
prop: P,
names: List<String> = listOf(),
fromString: ((String) -> String) = { it },
toString: ((String) -> String?) = { it.toString() },
skipIf: ((String) -> Boolean) = { it.isEmpty() },
toString: ((String) -> String?) = { it },
skipIf: ((String) -> Boolean) = String::isEmpty,
mergeDelimiter: String? = null)
: PropMapper<C, String, P>(dest = dest, prop = prop, names = if (names.any()) names else listOf(prop.name),
fromString = fromString, toString = toString, skipIf = skipIf, mergeDelimiter = mergeDelimiter)
@@ -212,13 +212,13 @@ data class DaemonOptions(
) : OptionsGroup {
override val mappers: List<PropMapper<*, *, *>>
get() = listOf(PropMapper(this, DaemonOptions::runFilesPath, fromString = { it.trimQuotes() }),
PropMapper(this, DaemonOptions::autoshutdownMemoryThreshold, fromString = { it.toLong() }, skipIf = { it == 0L }, mergeDelimiter = "="),
get() = listOf(PropMapper(this, DaemonOptions::runFilesPath, fromString = String::trimQuotes),
PropMapper(this, DaemonOptions::autoshutdownMemoryThreshold, fromString = String::toLong, skipIf = { it == 0L }, mergeDelimiter = "="),
// TODO: implement "use default" value without specifying default, so if client and server uses different defaults, it should not lead to many params in the cmd line; use 0 for it and used different val for infinite
PropMapper(this, DaemonOptions::autoshutdownIdleSeconds, fromString = { it.toInt() }, skipIf = { it == 0 }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::autoshutdownUnusedSeconds, fromString = { it.toInt() }, skipIf = { it == COMPILE_DAEMON_DEFAULT_UNUSED_TIMEOUT_S }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::shutdownDelayMilliseconds, fromString = { it.toLong() }, skipIf = { it == COMPILE_DAEMON_DEFAULT_SHUTDOWN_DELAY_MS }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::forceShutdownTimeoutMilliseconds, fromString = { it.toLong() }, skipIf = { it == COMPILE_DAEMON_FORCE_SHUTDOWN_DEFAULT_TIMEOUT_MS }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::autoshutdownIdleSeconds, fromString = String::toInt, skipIf = { it == 0 }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::autoshutdownUnusedSeconds, fromString = String::toInt, skipIf = { it == COMPILE_DAEMON_DEFAULT_UNUSED_TIMEOUT_S }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::shutdownDelayMilliseconds, fromString = String::toLong, skipIf = { it == COMPILE_DAEMON_DEFAULT_SHUTDOWN_DELAY_MS }, mergeDelimiter = "="),
PropMapper(this, DaemonOptions::forceShutdownTimeoutMilliseconds, fromString = String::toLong, skipIf = { it == COMPILE_DAEMON_FORCE_SHUTDOWN_DEFAULT_TIMEOUT_MS }, mergeDelimiter = "="),
BoolPropMapper(this, DaemonOptions::verbose),
BoolPropMapper(this, DaemonOptions::reportPerf))
}
@@ -73,10 +73,9 @@ object FileSystem {
val base = File(runtimeStateFilesBasePath)
// if base is not suitable, take home dir as a base and ensure the first name is prefixed with "." -
// this will work ok as a fallback solution on most systems
val dir = if (base.exists() && base.isDirectory) names.fold(base, { r, v -> File(r, v) })
val dir = if (base.exists() && base.isDirectory) names.fold(base, ::File)
else names.drop(1)
.fold(File(userHomePath, names.first().let { if (it.startsWith(".")) it else ".$it" }),
{ r, v -> File(r, v) })
.fold(File(userHomePath, names.first().let { if (it.startsWith(".")) it else ".$it" }), ::File)
return if ((dir.exists() && dir.isDirectory) || dir.mkdirs()) dir.absolutePath
else tempPath
}