From 76aee625e5097002d7d6fa8f3df659e9fc2a8e4c Mon Sep 17 00:00:00 2001 From: Elizabeth Worstell Date: Mon, 6 Nov 2023 16:09:38 -0800 Subject: [PATCH] fix kotlin verb registry --- .../kotlin/xyz/block/ftl/registry/Registry.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/registry/Registry.kt b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/registry/Registry.kt index 0ac64e28be..888241a527 100644 --- a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/registry/Registry.kt +++ b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/registry/Registry.kt @@ -8,7 +8,9 @@ import xyz.block.ftl.logging.Logging import java.util.concurrent.ConcurrentHashMap import kotlin.reflect.KClass import kotlin.reflect.KFunction +import kotlin.reflect.full.declaredFunctions import kotlin.reflect.full.findAnnotation +import kotlin.reflect.full.functions import kotlin.reflect.full.hasAnnotation import kotlin.reflect.jvm.kotlinFunction @@ -56,18 +58,16 @@ class Registry(val jvmModuleName: String = defaultJvmModuleName) { ClassGraph() .enableAllInfo() // Scan classes, methods, fields, annotations .acceptPackages(jvmModuleName) - .scan().use { scanResult -> - // Use the ScanResult within the try block, e.g. - for (clazz in scanResult.getClassesWithMethodAnnotation(Verb::class.java)) { - val kClass = clazz.loadClass().kotlin - if (kClass.hasAnnotation()) return - clazz.methodInfo - .filter { info -> info.hasAnnotation(Verb::class.java) && !info.hasAnnotation(Ignore::class.java) } - .forEach { info -> - val function = info.loadClassAndGetMethod().kotlinFunction!! - maybeRegisterVerb(kClass, function) - } + .scan() + .getClassesWithMethodAnnotation(Verb::class.java) + .forEach { + val kClass = it.loadClass().kotlin + if (kClass.hasAnnotation()) { + return@forEach } + kClass.declaredFunctions + .filter { func -> func.hasAnnotation() && !func.hasAnnotation() } + .forEach { verb -> maybeRegisterVerb(kClass, verb) } } }