From 0b7d5ba223657f0a5de33862871a2355e7235c18 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 9 Jun 2024 07:27:18 -0230 Subject: Backend: Dev Modules (#2011) Co-authored-by: Cal --- .../skyhanni/skyhannimodule/ModuleProcessor.kt | 17 ++++++++++++++--- .../hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'annotation-processors/src/main/kotlin/at') diff --git a/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/ModuleProcessor.kt b/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/ModuleProcessor.kt index 568164133..99d7904d0 100644 --- a/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/ModuleProcessor.kt +++ b/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/ModuleProcessor.kt @@ -76,6 +76,12 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg return symbol } + //TODO remove when KMixins added as it contains KSP annotation helpers. + private fun isDevAnnotation(klass: KSClassDeclaration): Boolean { + val annotation = klass.annotations.find { it.shortName.asString() == "SkyHanniModule" } ?: return false + return annotation.arguments.find { it.name?.asString() == "devOnly" }?.value as? Boolean ?: false + } + // TODO use Kotlin Poet once KMixins is merged private fun generateFile(symbols: List) { @@ -92,13 +98,18 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg OutputStreamWriter(file).use { it.write("package at.hannibal2.skyhanni.skyhannimodule\n\n") it.write("object LoadedModules {\n") - it.write(" val modules: List = listOf(\n") + it.write(" val isDev: Boolean = at.hannibal2.skyhanni.utils.system.PlatformUtils.isDevEnvironment\n") + it.write(" val modules: List = buildList {\n") symbols.forEach { symbol -> - it.write(" ${symbol.qualifiedName!!.asString()},\n") + if (isDevAnnotation(symbol)) { + it.write(" if (isDev) add(${symbol.qualifiedName!!.asString()})\n") + } else { + it.write(" add(${symbol.qualifiedName!!.asString()})\n") + } } - it.write(" )\n") + it.write(" }\n") it.write("}\n") } diff --git a/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt b/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt index cb6b0eae4..c854a572c 100644 --- a/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt +++ b/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt @@ -2,4 +2,9 @@ package at.hannibal2.skyhanni.skyhannimodule @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.SOURCE) -annotation class SkyHanniModule +annotation class SkyHanniModule( + /** + * If the module will only be loaded in a development environment. + */ + val devOnly: Boolean = false, +) -- cgit