diff --git a/src/main/kotlin/me/deotime/kpoetdsl/Attributes.kt b/src/main/kotlin/me/deotime/kpoetdsl/Attributes.kt index 03080b6..04f0a37 100644 --- a/src/main/kotlin/me/deotime/kpoetdsl/Attributes.kt +++ b/src/main/kotlin/me/deotime/kpoetdsl/Attributes.kt @@ -70,6 +70,7 @@ interface Attributes { interface Properties : Has { fun property(assembler: Assembler) + fun property(name: String, assembler: Assembler) } interface Code : Has { @@ -133,9 +134,12 @@ interface Attributes { ): Has.Properties = object : Has.Properties, Sourced by sourcedByCozy(cozy) { override fun property(assembler: Assembler) { - holder(source).add(PropertyBuilder.cozy().buildWith(assembler)) } + + override fun property(name: String, assembler: Assembler) { + holder(source).add(PropertyBuilder.cozy().apply { name(name) }.buildWith(assembler)) + } } @JvmName("propertyVisitor_typed") @@ -156,7 +160,7 @@ interface Attributes { } override fun code(format: String, vararg args: Any?) { - visitor(source, CodeBlock.of(format, args)) + visitor(source, CodeBlock.of(format, *args)) } } diff --git a/src/main/kotlin/me/deotime/kpoetdsl/TypeBuilder.kt b/src/main/kotlin/me/deotime/kpoetdsl/TypeBuilder.kt index 9bc7722..1fa9f65 100644 --- a/src/main/kotlin/me/deotime/kpoetdsl/TypeBuilder.kt +++ b/src/main/kotlin/me/deotime/kpoetdsl/TypeBuilder.kt @@ -1,6 +1,8 @@ package me.deotime.kpoetdsl +import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asTypeName import me.deotime.kpoetdsl.utils.Assembler import me.deotime.kpoetdsl.utils.buildWith import me.deotime.kpoetdsl.utils.required @@ -43,8 +45,22 @@ class TypeBuilder private constructor(private val cozy: Cozy) : types.forEach(source::superclass) } + fun inherit(vararg types: TypeName) { + types.forEach(source::superclass) + } + inline fun inherit() = inherit(T::class) + fun implement(vararg interfaces: TypeName) { + interfaces.forEach(source::addSuperinterface) + } + + fun implement(vararg interfaces: KClass<*>) { + interfaces.forEach(source::addSuperinterface) + } + + inline fun implement() = implement(T::class.asTypeName()) + @JvmInline value class Type private constructor(val init: (String) -> TypeSpec.Builder) { object Selector {