@@ -52,6 +52,9 @@ private val IntentsClassName = ClassName(INTENTS_PACKAGE, INTENTS_CLASS_NAME)
52
52
53
53
private const val NO_WARP = " ·"
54
54
55
+ private const val EVENT_NAME_BASED_MARKER_NAME = " EventNameBasedMarker"
56
+ private const val EVENT_NAME_BASED_MARKER_PKG = " love.forte.simbot.qguild.internal"
57
+
55
58
/* *
56
59
* 寻找所有 `love.forte.simbot.qguild.event.EventIntents` 的子 `object` 类型,
57
60
* 并生成它们 intents 的各种聚合到 `EventIntentsAggregation` 中。
@@ -99,7 +102,10 @@ internal class EventIntentsAggregationProcessor(
99
102
100
103
val fileBuilder = FileSpec .builder(OUTPUT_PACKAGE , AGGREGATION_FILE_NAME )
101
104
fileBuilder.addType(aggregationBuilder.build())
102
- fileBuilder.addFileComment(" 本文件内容为自动生成,生成于 %L" , OffsetDateTime .now(ZoneOffset .ofHours(8 )).toString())
105
+ fileBuilder.addFileComment(
106
+ " 本文件内容为自动生成,生成于 %L" ,
107
+ OffsetDateTime .now(ZoneOffset .ofHours(8 )).toString()
108
+ )
103
109
104
110
val targetFile = fileBuilder.build()
105
111
@@ -198,14 +204,40 @@ internal class EventIntentsAggregationProcessor(
198
204
data class NamesToType (val names : Set <String >, val declaration : KSClassDeclaration )
199
205
200
206
val nameToTypes = list.map { declaration ->
201
- val baseName = declaration.simpleName.asString()
207
+ val nameBasedAnnotation = declaration.annotations
208
+ .firstOrNull {
209
+ (it.annotationType.resolve().declaration as ? KSClassDeclaration )?.let { annoDecl ->
210
+ annoDecl.simpleName.asString() == EVENT_NAME_BASED_MARKER_NAME
211
+ && annoDecl.packageName.asString() == EVENT_NAME_BASED_MARKER_PKG
212
+ } ? : false
213
+ }
214
+
215
+ fun baseName (): String = declaration.simpleName.asString()
216
+
217
+ fun findFromAnnotation (name : String ): String? =
218
+ nameBasedAnnotation?.arguments?.firstOrNull {
219
+ it.name?.asString() == name
220
+ }?.value as ? String?
221
+
222
+ val firstUpper = findFromAnnotation(" firstUpper" )
223
+ ?.takeUnless { it.isBlank() }
224
+ ? : baseName()
225
+ val firstLower = findFromAnnotation(" firstLower" )
226
+ ?.takeUnless { it.isBlank() }
227
+ ? : baseName().replaceFirstChar(Char ::lowercaseChar)
228
+ val snackUpper = findFromAnnotation(" snackUpper" )
229
+ ?.takeUnless { it.isBlank() }
230
+ ? : baseName().toSnack(true )
231
+ val snackLower = findFromAnnotation(" snackLower" )
232
+ ?.takeUnless { it.isBlank() }
233
+ ? : baseName().toSnack(false )
234
+
235
+
202
236
val set = setOf (
203
- baseName,
204
- // 开头小写
205
- baseName.replaceFirstChar(Char ::lowercaseChar),
206
- // 下划线的全大写与全小写
207
- baseName.toSnack(false ),
208
- baseName.toSnack(true )
237
+ firstUpper,
238
+ firstLower,
239
+ snackUpper,
240
+ snackLower,
209
241
)
210
242
211
243
NamesToType (set, declaration)
0 commit comments