3

Having the following class:

data class TestMsg(
    @Parse(";") 
    val someArray: Array<String>
)

And trying to get the annotation with

TestMsg::class.primaryConstructor!!.parameters.forEach{
    println(it.findAnnotation<Parse>())
}

There is no annotation found. I had to move the annotation front of the parameter for make it working

data class TestMsg(
    @Parse(";") val someArray: Array<String>
)

is it a parsing error of jetbrains or is it the normal behavior?


EDIT

You can find the annotation right here:

@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.TYPE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
annotation class Parse(
    val delimiter: String
)
Naor Tedgi
  • 5,204
  • 3
  • 21
  • 48
zack evein
  • 279
  • 5
  • 13

1 Answers1

3

change AnnotationTarget.PROPERTY to AnnotationTarget.VALUE_PARAMETER

@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.TYPE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
annotation class Parse(
    val delimiter: String
)
Naor Tedgi
  • 5,204
  • 3
  • 21
  • 48