yigit
03/19/2021, 6:51 PMyigit
03/19/2021, 6:52 PM@Repeatable(RepeatableJavaAnnotation.List.class)
public @interface RepeatableJavaAnnotation {
String value();
@interface List {
RepeatableJavaAnnotation[] value();
}
}
@RepeatableJavaAnnotation("x")
@RepeatableJavaAnnotation("y")
class SomeClass
when you read this in JavaAP, you only see the List
version.
In KSP, you see the RepeatableJavaAnnotation
if it is in source and List
version if it is in .class
files.
That being said, kotlin compiler does not support non-source retention repeatable annotations so the .class
case can only ever happen for java source that were compiled to .class
.
https://youtrack.jetbrains.com/issue/KT-12794
My initial plan was to make people use the List
version in XProcessing to query those but that cannot work because the Repeatable
annotation in Kotlin does not have a container parameter (hence even if i can detect it is a repeatable annotation when parsing annotations from ksp, i cannot find its container).
So what I'm considering right now is to provide:
XAnnotated.getAnnotations(baseClass, containerClass = null): List<XAnnotationBox>
and also remove
toAnntoationBox(annotationClass):XAnnotationBox?
it is an ugly API but not sure what else to do.
Looking for any feedback but also wanted to raise this here as more people might be hitting this repeated annotation issue.yigit
03/19/2021, 7:00 PMyigit
03/19/2021, 7:28 PMyigit
03/19/2021, 7:30 PMhasAnnotation
though...yigit
03/19/2021, 11:52 PMyigit
03/19/2021, 11:52 PMgetAnnotations(KCLass)
and just find the container via reflection (and handle inconsistencies between ksp javap internally)yigit
03/19/2021, 11:53 PMAlex Vanyo
03/22/2021, 7:59 PMXAnnotated.getAnnotations
relate to AnnotatedConstruct.getAnnotationsByType
?
I currently have a repeatable annotation (defined in Kotlin) that I am generating code with with kapt
and ksp
(I’ve written the processing code twice for those, with a shared code generation portion).
On the kapt
side, I’m using getAnnotationsByType
to get consistent behavior with ksp