In my library I need to inspect generic type arguments from an annotation.
Until version 2.0.21-1.0.28 this worked fine, but starting with version 2.2.0-* it seems broken.
Example
private fun associateWithFor(item: KSAnnotation): List<ClassName> {
if (item.annotationType.toString() == MapConvert::class.simpleName) {
return item.annotationType.element!!
.typeArguments
.take(2)
.map { it.type!!.resolve().toClassName() }
}
return emptyList()
}
Annotation definition
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class MapConvert<S: Any, D: Any, C : KOMMConverter<S, *, D, *>>(
val converter: KClass<C>,
val name: String = ""
)
Usage
@MapConvert<SourceObject, JvmDestinationObject, JvmDestinationCostConverter>(
converter = JvmDestinationCostConverter::class
)
Problem
-
On 2.0.21-1.0.28: item.annotationType.element!!.typeArguments contains the expected generic arguments (SourceObject, JvmDestinationObject).
-
On 2.2.0-* (and newer): item.annotationType.element!!.typeArguments is always empty.
Expected behavior
Generic type arguments provided to an annotation should be accessible via annotationType.element!!.typeArguments, just like before.
In my library I need to inspect generic type arguments from an annotation.
Until version
2.0.21-1.0.28this worked fine, but starting with version2.2.0-*it seems broken.Example
Annotation definition
Usage
Problem
On
2.0.21-1.0.28:item.annotationType.element!!.typeArgumentscontains the expected generic arguments (SourceObject, JvmDestinationObject).On
2.2.0-*(and newer):item.annotationType.element!!.typeArgumentsis always empty.Expected behavior
Generic type arguments provided to an annotation should be accessible via
annotationType.element!!.typeArguments, just like before.