@@ -11,24 +11,18 @@ import dev.slne.surf.cloud.api.common.util.mutableObjectListOf
1111import dev.slne.surf.cloud.api.common.util.synchronize
1212import dev.slne.surf.cloud.core.common.coroutines.CloudEventBusScope
1313import dev.slne.surf.surfapi.core.api.util.findAnnotation
14- import io.ktor.client.plugins.cache.storage.FileStorage
1514import it.unimi.dsi.fastutil.objects.ObjectList
1615import kotlinx.coroutines.launch
1716import kotlinx.coroutines.withContext
1817import net.bytebuddy.ByteBuddy
1918import net.bytebuddy.description.modifier.FieldManifestation
2019import net.bytebuddy.description.modifier.Visibility
21- import net.bytebuddy.description.type.TypeDescription
2220import net.bytebuddy.dynamic.loading.ClassLoadingStrategy
2321import net.bytebuddy.implementation.FieldAccessor
2422import net.bytebuddy.implementation.MethodCall
2523import net.bytebuddy.implementation.bytecode.assign.Assigner
26- import net.bytebuddy.implementation.bytecode.assign.TypeCasting
27- import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess
2824import net.bytebuddy.matcher.ElementMatchers
29- import net.bytebuddy.utility.CompoundList
3025import org.springframework.core.ResolvableType
31- import org.springframework.core.convert.TypeDescriptor
3226import org.springframework.expression.spel.standard.SpelExpressionParser
3327import org.springframework.expression.spel.support.StandardEvaluationContext
3428import java.lang.reflect.Method
@@ -125,14 +119,19 @@ class CloudEventBusImpl : CloudEventBus {
125119 .subclass(EventListenerInvoker ::class .java)
126120 .implement(GeneratedInvoker ::class .java)
127121 .defineField(" owner" , instance.javaClass, Visibility .PRIVATE , FieldManifestation .FINAL )
122+ .defineMethod(" getOwner" , Any ::class .java, Visibility .PUBLIC )
123+ .intercept(FieldAccessor .ofField(" owner" ))
128124 .defineConstructor(Visibility .PUBLIC ).withParameters(instance.javaClass)
129- .intercept(MethodCall .invoke(Object ::class .java.getConstructor())
130- .andThen(FieldAccessor .ofField(" owner" ).setsArgumentAt(0 )))
125+ .intercept(
126+ MethodCall .invoke(Object ::class .java.getConstructor())
127+ .andThen(FieldAccessor .ofField(" owner" ).setsArgumentAt(0 ))
128+ )
131129 .method(ElementMatchers .named(" invoke" ))
132- .intercept(MethodCall .invoke(method)
133- .onField(" owner" )
134- .withArgument(0 )
135- .withAssigner(Assigner .DEFAULT , Assigner .Typing .DYNAMIC )
130+ .intercept(
131+ MethodCall .invoke(method)
132+ .onField(" owner" )
133+ .withArgument(0 )
134+ .withAssigner(Assigner .DEFAULT , Assigner .Typing .DYNAMIC )
136135 )
137136 .make()
138137 .load(instance.javaClass.classLoader, ClassLoadingStrategy .Default .INJECTION )
@@ -143,15 +142,21 @@ class CloudEventBusImpl : CloudEventBus {
143142 }
144143
145144 private class ReflectionInvoker (val instance : Any , val method : Method ) : EventListenerInvoker {
146- init { method.isAccessible = true }
145+ init {
146+ method.isAccessible = true
147+ }
148+
147149 override suspend fun invoke (event : CloudEvent ) {
148150 CloudEventBusScope .launch {
149151 val kfn = method.kotlinFunction ? : error(" Not a Kotlin function" )
150152 kfn.callSuspend(instance, event)
151153 }.join()
152154 }
153155 }
154- internal interface GeneratedInvoker { val owner: Any }
156+
157+ internal interface GeneratedInvoker {
158+ val owner: Any
159+ }
155160}
156161
157162val cloudEventBusImpl = CloudEventBus .instance as CloudEventBusImpl
0 commit comments