diff options
author | Linnea Gräf <nea@nea.moe> | 2024-10-13 17:32:10 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-10-13 17:32:10 +0200 |
commit | e6142bb93619dee768fc18b87ffdd28558d4bcab (patch) | |
tree | 03df79712151f7579cd683c8340741ebb3191822 /symbols | |
parent | daa63bd914a2f6c5e9b668abb8474884685ee818 (diff) | |
download | Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.tar.gz Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.tar.bz2 Firmament-e6142bb93619dee768fc18b87ffdd28558d4bcab.zip |
Make pickaxe ability display use AbilityUtils
[no changelog]
Diffstat (limited to 'symbols')
-rw-r--r-- | symbols/src/main/kotlin/process/GameTestContainingClassProcessor.kt | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/symbols/src/main/kotlin/process/GameTestContainingClassProcessor.kt b/symbols/src/main/kotlin/process/GameTestContainingClassProcessor.kt new file mode 100644 index 0000000..4fcf91f --- /dev/null +++ b/symbols/src/main/kotlin/process/GameTestContainingClassProcessor.kt @@ -0,0 +1,80 @@ +package moe.nea.firmament.annotations.process + +import com.google.auto.service.AutoService +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.processing.CodeGenerator +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.processing.SymbolProcessor +import com.google.devtools.ksp.processing.SymbolProcessorEnvironment +import com.google.devtools.ksp.processing.SymbolProcessorProvider +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFile +import com.google.gson.Gson +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import java.io.OutputStreamWriter +import java.nio.charset.StandardCharsets +import java.util.TreeSet + +class GameTestContainingClassProcessor( + val logger: KSPLogger, + val codeGenerator: CodeGenerator, + val sourceSetName: String, +) : SymbolProcessor { + + + @AutoService(SymbolProcessorProvider::class) + class Provider : SymbolProcessorProvider { + override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { + return GameTestContainingClassProcessor( + environment.logger, + environment.codeGenerator, + environment.options["firmament.sourceset"] ?: "main") + } + } + + val allClasses: MutableSet<String> = TreeSet() + val allSources = mutableSetOf<KSFile>() + + override fun process(resolver: Resolver): List<KSAnnotated> { + val annotated = resolver.getSymbolsWithAnnotation("net.minecraft.test.GameTest").toList() + annotated.forEach { + val containingClass = it.parent as KSClassDeclaration + allClasses.add(containingClass.qualifiedName!!.asString()) + allSources.add(it.containingFile!!) + } + return emptyList() + } + + fun createJson(): JsonObject { + return JsonObject().apply { + addProperty("schemaVersion", 1) + addProperty("id", "firmament-gametest") + addProperty("name", "Firmament Gametest") + addProperty("version", "1.0.0") + addProperty("environment", "*") + add("entrypoints", JsonObject().apply { + add("fabric-gametest", JsonArray().apply { + allClasses.forEach { + add(it) + } + }) + }) + } + } + + override fun finish() { + if (allClasses.isEmpty()) return + val stream = codeGenerator.createNewFile(Dependencies(aggregating = true, *allSources.toTypedArray()), + "", + "fabric.mod", + "json") + val output = OutputStreamWriter(stream, StandardCharsets.UTF_8) + Gson().toJson(createJson(), output) + output.close() + } + +} |