Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix kotlin verb registry #565

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<Ignore>()) 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<Ignore>()) {
return@forEach
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this magical syntax?!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually it's not necessary but in the odd case comes in handy!

}
kClass.declaredFunctions
.filter { func -> func.hasAnnotation<Verb>() && !func.hasAnnotation<Ignore>() }
.forEach { verb -> maybeRegisterVerb(kClass, verb) }
}
}

Expand Down