I'm working on annotation processor for Kotlin and because the processed elements are in Java I don't receive nullables as ?
instead with a @Nullable
annotation and that's fine, but I'm facing a problem with receiving null parameters in types and in higher order functions, for normal parameters.
var someNullField: String? = ""
I will receive java.lang.String
at process with @org.jetbrains.annotations.Nullable
in its annotations.
But List<String?>
for example will return me java.util.List<java.lang.String>
without any annotations not in the main element not in the type arguments which results in a unknown nullability state
I tried using javax.lang.model.util.Types
to find some sort of result but nothing.
Some of the code that i'm using now:
val utils = processingEnvironment.typeUtils
val type = fieldElement.asType()
if (type is DeclaredType) {
val typeElement = utils.asElement(type)
type.typeArguments
.forEach {
//Trying different ways and just printing for possible results
val capture = utils.capture(it)
val erasure = utils.erasure(it)
val element = utils.asElement(it)
printMessage("element: $element isNullable: ${element.isNullable()} isNotNull: ${element.isNotNull()}\ncapture: $capture isNullable: ${capture.isNullable()} isNotNull: ${capture.isNotNull()}\nerasure: $erasure isNullable: ${erasure.isNullable()} isNotNull: ${erasure.isNotNull()}")
}
}
All help will be appreciated.