com.ancientlightstudios.quarkus.kotlin.openapi.emitter.deserialization.CombineIntoObjectStatementEmitter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
A Maven plugin to use the OpenAPI generator.
package com.ancientlightstudios.quarkus.kotlin.openapi.emitter.deserialization
import com.ancientlightstudios.quarkus.kotlin.openapi.emitter.CodeEmitter
import com.ancientlightstudios.quarkus.kotlin.openapi.emitter.EmitterContext
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.*
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.MethodName.Companion.rawMethodName
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.PropertyExpression.Companion.property
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.TypeName.SimpleTypeName.Companion.typeName
import com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.VariableName.Companion.variableName
class CombineIntoObjectStatementEmitter(
private val context: KotlinExpression,
private val containerClassName: ClassName,
private val plainPrefixParameterNames: List,
private val parameterNames: List
) : CodeEmitter {
var resultStatement: KotlinExpression? = null
// if at least one parameter is specified, generates an expression like this
//
// maybeAllOf(, ) {
// (( as Maybe.Success).value)
// }
//
// there is a cast expression for every input parameter in the ctor invocation
override fun EmitterContext.emit() {
// TODO: eeds rework, this test might not work in all situation
if (plainPrefixParameterNames.isEmpty() && parameterNames.isEmpty()) {
return
}
val parameterExpressions = parameterNames.map {
it.cast(Library.MaybeSuccessClass.typeName()).property("value".variableName())
}
val maybeParameters = listOf(context, *parameterNames.toTypedArray())
resultStatement = InvocationExpression.invoke("maybeAllOf".rawMethodName(), maybeParameters) {
InvocationExpression.invoke(containerClassName.constructorName, plainPrefixParameterNames + parameterExpressions).statement()
}
}
}