org.jetbrains.kotlinx.jupyter.codegen.ClassAnnotationsProcessorImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-kernel Show documentation
Show all versions of kotlin-jupyter-kernel Show documentation
Kotlin Jupyter kernel published as artifact
package org.jetbrains.kotlinx.jupyter.codegen
import org.jetbrains.kotlinx.jupyter.api.ClassAnnotationHandler
import org.jetbrains.kotlinx.jupyter.api.ClassDeclarationsCallback
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
import org.jetbrains.kotlinx.jupyter.exceptions.LibraryProblemPart
import org.jetbrains.kotlinx.jupyter.exceptions.rethrowAsLibraryException
import kotlin.reflect.KClass
class ClassAnnotationsProcessorImpl : ClassAnnotationsProcessor {
private val handlers = mutableMapOf()
override fun register(handler: ClassAnnotationHandler) {
handlers[handler.annotation.qualifiedName!!] = handler.callback
}
override fun process(executedSnippet: KClass<*>, host: KotlinKernelHost) {
executedSnippet.nestedClasses
.flatMap { clazz -> clazz.annotations.map { it.annotationClass to clazz } }
.groupBy { it.first }
.forEach { (annotationClass, classesList) ->
val handler = handlers[annotationClass.qualifiedName!!]
if (handler != null) {
rethrowAsLibraryException(LibraryProblemPart.CLASS_ANNOTATIONS) {
handler(host, classesList.map { it.second })
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy