-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KSName doesn't offer a deterministic naming API #61
Comments
KSName is meant to align with qualified names therefore you are seeing this result, but it is also reasonable to provide correct logic to get the qualifier. We will discuss to see what's the path forward for KSName. |
sounds good. I'm one of the maintainers of KotlinPoet, we'd be interested in seeing what a kotlinpoet-ksp artifact could like on our end. Some obvious ones come to mind, like FileSpec.writeTo(CodeGenerator) support and KSName.toClassName(). Open to other suggestions as well for things you'd want to see in an artifact like that, let us know 👍. Will file an issue on our end soon to track ideas |
Current KSName implementation is based on the qualified name spec. To address this issue I will add a new property/function to KSName. |
A Forcing the notion of package in KSName would require all creation sites to supply package and the remaining identifier(s) separately. Although I agree that specifying package explicitly is much clearer, it is also less convenient. As for the |
To add more context, on Kotlin language perspective names are separated by dot, and the case when you see names separated by slash is platform dependent (in this case, it is the JVM runtime name). In my opinion the right way to solve this is to provide KSDeclaration with a |
Alternative solution for this is shipped with android/kotlin#98 |
KSName isn't ideal for handling non-trivial class names, such as heavily nested types. KotlinPoet's
ClassName.bestGuess()
API is used in the Glide example project, but that API should really only be used as a last resort.In Kotlin's internals and metadata, it has a pattern for its names that is deterministic (e.g.
"org/foo/bar/Baz.Nested"
). It would be ideal if this name was exposed or otherwise surfaced a more concrete API.Here's an implementation we have in KotlinPoet for piecing together a name from it: https://github.com/square/kotlinpoet/blob/06aad8e024aaa453477d420ad65cfe4af9e84f3a/kotlinpoet-metadata-specs/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/internal/ClassInspectorUtil.kt#L171-L209
Example of where KSName currently falls short:
dev.zacsweers.moshisealed.sample.test.MessageTest.MessageWithNullDefault
getQualifier
isdev.zacsweers.moshisealed.sample.test.MessageTest
🤔The text was updated successfully, but these errors were encountered: