Skip to content

Commit

Permalink
Type extraction should work with Inherited Handlers for Parameterized…
Browse files Browse the repository at this point in the history
… Commands (#29)

* Type extraction should work with Inherited Handlers for Parameterized Type

* Bump the version
  • Loading branch information
osoykan authored Sep 27, 2022
1 parent b81e31c commit d6490ad
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion kediatr-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trendyol</groupId>
<artifactId>kediatr-core</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<parent>
Expand Down
14 changes: 8 additions & 6 deletions kediatr-core/src/main/kotlin/com/trendyol/kediatr/Registrar.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.trendyol.kediatr

import java.lang.reflect.ParameterizedType
import java.lang.reflect.TypeVariable

@Suppress("UNCHECKED_CAST")
abstract class Registrar {
Expand All @@ -23,15 +24,15 @@ abstract class Registrar {

handler.genericInterfaces
.filterIsInstance<ParameterizedType>()
.map { extractParameter<TParameter>(it) }
.map { extractParameter(it) }
.forEach { registrar(it, handler) }

when (handler.genericSuperclass) {
is ParameterizedType -> {
val inheritedHandler = (handler.genericSuperclass as ParameterizedType).rawType as Class<*>
inheritedHandler.genericInterfaces
.filterIsInstance<ParameterizedType>()
.map { extractParameter<TParameter>(handler.genericSuperclass as ParameterizedType) }
.map { extractParameter(handler.genericSuperclass as ParameterizedType) }
.forEach { registrar(it, handler) }
}

Expand All @@ -40,7 +41,7 @@ abstract class Registrar {
if (interfaceOrBaseClass.isAssignableFrom(inheritedHandler)) {
inheritedHandler.genericInterfaces
.filterIsInstance<ParameterizedType>()
.map { extractParameter<TParameter>(it) }
.map { extractParameter(it) }
.forEach { registrar(it, handler) }
}
}
Expand All @@ -63,9 +64,10 @@ abstract class Registrar {
registrar(handler)
}

protected fun <T> extractParameter(genericInterface: ParameterizedType): Class<out T> =
protected fun extractParameter(genericInterface: ParameterizedType): Class<*> =
when (val typeArgument = genericInterface.actualTypeArguments[0]) {
is ParameterizedType -> typeArgument.rawType as Class<out T>
else -> typeArgument as Class<out T>
is ParameterizedType -> typeArgument.rawType as Class<*>
is TypeVariable<*> -> extractParameter((genericInterface.rawType as Class<*>).genericInterfaces[0] as ParameterizedType)
else -> typeArgument as Class<*>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.trendyol.kediatr.CommandBusBuilder
import com.trendyol.kediatr.CommandHandler
import com.trendyol.kediatr.HandlerNotFoundException
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.trendyol
import com.trendyol.kediatr.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down
4 changes: 2 additions & 2 deletions kediatr-koin-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.trendyol</groupId>
<artifactId>kediatr-koin-starter</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -195,7 +195,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-core</artifactId>
<version>1.0.18</version>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>io.insert-koin</groupId>
Expand Down
4 changes: 2 additions & 2 deletions kediatr-quarkus-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.trendyol</groupId>
<artifactId>kediatr-quarkus-starter</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<parent>
Expand Down Expand Up @@ -219,7 +219,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-core</artifactId>
<version>1.0.18</version>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
Expand Down
4 changes: 2 additions & 2 deletions kediatr-spring-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trendyol</groupId>
<artifactId>kediatr-spring-starter</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<parent>
Expand Down Expand Up @@ -274,7 +274,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-core</artifactId>
<version>1.0.18</version>
<version>1.1.2</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trendyol</groupId>
<artifactId>kediatR</artifactId>
<version>1.0.5</version>
<version>1.1.2</version>
<modules>
<module>kediatr-core</module>
<module>kediatr-spring-starter</module>
Expand Down

0 comments on commit d6490ad

Please sign in to comment.