https://kotlinlang.org logo
#ksp
Title
# ksp
f

franztesca

10/08/2023, 6:06 PM
What is the best way to check if a KSType is a given collection type? For example, I tried to use:
Copy code
val KSType.isSet: Boolean
    get() = declaration.qualifiedName?.asString() == Set::class.qualifiedName

val KSType.isMutableSet: Boolean get() = ...
However this doesn't work as
Copy code
println(MutableSet::class.qualifiedName)
prints
kotlin.collections.Set
😕 Is there a better way? thank you color
j

Jiaxiang

10/09/2023, 6:16 PM
instead of doing check on the name of the underlying declaration of a type, how about doing a subtype checking?
e.g: create a type from the
resolver.getClassDeclarationByName(Set::class.qualifiedName).asStarProjectedType().isAssignableFrom(<typeYouWantToCheck)