Can someone explain the change > KSP now handle...
# ksp
e
Can someone explain the change
KSP now handles annotation use site targets internally for property accessors (namely
@get:Anno
,
@set:Anno
).
property accessors will have corresponding targeted annotations from their receiver properties
annotations with
@get:
and
@set:
targets will not appear in property's annotation list.
I had this code to find a getter annotation on a constructor val and it's no longer finding it
Copy code
class Foo(@get:Annotation val bar: String)

fun KSAnnotated.hasAnnotation(className: String, useSiteTarget: AnnotationUseSiteTarget? = null): Boolean {
    return annotations.any {
        it.annotationType.resolve().declaration.qualifiedName?.asString() == className &&
            useSiteTarget == it.useSiteTarget
    }
}

override fun hasAnnotation(className: String): Boolean {
    return declaration.getter?.hasAnnotation(className) == true ||
                declaration.hasAnnotation(className, AnnotationUseSiteTarget.GET)
}
e
I think I figured it out,
@get:Annotation
is moved to the getter but it still has a useSiteTarget of
GET
.
so the new behavior broke my code but it does make sense
👍 1