MessageChain.firstOrNull rather than MessageChain.getOrNull on JVM

This commit is contained in:
Him188 2020-04-20 17:06:28 +08:00
parent 0689f84bf8
commit c4b3eade4a

View File

@ -60,15 +60,18 @@ interface MessageChain : Message, Iterable<SingleMessage> {
* @param key 由各个类型消息的伴生对象持有. [PlainText.Key]
* @throws NoSuchElementException 当找不到这个类型的 [Message]
*/
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("first")
operator fun <M : Message> get(key: Message.Key<M>): M = first(key)
/* final */ operator fun <M : Message> get(key: Message.Key<M>): M = first(key)
/**
* 获取第一个类型为 [key] [Message] 实例, 找不到则返回 `null`
*
* @param key 由各个类型消息的伴生对象持有. [PlainText.Key]
*/
fun <M : Message> getOrNull(key: Message.Key<M>): M? = firstOrNull(key)
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("firstOrNull")
/* final */ fun <M : Message> getOrNull(key: Message.Key<M>): M? = firstOrNull(key)
/**
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face], [XmlMessage], [QuoteReply].
@ -94,11 +97,19 @@ interface MessageChain : Message, Iterable<SingleMessage> {
this.forEach(block)
}
@PlannedRemoval("1.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmSynthetic
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME")
@JvmName("get")
fun <M : Message> get2(key: Message.Key<M>): M = first(key)
@PlannedRemoval("1.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmSynthetic
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME")
@JvmName("getOrNull")
fun <M : Message> getOrNull2(key: Message.Key<M>): M? = getOrNull(key)
}
// region accessors