main.de.jensklingenberg.ktorfit.reqBuilderExtension.RequestConverterText.kt Maven / Gradle / Ivy
The newest version!
package de.jensklingenberg.ktorfit.reqBuilderExtension
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.ksp.toClassName
import de.jensklingenberg.ktorfit.model.ParameterData
import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.RequestType
import de.jensklingenberg.ktorfit.model.converterHelper
fun FunSpec.Builder.addRequestConverterText(parameterDataList: List) =
apply {
if (parameterDataList.any { it.hasAnnotation() }) {
parameterDataList.map { parameter ->
val requestTypeClassName =
parameter.annotations
.filterIsInstance()
.firstOrNull()
?.requestType
?.toClassName()
if (parameter.hasAnnotation()) {
this.addStatement(
"val %L: %T = %L.convertParameterType(%L,%L::class,%T::class)",
parameter.name,
requestTypeClassName!!,
converterHelper.objectName,
parameter.name,
parameter.name,
requestTypeClassName,
)
}
parameter.name
}
}
}