Using KotlinPoet, is it possible to add a `@field:SomeAnnotation`?

28 views Asked by At

I am writing a KSP processor and I want to create a class that has a property which is annotated like this:

class MyClass {
  @field:Annotation
  var myProperty: MyType
}

Is that currently possible?

1

There are 1 answers

0
kaneda On

I've found a solution myself:

AnnotationSpec.builder(Annotation::class)
        .useSiteTarget(AnnotationSpec.UseSiteTarget.FIELD)
        .build()