Commit 1f308b30 authored by Him188's avatar Him188

Update docs

parent a9745071
...@@ -49,7 +49,7 @@ import kotlin.jvm.JvmSynthetic ...@@ -49,7 +49,7 @@ import kotlin.jvm.JvmSynthetic
* - 连接 [Message] 与 [Message], [String], (使用操作符 [Message.plus]): * - 连接 [Message] 与 [Message], [String], (使用操作符 [Message.plus]):
* ``` * ```
* val text = PlainText("Hello ") + PlainText("world") + "!" * val text = PlainText("Hello ") + PlainText("world") + "!"
* friend.sendMessage(text) * friend.sendMessage(text) // "Hello world!"
* ``` * ```
* 但注意: 不能 `String + Message`. 只能 `Message + String` * 但注意: 不能 `String + Message`. 只能 `Message + String`
* *
...@@ -177,18 +177,31 @@ interface Message { // must be interface. Don't consider any changes. ...@@ -177,18 +177,31 @@ interface Message { // must be interface. Don't consider any changes.
} }
} }
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: MessageChain): MessageChain = this + another as Message /* final */ operator fun plus(another: MessageChain): MessageChain = this + another as Message
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Message): MessageChain = this.followedBy(another) /* final */ operator fun plus(another: Message): MessageChain = this.followedBy(another)
/** 将 [another] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: SingleMessage): MessageChain = this.followedBy(another) /* final */ operator fun plus(another: SingleMessage): MessageChain = this.followedBy(another)
/** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage()) /* final */ operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage())
/** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: CharSequence): MessageChain = this.followedBy(another.toString().toMessage()) /* final */ operator fun plus(another: CharSequence): MessageChain = this.followedBy(another.toString().toMessage())
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Iterable<Message>): MessageChain = /* final */ operator fun plus(another: Iterable<Message>): MessageChain =
another.fold(this, Message::plus).asMessageChain() another.fold(this, Message::plus).asMessageChain()
/** 将 [another] 按顺序连接到这个消息的尾部. */
@JvmName("plusIterableString") @JvmName("plusIterableString")
/* final */ operator fun plus(another: Iterable<String>): MessageChain = /* final */ operator fun plus(another: Iterable<String>): MessageChain =
another.fold(this, Message::plus).asMessageChain() another.fold(this, Message::plus).asMessageChain()
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Sequence<Message>): MessageChain = /* final */ operator fun plus(another: Sequence<Message>): MessageChain =
another.fold(this, Message::plus).asMessageChain() another.fold(this, Message::plus).asMessageChain()
} }
......
...@@ -62,7 +62,22 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess { ...@@ -62,7 +62,22 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
/** /**
* 获取第一个类型为 [key] 的 [Message] 实例. 若不存在此实例, 返回 `null` * 获取第一个类型为 [key] 的 [Message] 实例. 若不存在此实例, 返回 `null`
* *
* ### Kotlin 使用方法
* ```
* val chain: MessageChain = ...
*
* val at = Message[At] // At 为伴生对象
* ```
*
* ### Java 使用方法
* ```java
* MessageChain chain = ...
* chain.first(At.Key)
* ```
*
* @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key] * @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key]
*
* @see MessageChain.getOrFail 在找不到此类型的元素时抛出 [NoSuchElementException]
*/ */
@JvmName("first") @JvmName("first")
final operator fun <M : Message> get(key: Message.Key<M>): M? = firstOrNull(key) final operator fun <M : Message> get(key: Message.Key<M>): M? = firstOrNull(key)
...@@ -93,7 +108,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess { ...@@ -93,7 +108,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
// region accessors // region accessors
/** /**
* 获取第一个类型为 [key] 的 [Message] 实例 * 获取第一个类型为 [key] 的 [Message] 实例, 在找不到此类型的元素时抛出 [NoSuchElementException]
* *
* @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key] * @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key]
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment