-
Notifications
You must be signed in to change notification settings - Fork 81
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
TypeReference.asTypeName()
does not copy type annotations
#647
Comments
Can you please share a concrete example? |
We have this top level function: @ContributesJsonAdapter
internal fun Moshi.Builder.componentModelAdapter(
types: @JvmSuppressWildcards Set<ComponentTypeMapping<*>>
) {
add(ComponentModelAdapterFactory(types))
} The issue here is that when you call |
TypeReference.requireTypeName()
does not copy type annotationsTypeReference.asTypeName()
does not copy type annotations
A fix/workaround is to manually copy the type annotations (for Psi, havent tried with Descriptor APIs) internal fun KtAnnotated.annotationSpecs(module: ModuleDescriptor) =
annotationEntries.map { it.toAnnotationReference(null, module).toAnnotationSpec() }
...
typeName = (it.type() as TypeReference.Psi).run {
asTypeName()
.copy(annotations = type.annotationSpecs(module)) // manually copy type annotations
}, |
I'd be happy to merge a PR. You could use https://github.com/square/anvil/blob/main/compiler/src/test/java/com/squareup/anvil/compiler/internal/reference/TypeReferenceTest.kt to write a test for this. |
It seems type annotations are not copied into the
TypeName
constructed from aTypeReference
The text was updated successfully, but these errors were encountered: