I have a Kotlin annotation:
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Type(
val type: String
)
It can be used on the Kotlin classes:
@Type(type = "type")
data class Annotated(
…
)
I am analyzing this source code with detekt which provides access to the Kotlin PSI. To get the annotation I use the code like:
val annotation = klass
.annotationEntries
.find {
"Type" == it?.shortName?.asString()
}
where, klass
has a type of KtClass
from Kotlin PSI. I've noticed, that KtClass
has two properties: annotations
and annotationEntries
and that annotations
is empty for the annotated class above.
What is the difference between annotations
and annotationEntries
and when should I use what?
Annotation is a declaration (annotation class
).
Annotation Entry is an application of annotation (@
).