1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-24 20:43:33 +08:00

findSubCommds改为返回基类

This commit is contained in:
hundun 2022-06-26 10:26:15 +08:00
parent 1851e267a3
commit af4731535e
2 changed files with 5 additions and 10 deletions
mirai-console/backend/mirai-console/src

View File

@ -98,17 +98,12 @@ public abstract class CompositeCommand(
private val reflector by lazy { CommandReflector(this, CompositeCommandSubCommandAnnotationResolver) }
@ExperimentalCommandDescriptors
public val overloadImpls: List<@JvmWildcard CommandSignatureFromKFunctionImpl> by lazy {
public final override val overloads: List<@JvmWildcard CommandSignatureFromKFunction> by lazy {
reflector.findSubCommands().also {
reflector.validate(it)
}
}
@ExperimentalCommandDescriptors
public final override val overloads: List<@JvmWildcard CommandSignatureFromKFunction> by lazy {
overloadImpls
}
/**
* 自动根据带有 [SubCommand] 注解的函数签名生成 [usage]. 也可以被覆盖.
*/

View File

@ -227,7 +227,7 @@ internal class CommandReflector(
}
}
fun validate(signatures: List<CommandSignatureFromKFunctionImpl>) {
fun validate(signatures: List<CommandSignatureFromKFunction>) {
data class ErasedParameterInfo(
val index: Int,
@ -267,7 +267,7 @@ internal class CommandReflector(
}
@Throws(IllegalCommandDeclarationException::class)
fun findSubCommands(): List<CommandSignatureFromKFunctionImpl> {
fun findSubCommands(): List<CommandSignatureFromKFunction> {
val fromMemberFunctions = command::class.functions // exclude static later
.asSequence()
.filter { it.isSubCommandFunction() }
@ -358,10 +358,10 @@ internal class CommandReflector(
.filter { it is CompositeCommand }
.flatMap { property ->
property as CompositeCommand
property.overloadImpls
property.overloads
}.toList()
val list: MutableList<CommandSignatureFromKFunctionImpl> = ArrayList()
val list: MutableList<CommandSignatureFromKFunction> = ArrayList()
list.addAll(fromMemberFunctions)
list.addAll(fromMemberProperties)
return list