@@ -68,28 +68,28 @@ internal fun Any.flattenCommandComponents(): MessageChain = buildMessageChain {
68
68
internal object CompositeCommandSubCommandAnnotationResolver :
69
69
SubCommandAnnotationResolver <Command > {
70
70
override fun isDeclaredSubCommand (ownerCommand : Command , function : KFunction <* >) =
71
- function.hasAnnotation<SubCommandGroup .SubCommand >()
71
+ function.hasAnnotation<CompositeCommand .SubCommand >()
72
72
73
73
override fun getDeclaredSubCommandNames (ownerCommand : Command , function : KFunction <* >): Array <out String > {
74
- val annotated = function.findAnnotation<SubCommandGroup .SubCommand >()!! .value
74
+ val annotated = function.findAnnotation<CompositeCommand .SubCommand >()!! .value
75
75
return if (annotated.isEmpty()) arrayOf(function.name)
76
76
else annotated
77
77
}
78
78
79
79
override fun getAnnotatedName (ownerCommand : Command , parameter : KParameter ): String? =
80
- parameter.findAnnotation<SubCommandGroup .Name >()?.value
80
+ parameter.findAnnotation<CompositeCommand .Name >()?.value
81
81
82
82
override fun getDescription (ownerCommand : Command , function : KFunction <* >): String? =
83
- function.findAnnotation<SubCommandGroup .Description >()?.value
83
+ function.findAnnotation<CompositeCommand .Description >()?.value
84
84
85
85
override fun isCombinedSubCommands (command : Command , kProperty : KProperty <* >): Boolean =
86
- kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >() || kProperty.hasAnnotation<SubCommandGroup .SubCommand >()
86
+ kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >() || kProperty.hasAnnotation<CompositeCommand .SubCommand >()
87
87
88
88
override fun getCombinedAdditionNames (command : Command , kProperty : KProperty <* >): Array <out String > {
89
89
return if (kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >()) {
90
90
emptyArray()
91
91
} else {
92
- val annotated = kProperty.findAnnotation<SubCommandGroup .SubCommand >()!! .value
92
+ val annotated = kProperty.findAnnotation<CompositeCommand .SubCommand >()!! .value
93
93
if (annotated.isEmpty()) arrayOf(kProperty.name)
94
94
else annotated
95
95
}
@@ -100,28 +100,26 @@ internal object CompositeCommandSubCommandAnnotationResolver :
100
100
internal object GroupedCommandSubCommandAnnotationResolver :
101
101
SubCommandAnnotationResolver <Any > {
102
102
override fun isDeclaredSubCommand (ownerCommand : Any , function : KFunction <* >) =
103
- function.hasAnnotation<SubCommandGroup .SubCommand >()
103
+ function.hasAnnotation<CompositeCommand .SubCommand >()
104
104
105
105
override fun getDeclaredSubCommandNames (ownerCommand : Any , function : KFunction <* >): Array <out String > {
106
- val annotated = function.findAnnotation<SubCommandGroup .SubCommand >()!! .value
106
+ val annotated = function.findAnnotation<CompositeCommand .SubCommand >()!! .value
107
107
return if (annotated.isEmpty()) arrayOf(function.name)
108
108
else annotated
109
109
}
110
110
111
- override fun getAnnotatedName (ownerCommand : Any , parameter : KParameter ): String? =
112
- parameter.findAnnotation<SubCommandGroup .Name >()?.value
111
+ override fun getAnnotatedName (ownerCommand : Any , parameter : KParameter ): String? = null
113
112
114
- override fun getDescription (ownerCommand : Any , function : KFunction <* >): String? =
115
- function.findAnnotation<SubCommandGroup .Description >()?.value
113
+ override fun getDescription (ownerCommand : Any , function : KFunction <* >): String? = null
116
114
117
115
override fun isCombinedSubCommands (command : Any , kProperty : KProperty <* >): Boolean =
118
- kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >() || kProperty.hasAnnotation<SubCommandGroup .SubCommand >()
116
+ kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >() || kProperty.hasAnnotation<CompositeCommand .SubCommand >()
119
117
120
118
override fun getCombinedAdditionNames (command : Any , kProperty : KProperty <* >): Array <out String > {
121
119
return if (kProperty.hasAnnotation<SubCommandGroup .FlattenSubCommands >()) {
122
120
emptyArray()
123
121
} else {
124
- val annotated = kProperty.findAnnotation<SubCommandGroup .SubCommand >()!! .value
122
+ val annotated = kProperty.findAnnotation<CompositeCommand .SubCommand >()!! .value
125
123
if (annotated.isEmpty()) arrayOf(kProperty.name)
126
124
else annotated
127
125
}
@@ -152,11 +150,29 @@ internal object SimpleCommandSubCommandAnnotationResolver :
152
150
}
153
151
154
152
internal interface SubCommandAnnotationResolver <T > {
153
+ /* *
154
+ * 判断ownerCommand中的一个function是否能成为SubCommand
155
+ */
155
156
fun isDeclaredSubCommand (ownerCommand : T , function : KFunction <* >): Boolean
157
+ /* *
158
+ * 得出ownerCommand中的一个function成为SubCommand时的名字列表
159
+ */
156
160
fun getDeclaredSubCommandNames (ownerCommand : T , function : KFunction <* >): Array <out String >
161
+ /* *
162
+ * 得出ownerCommand中的一个function成为SubCommand时其参数表中的参数的描述
163
+ */
157
164
fun getAnnotatedName (ownerCommand : T , parameter : KParameter ): String?
165
+ /* *
166
+ * 得出ownerCommand中的一个function成为SubCommand时的描述
167
+ */
158
168
fun getDescription (ownerCommand : T , function : KFunction <* >): String?
169
+ /* *
170
+ * 判断ownerCommand中的一个kProperty是否能成为SubCommand
171
+ */
159
172
fun isCombinedSubCommands (command : T , kProperty : KProperty <* >): Boolean
173
+ /* *
174
+ * 得出ownerCommand中的一个kProperty成为SubCommand时的指令路径的增加部分
175
+ */
160
176
fun getCombinedAdditionNames (command : T , kProperty : KProperty <* >): Array <out String >
161
177
}
162
178
0 commit comments