Skip to content

Commit

Permalink
Merge pull request #42 from SchwarzIT/feature/add-entity-super-interface
Browse files Browse the repository at this point in the history
Feature/add entity super interface
  • Loading branch information
flgubler-ergon authored Apr 13, 2021
2 parents 21c9ad8 + 71c2e6e commit 7a50b82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kaufland.com.coachbasebinderapi

interface IEntity : MapSupport {
fun getId(): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import java.util.*
class EntityGeneration {

private val id: FunSpec
get() = FunSpec.builder("getId").addModifiers(KModifier.PUBLIC).returns(TypeUtil.string().copy(nullable = true)).addStatement("return mDoc.get(%N) as %T", "_ID", TypeUtil.string().copy(nullable = true)).build()
get() = FunSpec.builder("getId")
.addModifiers(KModifier.PUBLIC, KModifier.OVERRIDE)
.returns(TypeUtil.string().copy(nullable = true))
.addStatement("return mDoc.get(%N) as %T", "_ID", TypeUtil.string().copy(nullable = true))
.build()


fun generateModel(holder: EntityHolder, useSuspend : Boolean): FileSpec {
Expand Down Expand Up @@ -42,7 +46,7 @@ class EntityGeneration {

val typeBuilder = TypeSpec.classBuilder(holder.entitySimpleName)
.addModifiers(KModifier.PUBLIC)
.addSuperinterface(TypeUtil.mapSupport())
.addSuperinterface(TypeUtil.iEntity())
.addSuperinterface(holder.interfaceTypeName)
.addFunction(EnsureTypesGeneration.ensureTypes(holder, false))
.addFunction(CblDefaultGeneration.addDefaults(holder, false))
Expand Down
8 changes: 7 additions & 1 deletion couchbase-entity/src/main/java/com/kaufland/util/TypeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.squareup.kotlinpoet.*

import javax.lang.model.type.TypeMirror
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import kaufland.com.coachbasebinderapi.IEntity
import kaufland.com.coachbasebinderapi.MapSupport
import kaufland.com.coachbasebinderapi.mapify.IMapper
import kaufland.com.coachbasebinderapi.mapify.IMapifyable
import kaufland.com.coachbasebinderapi.mapify.Mapifyable
Expand Down Expand Up @@ -89,7 +91,7 @@ object TypeUtil {
}

fun mapSupport(): TypeName {
return ClassName("kaufland.com.coachbasebinderapi", "MapSupport")
return MapSupport::class.asTypeName()
}

fun iMapper(typename: TypeName): TypeName {
Expand All @@ -108,6 +110,10 @@ object TypeUtil {
return SerializableMapifyable::class.asTypeName().parameterizedBy(typename)
}

fun iEntity(): TypeName {
return IEntity::class.asTypeName()
}

fun clazz(typename: TypeName) : TypeName{
return ClassName("java.lang", "Class").parameterizedBy(typename)
}
Expand Down

0 comments on commit 7a50b82

Please sign in to comment.