mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-15 03:20:26 +00:00
try to fix build
This commit is contained in:
@@ -10,6 +10,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(":micro_utils.koin")
|
api project(":micro_utils.koin")
|
||||||
|
api project(":micro_utils.ksp.generator")
|
||||||
api libs.kotlin.poet
|
api libs.kotlin.poet
|
||||||
api libs.ksp
|
api libs.ksp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.squareup.kotlinpoet.asTypeName
|
|||||||
import com.squareup.kotlinpoet.ksp.toClassName
|
import com.squareup.kotlinpoet.ksp.toClassName
|
||||||
import com.squareup.kotlinpoet.ksp.toTypeName
|
import com.squareup.kotlinpoet.ksp.toTypeName
|
||||||
import com.squareup.kotlinpoet.ksp.writeTo
|
import com.squareup.kotlinpoet.ksp.writeTo
|
||||||
|
import dev.inmo.micro_ksp.generator.safeClassName
|
||||||
import dev.inmo.micro_utils.koin.annotations.GenerateGenericKoinDefinition
|
import dev.inmo.micro_utils.koin.annotations.GenerateGenericKoinDefinition
|
||||||
import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition
|
import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
@@ -237,15 +238,7 @@ class Processor(
|
|||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
ksFile.getAnnotationsByType(GenerateKoinDefinition::class).forEach {
|
ksFile.getAnnotationsByType(GenerateKoinDefinition::class).forEach {
|
||||||
val type = runCatching {
|
val type = it.type.safeClassName()
|
||||||
it.type.asTypeName()
|
|
||||||
}.getOrElse { e ->
|
|
||||||
if (e is KSTypeNotPresentException) {
|
|
||||||
e.ksType.toClassName()
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val targetType = runCatching {
|
val targetType = runCatching {
|
||||||
type.parameterizedBy(*(it.typeArgs.takeIf { it.isNotEmpty() } ?.map { it.asTypeName() } ?.toTypedArray() ?: return@runCatching type))
|
type.parameterizedBy(*(it.typeArgs.takeIf { it.isNotEmpty() } ?.map { it.asTypeName() } ?.toTypedArray() ?: return@runCatching type))
|
||||||
}.getOrElse { e ->
|
}.getOrElse { e ->
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package dev.inmo.micro_utils.koin.generator.test
|
|||||||
|
|
||||||
import kotlin.Any
|
import kotlin.Any
|
||||||
import kotlin.Boolean
|
import kotlin.Boolean
|
||||||
import kotlin.Deprecated
|
|
||||||
import kotlin.String
|
import kotlin.String
|
||||||
import org.koin.core.Koin
|
import org.koin.core.Koin
|
||||||
import org.koin.core.definition.Definition
|
import org.koin.core.definition.Definition
|
||||||
@@ -30,95 +29,59 @@ public val Koin.sampleInfo: Test<String>
|
|||||||
/**
|
/**
|
||||||
* @return Definition by key "sampleInfo" with [parameters]
|
* @return Definition by key "sampleInfo" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun Scope.sampleInfo(noinline parameters: ParametersDefinition): Test<String> =
|
public inline fun Scope.sampleInfo(noinline parameters: ParametersDefinition): Test<String> = get(named("sampleInfo"), parameters)
|
||||||
get(named("sampleInfo"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Definition by key "sampleInfo" with [parameters]
|
* @return Definition by key "sampleInfo" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun Koin.sampleInfo(noinline parameters: ParametersDefinition): Test<String> =
|
public inline fun Koin.sampleInfo(noinline parameters: ParametersDefinition): Test<String> = get(named("sampleInfo"), parameters)
|
||||||
get(named("sampleInfo"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.single] and key "sampleInfo"
|
* Will register [definition] with [org.koin.core.module.Module.single] and key "sampleInfo"
|
||||||
*/
|
*/
|
||||||
@Deprecated(
|
public fun Module.singleSampleInfo(createdAtStart: Boolean = false, definition: Definition<Test<String>>): KoinDefinition<Test<String>> = single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition)
|
||||||
"This definition is old style and should not be used anymore. Use singleSampleInfo instead",
|
|
||||||
ReplaceWith("singleSampleInfo"),
|
|
||||||
)
|
|
||||||
public fun Module.sampleInfoSingle(createdAtStart: Boolean = false,
|
|
||||||
definition: Definition<Test<String>>): KoinDefinition<Test<String>> =
|
|
||||||
single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Will register [definition] with [org.koin.core.module.Module.single] and key "sampleInfo"
|
|
||||||
*/
|
|
||||||
public fun Module.singleSampleInfo(createdAtStart: Boolean = false,
|
|
||||||
definition: Definition<Test<String>>): KoinDefinition<Test<String>> =
|
|
||||||
single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.factory] and key "sampleInfo"
|
* Will register [definition] with [org.koin.core.module.Module.factory] and key "sampleInfo"
|
||||||
*/
|
*/
|
||||||
@Deprecated(
|
public fun Module.factorySampleInfo(definition: Definition<Test<String>>): KoinDefinition<Test<String>> = factory(named("sampleInfo"), definition = definition)
|
||||||
"This definition is old style and should not be used anymore. Use factorySampleInfo instead",
|
|
||||||
ReplaceWith("factorySampleInfo"),
|
|
||||||
)
|
|
||||||
public fun Module.sampleInfoFactory(definition: Definition<Test<String>>):
|
|
||||||
KoinDefinition<Test<String>> = factory(named("sampleInfo"), definition = definition)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Will register [definition] with [org.koin.core.module.Module.factory] and key "sampleInfo"
|
|
||||||
*/
|
|
||||||
public fun Module.factorySampleInfo(definition: Definition<Test<String>>):
|
|
||||||
KoinDefinition<Test<String>> = factory(named("sampleInfo"), definition = definition)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Definition by key "test" with [parameters]
|
* @return Definition by key "test" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Scope.test(noinline parameters: ParametersDefinition? = null): T
|
public inline fun <reified T : Any> Scope.test(noinline parameters: ParametersDefinition? = null): T = get(named("test"), parameters)
|
||||||
= get(named("test"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Definition by key "test" with [parameters]
|
* @return Definition by key "test" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Koin.test(noinline parameters: ParametersDefinition? = null): T
|
public inline fun <reified T : Any> Koin.test(noinline parameters: ParametersDefinition? = null): T = get(named("test"), parameters)
|
||||||
= get(named("test"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.single] and key "test"
|
* Will register [definition] with [org.koin.core.module.Module.single] and key "test"
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Module.singleTest(createdAtStart: Boolean = false, noinline
|
public inline fun <reified T : Any> Module.singleTest(createdAtStart: Boolean = false, noinline definition: Definition<T>): KoinDefinition<T> = single(named("test"), createdAtStart = createdAtStart, definition = definition)
|
||||||
definition: Definition<T>): KoinDefinition<T> = single(named("test"), createdAtStart =
|
|
||||||
createdAtStart, definition = definition)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.factory] and key "test"
|
* Will register [definition] with [org.koin.core.module.Module.factory] and key "test"
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Module.factoryTest(noinline definition: Definition<T>):
|
public inline fun <reified T : Any> Module.factoryTest(noinline definition: Definition<T>): KoinDefinition<T> = factory(named("test"), definition = definition)
|
||||||
KoinDefinition<T> = factory(named("test"), definition = definition)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Definition by key "testNullable" with [parameters]
|
* @return Definition by key "testNullable" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Scope.testNullable(noinline parameters: ParametersDefinition? =
|
public inline fun <reified T : Any> Scope.testNullable(noinline parameters: ParametersDefinition? = null): T? = getOrNull(named("testNullable"), parameters)
|
||||||
null): T? = getOrNull(named("testNullable"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Definition by key "testNullable" with [parameters]
|
* @return Definition by key "testNullable" with [parameters]
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Koin.testNullable(noinline parameters: ParametersDefinition? =
|
public inline fun <reified T : Any> Koin.testNullable(noinline parameters: ParametersDefinition? = null): T? = getOrNull(named("testNullable"), parameters)
|
||||||
null): T? = getOrNull(named("testNullable"), parameters)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.single] and key "testNullable"
|
* Will register [definition] with [org.koin.core.module.Module.single] and key "testNullable"
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Module.singleTestNullable(createdAtStart: Boolean = false,
|
public inline fun <reified T : Any> Module.singleTestNullable(createdAtStart: Boolean = false, noinline definition: Definition<T>): KoinDefinition<T> = single(named("testNullable"), createdAtStart = createdAtStart, definition = definition)
|
||||||
noinline definition: Definition<T>): KoinDefinition<T> = single(named("testNullable"),
|
|
||||||
createdAtStart = createdAtStart, definition = definition)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will register [definition] with [org.koin.core.module.Module.factory] and key "testNullable"
|
* Will register [definition] with [org.koin.core.module.Module.factory] and key "testNullable"
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Any> Module.factoryTestNullable(noinline definition: Definition<T>):
|
public inline fun <reified T : Any> Module.factoryTestNullable(noinline definition: Definition<T>): KoinDefinition<T> = factory(named("testNullable"), definition = definition)
|
||||||
KoinDefinition<T> = factory(named("testNullable"), definition = definition)
|
|
||||||
|
|||||||
22
ksp/generator/src/main/kotlin/KClassTypeName.kt
Normal file
22
ksp/generator/src/main/kotlin/KClassTypeName.kt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.inmo.micro_ksp.generator
|
||||||
|
|
||||||
|
import com.google.devtools.ksp.KSTypeNotPresentException
|
||||||
|
import com.google.devtools.ksp.KspExperimental
|
||||||
|
import com.squareup.kotlinpoet.ClassName
|
||||||
|
import com.squareup.kotlinpoet.asTypeName
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
@OptIn(KspExperimental::class)
|
||||||
|
fun KClass<*>.safeClassName() = runCatching {
|
||||||
|
asTypeName()
|
||||||
|
}.getOrElse { e ->
|
||||||
|
if (e is KSTypeNotPresentException) {
|
||||||
|
ClassName(
|
||||||
|
e.ksType.declaration.packageName.asString(),
|
||||||
|
e.ksType.declaration.qualifiedName ?.asString() ?.replaceFirst(e.ksType.declaration.packageName.asString(), "")
|
||||||
|
?: e.ksType.declaration.simpleName.asString()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user