mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2024-12-29 12:00:15 +00:00
decrease number of expected functions
This commit is contained in:
parent
1b87562035
commit
ea29a801fd
@ -36,7 +36,7 @@ kotlin {
|
|||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('stdlib')
|
implementation kotlin('stdlib')
|
||||||
api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
api kotlin('reflect')
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package com.insanusmokrassar.sdi
|
package com.insanusmokrassar.sdi
|
||||||
|
|
||||||
import com.insanusmokrassar.sdi.utils.*
|
import com.insanusmokrassar.sdi.utils.createModuleBasedOnConfigRoot
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.*
|
import kotlinx.serialization.internal.HashMapSerializer
|
||||||
|
import kotlinx.serialization.internal.StringSerializer
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.*
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@ImplicitReflectionSerializer
|
||||||
@Serializable(ModuleSerializer::class)
|
@Serializable(ModuleSerializer::class)
|
||||||
|
@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi.utils
|
|||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.*
|
import kotlinx.serialization.modules.SerializerAlreadyRegisteredException
|
||||||
|
import kotlinx.serialization.modules.SerializersModuleBuilder
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@ImplicitReflectionSerializer
|
||||||
@ -13,7 +14,7 @@ internal class DependencyResolver<T : Any>(
|
|||||||
private val dependencyGetter: (String) -> Any
|
private val dependencyGetter: (String) -> Any
|
||||||
) : KSerializer<T> {
|
) : KSerializer<T> {
|
||||||
private val originalSerializer: KSerializer<T> = try {
|
private val originalSerializer: KSerializer<T> = try {
|
||||||
resolveSerializerByKClass(kClass)
|
kClass.serializer()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
PolymorphicSerializer(kClass)
|
PolymorphicSerializer(kClass)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package com.insanusmokrassar.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.*
|
import kotlinx.serialization.modules.SerializerAlreadyRegisteredException
|
||||||
|
import kotlinx.serialization.modules.SerializersModule
|
||||||
|
|
||||||
private typealias PackageOrOtherDependencyNamePair = Pair<String?, String?>
|
private typealias PackageOrOtherDependencyNamePair = Pair<String?, String?>
|
||||||
|
|
||||||
@ -63,9 +64,7 @@ internal fun createModuleBasedOnConfigRoot(jsonObject: JsonObject): Json {
|
|||||||
key to packageName
|
key to packageName
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
return Json(
|
val context = SerializersModule {
|
||||||
configuration = JsonConfiguration(useArrayPolymorphism = true),
|
|
||||||
context = SerializersModule {
|
|
||||||
keysToPackages.values.forEach {
|
keysToPackages.values.forEach {
|
||||||
val kclass = resolveKClassByPackageName(it)
|
val kclass = resolveKClassByPackageName(it)
|
||||||
|
|
||||||
@ -82,6 +81,9 @@ internal fun createModuleBasedOnConfigRoot(jsonObject: JsonObject): Json {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Json(
|
||||||
|
configuration = JsonConfiguration(useArrayPolymorphism = true),
|
||||||
|
context = context
|
||||||
).also {
|
).also {
|
||||||
jsonStringFormat = it
|
jsonStringFormat = it
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package com.insanusmokrassar.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.KSerializer
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KType
|
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
expect fun resolveSerializerByPackageName(packageName: String): KSerializer<*>
|
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
expect fun <T : Any> resolveSerializerByKClass(kClass: KClass<T>): KSerializer<T>
|
|
||||||
|
|
||||||
expect fun resolveKClassByPackageName(packageName: String): KClass<*>
|
expect fun resolveKClassByPackageName(packageName: String): KClass<*>
|
||||||
|
|
||||||
expect val KClass<*>.currentSupertypes: List<KType>
|
@ImplicitReflectionSerializer
|
||||||
|
internal fun <T : Any> resolveSerializerByKClass(kClass: KClass<T>): KSerializer<T> = kClass.serializer()
|
||||||
|
|
||||||
val KClass<*>.allSubclasses: Set<KClass<*>>
|
@ImplicitReflectionSerializer
|
||||||
|
internal fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = resolveSerializerByKClass(
|
||||||
|
resolveKClassByPackageName(packageName)
|
||||||
|
)
|
||||||
|
|
||||||
|
internal val KClass<*>.allSubclasses: Set<KClass<*>>
|
||||||
get() {
|
get() {
|
||||||
val subclasses = mutableSetOf<KClass<*>>()
|
val subclasses = mutableSetOf<KClass<*>>()
|
||||||
val leftToVisit = currentSupertypes.mapNotNull { it.classifier as? KClass<*> }.toMutableList()
|
val leftToVisit = supertypes.mapNotNull { it.classifier as? KClass<*> }.toMutableList()
|
||||||
while (leftToVisit.isNotEmpty()) {
|
while (leftToVisit.isNotEmpty()) {
|
||||||
val top = leftToVisit.removeAt(0)
|
val top = leftToVisit.removeAt(0)
|
||||||
if (subclasses.add(top)) {
|
if (subclasses.add(top)) {
|
||||||
|
@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi
|
|||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.test.*
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
interface List_ParentalAPI {
|
interface List_ParentalAPI {
|
||||||
val services: List<List_ChildAPI>
|
val services: List<List_ChildAPI>
|
||||||
|
@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi
|
|||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.test.*
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
interface SimpleCustomObject_ControllerAPI {
|
interface SimpleCustomObject_ControllerAPI {
|
||||||
fun showUp()
|
fun showUp()
|
||||||
|
@ -2,7 +2,8 @@ package com.insanusmokrassar.sdi
|
|||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.test.*
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
interface Simple_ControllerAPI {
|
interface Simple_ControllerAPI {
|
||||||
fun showUp()
|
fun showUp()
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
|
||||||
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
import kotlin.reflect.KType
|
|
||||||
|
|
||||||
actual val KClass<*>.currentSupertypes: List<KType>
|
|
||||||
get() = this.supertypes
|
|
@ -1,12 +1,5 @@
|
|||||||
package com.insanusmokrassar.sdi.utils
|
package com.insanusmokrassar.sdi.utils
|
||||||
|
|
||||||
import kotlinx.serialization.*
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
actual fun resolveSerializerByPackageName(packageName: String): KSerializer<*> = Class.forName(packageName).kotlin.serializer()
|
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
actual fun <T : Any> resolveSerializerByKClass(kClass: KClass<T>): KSerializer<T> = kClass.serializer()
|
|
||||||
|
|
||||||
actual fun resolveKClassByPackageName(packageName: String): KClass<*> = Class.forName(packageName).kotlin
|
actual fun resolveKClassByPackageName(packageName: String): KClass<*> = Class.forName(packageName).kotlin
|
||||||
|
Loading…
Reference in New Issue
Block a user