All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cultureamp.eventsourcing.Upcast.kt Maven / Gradle / Ivy

The newest version!
package com.cultureamp.eventsourcing

import kotlin.reflect.KClass
import kotlin.reflect.full.functions

interface Upcast {
    fun upcast(event: E, metadata: M): OE
}

@Target(AnnotationTarget.CLASS)
@MustBeDocumented
annotation class UpcastEvent(val upcastType: KClass>)

fun UpcastEvent.upcasting(event: DomainEvent, metadata: EventMetadata): DomainEvent = this.upcastType
    .functions
    .find {
            f ->
        f.name == "upcast" &&
            f.parameters.size == 3 &&
            f.parameters[1].type.classifier is KClass<*> &&
            (f.parameters[1].type.classifier as KClass<*>).isInstance(event)
    }
    ?.call(this.upcastType.objectInstance, event, metadata) as DomainEvent




© 2015 - 2025 Weber Informatics LLC | Privacy Policy