3

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?

madhead
  • 31,729
  • 16
  • 153
  • 201

1 Answers1

1

Annotation is a declaration (annotation class).

Annotation Entry is an application of annotation (@).

Miha_x64
  • 5,973
  • 1
  • 41
  • 63