aboutsummaryrefslogtreecommitdiff
path: root/annotation-processors/src/main/kotlin/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorBrady <thatgravyboat@gmail.com>2024-06-09 07:27:18 -0230
committerGitHub <noreply@github.com>2024-06-09 11:57:18 +0200
commit0b7d5ba223657f0a5de33862871a2355e7235c18 (patch)
treef9bafed7c379d89c23d13af141b0dfa9df1dcc50 /annotation-processors/src/main/kotlin/at/hannibal2/skyhanni
parent1c13055266d04715b2292cc6ab107202a346adca (diff)
downloadskyhanni-0b7d5ba223657f0a5de33862871a2355e7235c18.tar.gz
skyhanni-0b7d5ba223657f0a5de33862871a2355e7235c18.tar.bz2
skyhanni-0b7d5ba223657f0a5de33862871a2355e7235c18.zip
Backend: Dev Modules (#2011)
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'annotation-processors/src/main/kotlin/at/hannibal2/skyhanni')
-rw-r--r--annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/ModuleProcessor.kt17
-rw-r--r--annotation-processors/src/main/kotlin/at/hannibal2/skyhanni/skyhannimodule/SkyHanniModule.kt7
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,
+)