Consider the following sources:
@Target(PROPERTY, VALUE_PARAMETER)
annotation class MyAnnotation
class MyClass {
@MyAnnotation lateinit var str: String
}
And the following processor logic:
val myClassName = resolver.getKSNameFromString("MyClass")
val myClass: KSClassDeclaration = resolver.getClassDeclarationByName(myClassName)!!
val prop = myClass.getAllProperties().single()
println("${prop}: ${prop.annotations.map { it.shortName.asString() }.toList()}")
This results in the following outputs:
# KSP1
prop: [MyAnnotation]
# KSP2
prop: []
In particular, the MyAnnotation is missing from the property in KSP2.
Note that if we remove VALUE_PARAMETER from the target the annotation shows up on the property.
Consider the following sources:
And the following processor logic:
This results in the following outputs:
In particular, the
MyAnnotationis missing from the property in KSP2.Note that if we remove
VALUE_PARAMETERfrom the target the annotation shows up on the property.