Skip to content

Commit

Permalink
Use ksp only for unique key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
IVIanuu committed Feb 23, 2024
1 parent bf54223 commit d453e46
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.ivianuu.injekt.compiler.*
import org.jetbrains.kotlin.utils.addToStdlib.*
import java.util.*

@OptIn(UnsafeCastFunction::class)
class InjektSymbolProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
resolver.getSymbolsWithAnnotation(InjektFqNames.Provide.asString())
Expand Down Expand Up @@ -85,12 +84,11 @@ class InjektSymbolProcessor(private val environment: SymbolProcessorEnvironment)

private fun KSDeclaration.uniqueKey(): String = buildString {
modifiers.forEach { append(it) }
annotations.forEach { append(it.annotationType.uniqueTypeKey()) }

when (this@uniqueKey) {
is KSClassDeclaration -> {
superTypes.forEach { append(it.uniqueTypeKey()) }
annotations
.forEach { append(it.annotationType.uniqueTypeKey()) }
primaryConstructor?.uniqueKey()?.let { append(it) }
}
is KSFunctionDeclaration -> {
Expand All @@ -108,8 +106,19 @@ class InjektSymbolProcessor(private val environment: SymbolProcessorEnvironment)
}
}

private fun KSTypeReference.uniqueTypeKey() = resolve().safeAs<KSTypeImpl>()
?.kotlinType?.uniqueTypeKey() ?: "error"
private fun KSTypeReference.uniqueTypeKey(): String = buildString {
fun KSType.append() {
annotations.forEach { it.annotationType.resolve().append() }
append(declaration.qualifiedName!!.asString())
arguments.forEach {
append(it.type?.uniqueTypeKey())
append(it.variance)
}
append(isMarkedNullable)
}

resolve().append()
}

@AutoService(SymbolProcessorProvider::class)
class Provider : SymbolProcessorProvider {
Expand Down

0 comments on commit d453e46

Please sign in to comment.