Is there anyway to "mock" references to other pack...
# ksp
z
Is there anyway to "mock" references to other packages that should be used by my annotation processor? I'm trying to build one in IntelliJ for use in an Android project later, but the androidx libraries are not included. Should I just import them in the project using the annotation processor like normal to test?
a
Use kotlin poet class names instead Or if you need to test, are you using kotlin compiler testing?
j
If you are generating code, I agree using
ClassName
and friends to model the types is the way to go.
If you are looking up code, there should be a way to look up "mirror"-like versions of the types by names. I've never written a KSP processor, but regular annotation processors and basically every mechanism of similar functionality has this ability, so it's just about finding the right API for it. You basically resolve a reference to the Android type by its name, and then use that reference on the code under compilation.
z
If by using KotlinPoet Class names as the
Copy code
ClassName
type, I am doing that. I'm sorry if I wasn't clear - I meant mocking the types generated by the file for packages that are not included in the target project yet.
And by "mirroring" would that be through the Reflect API or is it something different? Because I think what you are referring to is what I want - I want the type resolutions because I know they will exist in the using project, I don't want to include the Android dependency for testing though.
j
No it would be through some KSP API to look up types