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