mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Public API stabilization
This commit is contained in:
parent
259d0f90d5
commit
74f56c1e70
@ -52,6 +52,7 @@ kotlin {
|
||||
useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
|
||||
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
|
||||
useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
|
||||
useExperimentalAnnotation("net.mamoe.mirai.console.data.ExperimentalPluginConfig")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_SUPER_CLASS", "NOTHING_TO_INLINE")
|
||||
@file:JvmName("PluginDataKt")
|
||||
|
||||
package net.mamoe.mirai.console.data
|
||||
|
||||
@ -24,28 +25,6 @@ import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KType
|
||||
|
||||
|
||||
/**
|
||||
* 序列化之后的名称.
|
||||
*
|
||||
* 例:
|
||||
* ```
|
||||
* @SerialName("accounts")
|
||||
* object AccountPluginData : PluginData by ... {
|
||||
* @SerialName("info")
|
||||
* val map: Map<String, String> by value("a" to "b")
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* 将被保存为配置 (YAML 作为示例):
|
||||
* ```yaml
|
||||
* accounts:
|
||||
* info:
|
||||
* a: b
|
||||
* ```
|
||||
*/
|
||||
public typealias SerialName = kotlinx.serialization.SerialName
|
||||
|
||||
/**
|
||||
* 一个插件内部的, 对用户隐藏的数据对象. 可包含对多个 [Value] 的值变更的跟踪.
|
||||
*
|
||||
@ -210,7 +189,12 @@ public inline fun <reified T> PluginData.value(default: T): SerializerAwareValue
|
||||
*/
|
||||
@LowPriorityInOverloadResolution
|
||||
public inline fun <reified T> PluginData.value(): SerializerAwareValue<T> =
|
||||
value(T::class.run { objectInstance ?: createInstanceSmart() } as T)
|
||||
valueImpl(typeOf0<T>(), T::class)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@PublishedApi
|
||||
internal fun <T> PluginData.valueImpl(type: KType, classifier: KClass<*>): SerializerAwareValue<T> =
|
||||
valueFromKType(type, classifier.run { objectInstance ?: createInstanceSmart() } as T)
|
||||
|
||||
/**
|
||||
* 通过一个特定的 [KType] 创建 [Value], 并设置初始值.
|
||||
|
@ -0,0 +1,22 @@
|
||||
package net.mamoe.mirai.console.data
|
||||
|
||||
/**
|
||||
* 序列化之后的名称.
|
||||
*
|
||||
* 例:
|
||||
* ```
|
||||
* @SerialName("accounts")
|
||||
* object AccountPluginData : PluginData by ... {
|
||||
* @SerialName("info")
|
||||
* val map: Map<String, String> by value("a" to "b")
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* 将被保存为配置 (YAML 作为示例):
|
||||
* ```yaml
|
||||
* accounts:
|
||||
* info:
|
||||
* a: b
|
||||
* ```
|
||||
*/
|
||||
public typealias SerialName = kotlinx.serialization.SerialName
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.data
|
||||
|
@ -28,7 +28,6 @@ private val primitiveCollectionsImplemented by lazy {
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
internal inline fun <reified T> typeOf0(): KType = kotlin.reflect.typeOf<T>()
|
||||
|
||||
@PublishedApi
|
||||
@Suppress("UnsafeCall", "SMARTCAST_IMPOSSIBLE", "UNCHECKED_CAST")
|
||||
internal fun PluginData.valueFromKTypeImpl(type: KType): SerializerAwareValue<*> {
|
||||
val classifier = type.classifier
|
||||
|
Loading…
Reference in New Issue
Block a user