Wizard: minor, remove unused functions

This commit is contained in:
Ilya Kirillov
2020-03-07 23:06:16 +03:00
parent 2460f6cfe6
commit 693e12d826
4 changed files with 1 additions and 53 deletions
@@ -25,14 +25,6 @@ abstract class Parser<out T : Any> {
abstract fun ParsingContext.parse(value: Any?, path: String): TaskResult<T>
}
fun <T : Any> alwaysFailingParser() = object : Parser<T>() {
override fun ParsingContext.parse(value: Any?, path: String): TaskResult<T> =
Failure(object : Error() {
override val message: String
get() = "Should not be called"
})
}
fun <T : Any> Parser<T>.parse(context: ParsingContext, value: Any?, path: String) =
with(context) { parse(value, path) }
@@ -90,40 +82,6 @@ inline fun <reified T : Any> valueParser() = valueParser { value, path ->
value.parseAs(path, T::class).get()
}
class DisjunctionParser<T : Any>(
private val keyToParser: Map<String, Parser<T>>
) : Parser<T>() {
constructor(vararg keyToParser: Pair<String, Parser<T>>) : this(keyToParser.toMap())
override fun ParsingContext.parse(value: Any?, path: String): TaskResult<T> = when (value) {
is String -> // consider string value as an empty map
mapOf(value to emptyMap<Any?, Any?>()).asSuccess()
else -> value.parseAs<Map<*, *>>(path)
}.flatMap { map ->
computeM {
val (singleItem) = map.entries.singleOrNull()
?.takeIf { it.key is String }
.toResult { ParseError("Setting `$path` should contain a single-key value") }
val (parser) = keyToParser[singleItem.key as String]
.toResult { ParseError("`$path` should be one of [${keyToParser.keys.joinToString()}]") }
parser.parse(this@parse, singleItem.value, path)
}
}
}
class CollectingParser<T : Any>(
private val keyToParser: Map<String, Parser<T>>
) : Parser<List<T>>() {
override fun ParsingContext.parse(value: Any?, path: String): TaskResult<List<T>> =
value.parseAs<Map<*, *>, List<T>>(this, path) { map ->
map.mapNotNull { (key, value) ->
val parser = keyToParser[key] ?: return@mapNotNull null
parser.parse(this, value, "$path.$key")
}.sequence()
}
}
fun Any?.classMismatchError(path: String, expected: KClass<*>): ParseError {
val classpath = this?.let { it::class.simpleName } ?: "null"
return ParseError("Expected ${expected.simpleName!!} for `$path` but $classpath was found")
@@ -23,8 +23,6 @@ fun <V> inValidatorContext(validator: ReadingContext.(V) -> SettingValidator<V>)
typealias StringValidator = SettingValidator<String>
object StringValidators {
fun shouldNotBeBlank(name: String) = settingValidator { value: String ->
if (value.isBlank()) ValidationResult.ValidationError("${name.capitalize()} should not be blank ")
@@ -254,8 +254,7 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
.forEach { (id, configurators) -> assert(configurators.size == 1) { id } }
}
val BY_ID = ALL.associateBy(ModuleConfigurator::id)
val BY_MODULE_KIND = ALL.groupBy(ModuleConfigurator::moduleKind)
private val BY_ID = ALL.associateBy(ModuleConfigurator::id)
fun getParser(moduleIdentificator: Identificator): Parser<ModuleConfigurator> =
valueParserM { value, path ->
@@ -119,13 +119,6 @@ class Module(
}
val Module.mainSourceset: Sourceset?
get() = sourcesets.firstOrNull { it.sourcesetType == SourcesetType.main }
val Module.testSourceset: Sourceset?
get() = sourcesets.firstOrNull { it.sourcesetType == SourcesetType.test }
val Module.path
get() = generateSequence(this, Module::parent)
.map { it.name }