mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 05:19:23 +00:00
try to fix build
This commit is contained in:
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