Timo Gruen
12/28/2020, 3:28 PMProperty
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER)
@Retention(AnnotationRetention.RUNTIME)
annotation class Property
When using the annotation on a property e.g.:
data class Example(@Property val key: String)
and introspecting the class with a AnnotationProcessor i can find three different elements which are related to that key
property.
The first one is key
, the second one is getKey
and the third (which is currently probably the reason for my confusion) is the getKey$annotations()
one, which is the only element having the annotation from java annotation processor perspective.
I would have assumed that either key
or getKey
would also be annotated on byte-code level. Any guidance on how i can access the element getKey
OR key
using the annotation processor api?
My actual goal is to retrieve the name key
as well as the type String
of the annotated element@target
is only AnnotationTarget.Field
it just works fine - but then i’m having issues with the Kotlin Reflection not having the annotation at runtime. (Even if the AnnotationRetention
is Runtime
)
Any advice here?Marc Knaup
12/29/2020, 3:55 PMMeta.of(yourElement)
.
Here I use it in my JSON annotation processor:
https://github.com/fluidsonic/fluid-json/blob/accd358687a1247785366625341eeb7ca6be0b99/annotation-processor/sources/jvm-jdk8/collection/CollectionPhase.kt?ts=4#L61Timo Gruen
12/29/2020, 4:13 PMxy$annotations()
to xy
. Enables me to be compliant with java and kotlin and not just kotlin.Marc Knaup
12/29/2020, 4:23 PM$annotations
hack in Java 🤔Timo Gruen
12/29/2020, 4:28 PM$annotations
are only present if it’s processing a kotlin file but still, i can use the entire code for both (as long as i’m sanitizing that $annotations
thingy when approaching kotlin).$annotations?
actually is? Haven’t found any documentationMarc Knaup
12/29/2020, 4:31 PMTimo Gruen
12/29/2020, 4:34 PM