diff options
Diffstat (limited to 'annotation-processors/src/main/kotlin/at')
2 files changed, 20 insertions, 4 deletions
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<KSClassDeclaration>) { @@ -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<Any> = listOf(\n") + it.write(" val isDev: Boolean = at.hannibal2.skyhanni.utils.system.PlatformUtils.isDevEnvironment\n") + it.write(" val modules: List<Any> = 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, +) |