Skip to content

Commit

Permalink
add mixins for impl classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Nov 8, 2023
1 parent a3bea24 commit d7cd106
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.vrap.codegen.languages.javalang.client.builder.producers

import com.google.common.collect.Lists
import io.vrap.codegen.languages.extensions.isPatternProperty
import io.vrap.codegen.languages.extensions.toComment
import io.vrap.codegen.languages.java.base.JavaSubTemplates
Expand All @@ -12,10 +13,8 @@ import io.vrap.rmf.codegen.rendering.utils.keepIndentation
import io.vrap.rmf.codegen.types.VrapArrayType
import io.vrap.rmf.codegen.types.VrapObjectType
import io.vrap.rmf.codegen.types.VrapTypeProvider
import io.vrap.rmf.raml.model.types.BooleanInstance
import io.vrap.rmf.raml.model.types.ObjectType
import io.vrap.rmf.raml.model.types.Property
import io.vrap.rmf.raml.model.types.UnionType
import io.vrap.rmf.raml.model.types.*
import io.vrap.rmf.raml.model.types.Annotation


class JavaModelClassFileProducer constructor(override val vrapTypeProvider: VrapTypeProvider, @AllObjectTypes private val allObjectTypes: List<ObjectType>) : JavaObjectTypeExtensions, JavaEObjectTypeExtensions, FileProducer {
Expand All @@ -28,6 +27,17 @@ class JavaModelClassFileProducer constructor(override val vrapTypeProvider: Vrap

val vrapType = vrapTypeProvider.doSwitch(type).toJavaVType() as VrapObjectType

val implements = Lists.newArrayList(vrapType.simpleClassName, "ModelBase")
.plus(
when (val ex = type.getAnnotation("java-impl-implements") ) {
is Annotation -> {
(ex.value as StringInstance).value.escapeAll()
}
else -> null
}
)
.filterNotNull()

val content = """
|package ${vrapType.`package`.toJavaPackage()};
|
Expand All @@ -53,7 +63,7 @@ class JavaModelClassFileProducer constructor(override val vrapTypeProvider: Vrap
| */
|<${JavaSubTemplates.generatedAnnotation}>${if (type.markDeprecated()) """
|@Deprecated""" else ""}
|public class ${vrapType.simpleClassName}Impl implements ${vrapType.simpleClassName}, ModelBase {
|public class ${vrapType.simpleClassName}Impl implements ${implements.joinToString(separator = ", ")} {
|
| <${type.beanFields().escapeAll()}>
|
Expand All @@ -65,6 +75,7 @@ class JavaModelClassFileProducer constructor(override val vrapTypeProvider: Vrap
|
| <${type.equalsMethod().escapeAll()}>
|
| <${type.getAnnotation("java-impl-mixin")?.value?.value?.let { (it as String).escapeAll()} ?: ""}>
|}
""".trimMargin().keepIndentation()
return TemplateFile(
Expand Down

0 comments on commit d7cd106

Please sign in to comment.