Short version: How can I tell if a KSType is a primitive or even compare it to a kotlin type?
I'm writing a code generator in Kotlin using ksp. I am iterating through a type's functions and have a KSFunctionDeclaration. I want to know if the return type of the function is a primitive.
I can see the name of the type using it.returnType?.resolve()?.declaration?.simpleName and that will show Long or Int etc. So I can just check if that name == "Long" etc. But it seems like there should be a way to compare to an actual type.
I found the builtins property on Resolver that has a property of type KSType for each built in type. But I don't know how to get to the Resolver.
builtInsare the way to compare types and return types when it comes to primitives.Resolvercan be passed as argument to your visitors, it's totally safe.For non-primitive types you can use this extension: