Hi, I'm writting my first annotation processor in ...
# getting-started
v
Hi, I'm writting my first annotation processor in Kotlin. I need to check the type of a annotated property in order to know if is optional or not. I have something like @MyAnnotation var property: String? But I don't know if it can be done. I have an instance of Element class from javax.lang.model.element packpage in my annotation processor. I can do element.asType() to get the type of my property, but I don't know how to check if this property is optional or not.
w
Copy code
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
annotation class QueryParseElement(val name: String)

fun IgnoreShitFun(): SomeMap {
return mapOf(*clazz.declaredFields.filter {
            it.isAnnotationPresent(QueryParseElement::class.java)
        }.map {
            val xmlName: QueryParseElement = it.getAnnotation(QueryParseElement::class.java)

          xmlName
        }.toTypedArray())
}
Copy code
class Shit {
    @field:QueryParseElement(name = "DESCRIPTION")
    override var description: String? = null
you mean something like this?
o
@yan ^^
y
You can check if the field (or the getter) has @Nullable or it.