diff options
author | Linnea Gräf <nea@nea.moe> | 2024-09-01 22:21:19 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-09-01 22:21:19 +0200 |
commit | 5ed74f2df49c93ed1617520a935078b59ad7e195 (patch) | |
tree | f0d52699fff7f820bd724902878988859bd43516 /symbols/src/main | |
parent | 816f80f862d2f5de6bc9b0ae84cd6df0da341228 (diff) | |
download | firmament-5ed74f2df49c93ed1617520a935078b59ad7e195.tar.gz firmament-5ed74f2df49c93ed1617520a935078b59ad7e195.tar.bz2 firmament-5ed74f2df49c93ed1617520a935078b59ad7e195.zip |
Add per compat project event listeners
[no changelog]
Diffstat (limited to 'symbols/src/main')
-rw-r--r-- | symbols/src/main/kotlin/process/SubscribeAnnotationProcessor.kt | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/symbols/src/main/kotlin/process/SubscribeAnnotationProcessor.kt b/symbols/src/main/kotlin/process/SubscribeAnnotationProcessor.kt index 307f5c3..e6fcd89 100644 --- a/symbols/src/main/kotlin/process/SubscribeAnnotationProcessor.kt +++ b/symbols/src/main/kotlin/process/SubscribeAnnotationProcessor.kt @@ -1,4 +1,3 @@ - package moe.nea.firmament.annotations.process import com.google.auto.service.AutoService @@ -16,23 +15,24 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.Nullability import com.google.devtools.ksp.validate -import java.text.SimpleDateFormat -import java.util.Date import moe.nea.firmament.annotations.Subscribe class SubscribeAnnotationProcessor( val logger: KSPLogger, val codeGenerator: CodeGenerator, + val sourceSetName: String, ) : SymbolProcessor { override fun finish() { subscriptions.sort() + if (subscriptions.isEmpty()) return val subscriptionSet = subscriptions.mapTo(mutableSetOf()) { it.parent.containingFile!! } val dependencies = Dependencies( aggregating = true, *subscriptionSet.toTypedArray()) + val generatedFileName = "AllSubscriptions${sourceSetName.replaceFirstChar { it.uppercaseChar() }}" val subscriptionsFile = codeGenerator - .createNewFile(dependencies, "moe.nea.firmament.annotations.generated", "AllSubscriptions") + .createNewFile(dependencies, "moe.nea.firmament.annotations.generated", generatedFileName) .bufferedWriter() subscriptionsFile.apply { appendLine("// This file is @generated by SubscribeAnnotationProcessor") @@ -44,8 +44,8 @@ class SubscribeAnnotationProcessor( appendLine() appendLine("import moe.nea.firmament.events.subscription.*") appendLine() - appendLine("object AllSubscriptions {") - appendLine(" fun provideSubscriptions(addSubscription: (Subscription<*>) -> Unit) {") + appendLine("class $generatedFileName : SubscriptionList {") + appendLine(" override fun provideSubscriptions(addSubscription: (Subscription<*>) -> Unit) {") for (subscription in subscriptions) { val owner = subscription.parent.qualifiedName!!.asString() val method = subscription.child.simpleName.asString() @@ -53,12 +53,20 @@ class SubscribeAnnotationProcessor( appendLine(" addSubscription(Subscription<$type>(") appendLine(" ${owner},") appendLine(" ${owner}::${method},") - appendLine(" ${type}))") + appendLine(" ${type},") + appendLine(" \"${method}\"))") } appendLine(" }") appendLine("}") } subscriptionsFile.close() + val metaInf = codeGenerator.createNewFileByPath( + Dependencies(false), + "META-INF/services/moe.nea.firmament.events.subscription.SubscriptionList", extensionName = "") + .bufferedWriter() + metaInf.append("moe.nea.firmament.annotations.generated.") + metaInf.appendLine(generatedFileName) + metaInf.close() } data class Subscription( @@ -121,6 +129,8 @@ class SubscribeAnnotationProcessor( @AutoService(SymbolProcessorProvider::class) class SubscribeAnnotationProcessorProvider : SymbolProcessorProvider { override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { - return SubscribeAnnotationProcessor(environment.logger, environment.codeGenerator) + return SubscribeAnnotationProcessor(environment.logger, + environment.codeGenerator, + environment.options["firmament.sourceset"] ?: "main") } } |