Skip to content

KSName doesn't offer a deterministic naming API #61

@ZacSweers

Description

@ZacSweers

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:

  • Given this name: dev.zacsweers.moshisealed.sample.test.MessageTest.MessageWithNullDefault
  • The result of getQualifier is dev.zacsweers.moshisealed.sample.test.MessageTest 🤔

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions