How to detect array of nullable type via annotation processor?


#1

We can check a Nullable parameter by it.getAnnotation(org.jetbrains.annotations.Nullable::class.java) != null at compile time.
But how to check an array’s element should be nullable or not at compile time via annotation processor .


#2

There was a discussion about this already (Kotlin JS - annotations processor). We did not find a solution to check for nullability on generic parameters sadly. The problem is that the annotation processor only gives access to the java type descriptions, which do not contain any information about nullability. This should be solved once we get access to the Kotlin type information. I think JetBrains is planning an creating a better way of doing annotation processing which will give us access to those information, but as far as I remember they are not yet actively working on it (at least they did not tell us about it) and there is definitely no release date.


#3

Actually, unless I misunderstood, you can use the @Metadata annotation to retrieve additional information on the different types used in your classes and functions. The video at https://www.youtube.com/watch?v=dAQaZFyZ_hQ and repo https://github.com/Takhion/kotlin-metadata might help you :slight_smile:


#4

Intersting I did not know about that one. But In my defence, the last time I looked into annotation processing was more than a year ago, so yeah.
And I can’t wait for the compiler plugins :blush: