Skip to content

Commit

Permalink
Merge pull request #73 from SchwarzIT/feature/guf-add-super-interface…
Browse files Browse the repository at this point in the history
…s-to-interface

Feature/add super interfaces to interface
  • Loading branch information
flgubler-ergon authored May 2, 2023
2 parents 161a200 + 77024e8 commit fbeaf1d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class CommonInterfaceGeneration {

holder.deprecated?.addDeprecated(interfaceSpec)

holder.basedOn.forEach { interfaceSpec.addSuperinterface(it.interfaceTypeName) }
holder.collectAllSuperInterfaceNames().forEach { interfaceSpec.addSuperinterface(it) }

val companionSpec = TypeSpec.companionObjectBuilder()

for (fieldHolder in holder.allFields) {
val isBaseField = holder.basedOn.any {
it.fields.containsKey(fieldHolder.dbField) || it.fieldConstants.containsKey(fieldHolder.dbField)
val isBaseField = holder.collectAllSuperInterfaceFields().any {
it.hasFieldWithName(fieldHolder.dbField) || it.hasFieldConstantWithName(fieldHolder.dbField)
}
val propertySpec = fieldHolder.interfaceProperty(isBaseField, holder.deprecated)
interfaceSpec.addProperty(propertySpec)
Expand Down Expand Up @@ -55,7 +55,7 @@ class CommonInterfaceGeneration {
).mutable().initializer("%T()", TypeUtil.linkedHashMapStringAnyNullable()).build()
)
.addFunction(constructorMap())
.superclass(holder.sourceElement!!.typeName)
.superclass(holder.sourceElement.typeName)

holder.deprecated?.addDeprecated(typeBuilder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class EntityGeneration {
.addModifiers(KModifier.PUBLIC)
.addSuperinterface(TypeUtil.iEntity())
.addSuperinterface(holder.interfaceTypeName)
.addSuperinterfaces(holder.collectAllChildInterfaces())
.addProperty(holder.dbNameProperty())
.addFunction(EnsureTypesGeneration.ensureTypes(holder, false))
.addFunction(CblDefaultGeneration.addDefaults(holder, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class WrapperGeneration {
.addSuperinterface(TypeUtil.mapSupport())
.addModifiers(KModifier.PUBLIC)
.addSuperinterface(holder.interfaceTypeName)
.addSuperinterfaces(holder.collectAllChildInterfaces())
.addFunction(EnsureTypesGeneration.ensureTypes(holder, true))
.addFunction(CblDefaultGeneration.addDefaults(holder, true))
.addFunction(CblConstantGeneration.addConstants(holder, true))
Expand All @@ -28,7 +27,7 @@ class WrapperGeneration {
.addProperty(PropertySpec.builder("mDoc", TypeUtil.mutableMapStringAnyNullable()).addModifiers(KModifier.PRIVATE).mutable().initializer("%T()", TypeUtil.linkedHashMapStringAnyNullable()).build())
.addFunction(constructorMap())
.addFunction(constructorDefault())
.superclass(holder.sourceElement!!.typeName)
.superclass(holder.sourceElement.typeName)
.addFunction(BuilderClassGeneration.generateBuilderFun())

holder.deprecated?.addDeprecated(typeBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.schwarz.crystalprocessor.model.source.ISourceModel
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.TypeName

abstract class BaseEntityHolder(val sourceElement: ISourceModel) : IClassModel by sourceElement {
abstract class BaseEntityHolder(val sourceElement: ISourceModel) : IClassModel by sourceElement, ModelHolderWithFields {

val fields: MutableMap<String, CblFieldHolder> = mutableMapOf()

Expand Down Expand Up @@ -56,9 +56,18 @@ abstract class BaseEntityHolder(val sourceElement: ISourceModel) : IClassModel b
val interfaceTypeName: TypeName
get() = ClassName(sourcePackage, interfaceSimpleName)

fun collectAllChildInterfaces(): List<TypeName> {
override fun hasFieldWithName(name: String): Boolean = fields.containsKey(name)
override fun hasFieldConstantWithName(name: String): Boolean = fieldConstants.containsKey(name)

fun collectAllSuperInterfaceNames(): List<TypeName> {
val basedOnInterfaceTypeNames = basedOn.map { it.interfaceTypeName }
val reducesModelsInterfaceTypeNames = reducesModels.map { ClassName(sourcePackage, "I${it.namePrefix}$sourceClazzSimpleName") }
return listOf(*basedOnInterfaceTypeNames.toTypedArray(), *reducesModelsInterfaceTypeNames.toTypedArray())
}

fun collectAllSuperInterfaceFields(): List<ModelHolderWithFields> {
val basedOnInterfaceTypes = basedOn
val reducesModelsInterfaceTypes = reducesModels
return listOf(*basedOnInterfaceTypes.toTypedArray(), *reducesModelsInterfaceTypes.toTypedArray())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.schwarz.crystalprocessor.model.entity

interface ModelHolderWithFields {
fun hasFieldWithName(name: String): Boolean
fun hasFieldConstantWithName(name: String): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ data class ReducedModelHolder(
val includeDocId: Boolean,
val includeBasedOn: Boolean,
private val parentModel: BaseEntityHolder
)
) : ModelHolderWithFields {
override fun hasFieldWithName(name: String): Boolean = includedElements.contains(name)
override fun hasFieldConstantWithName(name: String): Boolean = includedElements.contains(name)
}

0 comments on commit fbeaf1d

Please sign in to comment.