I'm trying to generate a subclass from an annotated class and getting methods parameters using code below, My problem is that I always get java types, not kotlin types which conflict with parent class causing override error, How do I get correct types kotlin or java types,this exactly happens with String,Int and List
method.parameters.onEach { variableElement ->
if (!variableElement.asType().asTypeName()
.toString()
.contains("Continuation")
) {
val types = ElementFilter.typesIn(variableElement.enclosedElements)
val parameterBuilder = ParameterSpec.builder(
variableElement.simpleName.toString(),
variableElement.asType().asTypeName()
)
function.addParameter(parameterBuilder.build())
}
}
Since Kotlin types are just aliases for the underlying Java types you indeed won't get the correct type information without reading it from the
@Metadata
class annotation. Try theinterop:kotlinx-metadata
artifact that contains helpers for extracting this kind of information from the metadata.