mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Rearrange implementations
This commit is contained in:
parent
3c36bb7660
commit
a7eaf788ac
@ -9,6 +9,7 @@
|
||||
|
||||
package net.mamoe.mirai.console.codegen
|
||||
|
||||
import org.intellij.lang.annotations.Language
|
||||
import java.io.File
|
||||
|
||||
|
||||
@ -48,6 +49,9 @@ import kotlinx.serialization.builtins.*
|
||||
""".trimIndent()
|
||||
|
||||
fun genAllValueUseSite(): String = buildString {
|
||||
fun appendln(@Language("kt") code: String) {
|
||||
this.appendln(code.trimIndent())
|
||||
}
|
||||
// PRIMITIVE
|
||||
for (number in NUMBERS + OTHER_PRIMITIVES) {
|
||||
appendln(genValueUseSite(number, number))
|
||||
@ -73,6 +77,7 @@ fun genAllValueUseSite(): String = buildString {
|
||||
// MUTABLE LIST / MUTABLE SET
|
||||
for (collectionName in listOf("List", "Set")) {
|
||||
for (number in NUMBERS + OTHER_PRIMITIVES) {
|
||||
appendln()
|
||||
appendln(
|
||||
"""
|
||||
@JvmName("valueMutable")
|
||||
@ -81,6 +86,33 @@ fun genAllValueUseSite(): String = buildString {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// SPECIAL
|
||||
appendln()
|
||||
appendln(
|
||||
"""
|
||||
fun <T : Setting> Setting.value(default: T): Value<T> {
|
||||
require(this::class != default::class) {
|
||||
"Recursive nesting is prohibited"
|
||||
}
|
||||
return valueImpl(default)
|
||||
}
|
||||
|
||||
inline fun <T : Setting> Setting.value(default: T, crossinline initializer: T.() -> Unit): Value<T> =
|
||||
value(default).also { it.value.apply(initializer) }
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: List<T>): SettingListValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableList<T>): MutableSettingListValue<T> = valueImpl(default)
|
||||
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: Set<T>): SettingSetValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableSet<T>): MutableSettingSetValue<T> = valueImpl(default)
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun genValueUseSite(kotlinTypeName: String, miraiValueName: String): String =
|
||||
|
@ -21,7 +21,7 @@ fun main() {
|
||||
}.writeText(genPublicApi())
|
||||
}
|
||||
|
||||
internal const val COPYRIGHT = """
|
||||
internal val COPYRIGHT = """
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
@ -30,7 +30,7 @@ internal const val COPYRIGHT = """
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
"""
|
||||
""".trim()
|
||||
|
||||
internal val NUMBERS = listOf(
|
||||
"Int",
|
||||
|
@ -45,25 +45,3 @@ abstract class Setting : AbstractSetting() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val <T : Setting> T.serializer: KSerializer<T>
|
||||
get() = kotlinSerializer as KSerializer<T>
|
||||
|
||||
|
||||
fun <T : Setting> Setting.value(default: T): Value<T> {
|
||||
require(this::class != default::class) {
|
||||
"Recursive nesting is prohibited"
|
||||
}
|
||||
return valueImpl(default)
|
||||
}
|
||||
|
||||
inline fun <T : Setting> Setting.value(default: T, crossinline initializer: T.() -> Unit): Value<T> =
|
||||
value(default).also { it.value.apply(initializer) }
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: List<T>): SettingListValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableList<T>): MutableSettingListValue<T> = valueImpl(default)
|
||||
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: Set<T>): SettingSetValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableSet<T>): MutableSettingSetValue<T> = valueImpl(default)
|
||||
|
@ -33,6 +33,7 @@ internal inline fun <reified T : Setting> Setting.valueImpl(
|
||||
): MutableSettingListValue<T> = valueImpl(default, T::class.createInstance().serializer)
|
||||
|
||||
|
||||
/*
|
||||
@PublishedApi
|
||||
@JvmName("valueImpl1")
|
||||
internal fun <T : Any> Setting.valueImpl(
|
||||
@ -40,7 +41,7 @@ internal fun <T : Any> Setting.valueImpl(
|
||||
valueMapper: (T) -> Value<T>,
|
||||
elementSerializer: KSerializer<T>
|
||||
): MutableListValue<T> = valueImpl(default.mapTo(mutableListOf(), valueMapper), valueMapper, elementSerializer)
|
||||
|
||||
*/
|
||||
internal fun <T : Any> Setting.valueImpl(
|
||||
default: MutableList<Value<T>>,
|
||||
valueMapper: (T) -> Value<T>,
|
||||
@ -225,7 +226,7 @@ internal inline fun <reified T : Setting> Setting.valueImpl(
|
||||
default: MutableSet<T>
|
||||
): MutableSettingSetValue<T> = valueImpl(default, T::class.createInstance().serializer)
|
||||
|
||||
|
||||
/*
|
||||
@JvmName("valueImpl1")
|
||||
@PublishedApi
|
||||
internal fun <T : Any> Setting.valueImpl(
|
||||
@ -233,7 +234,7 @@ internal fun <T : Any> Setting.valueImpl(
|
||||
valueMapper: (T) -> Value<T>,
|
||||
elementSerializer: KSerializer<T>
|
||||
): MutableSetValue<T> = valueImpl(default.mapTo(mutableSetOf(), valueMapper), valueMapper, elementSerializer)
|
||||
|
||||
*/
|
||||
@JvmName("valueImplMutable")
|
||||
internal fun <T : Any> Setting.valueImpl(
|
||||
default: MutableSet<Value<T>>,
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
@ -116,3 +115,24 @@ fun Setting.value(default: MutableSet<Char>): MutableCharSetValue = valueImpl(de
|
||||
@JvmName("valueMutable")
|
||||
fun Setting.value(default: MutableSet<String>): MutableStringSetValue = valueImpl(default)
|
||||
|
||||
fun <T : Setting> Setting.value(default: T): Value<T> {
|
||||
require(this::class != default::class) {
|
||||
"Recursive nesting is prohibited"
|
||||
}
|
||||
return valueImpl(default)
|
||||
}
|
||||
|
||||
inline fun <T : Setting> Setting.value(default: T, crossinline initializer: T.() -> Unit): Value<T> =
|
||||
value(default).also { it.value.apply(initializer) }
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: List<T>): SettingListValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableList<T>): MutableSettingListValue<T> = valueImpl(default)
|
||||
|
||||
|
||||
inline fun <reified T : Setting> Setting.value(default: Set<T>): SettingSetValue<T> = valueImpl(default)
|
||||
|
||||
@JvmName("valueMutable")
|
||||
inline fun <reified T : Setting> Setting.value(default: MutableSet<T>): MutableSettingSetValue<T> = valueImpl(default)
|
||||
|
||||
|
@ -62,31 +62,24 @@ sealed class PrimitiveArrayValue<T : Any> : ArrayValue<T>()
|
||||
abstract class IntArrayValue internal constructor() : PrimitiveArrayValue<IntArray>(), Iterable<Int> {
|
||||
override fun iterator(): Iterator<Int> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class ShortArrayValue internal constructor() : PrimitiveArrayValue<ShortArray>(), Iterable<Short> {
|
||||
override fun iterator(): Iterator<Short> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class ByteArrayValue internal constructor() : PrimitiveArrayValue<ByteArray>(), Iterable<Byte> {
|
||||
override fun iterator(): Iterator<Byte> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class LongArrayValue internal constructor() : PrimitiveArrayValue<LongArray>(), Iterable<Long> {
|
||||
override fun iterator(): Iterator<Long> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class FloatArrayValue internal constructor() : PrimitiveArrayValue<FloatArray>(), Iterable<Float> {
|
||||
override fun iterator(): Iterator<Float> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class DoubleArrayValue internal constructor() : PrimitiveArrayValue<DoubleArray>(), Iterable<Double> {
|
||||
override fun iterator(): Iterator<Double> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class BooleanArrayValue internal constructor() : PrimitiveArrayValue<BooleanArray>(), Iterable<Boolean> {
|
||||
override fun iterator(): Iterator<Boolean> = this.value.iterator()
|
||||
}
|
||||
|
||||
abstract class CharArrayValue internal constructor() : PrimitiveArrayValue<CharArray>(), Iterable<Char> {
|
||||
override fun iterator(): Iterator<Char> = this.value.iterator()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user