Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DeoTimeTheGithubUser/KotlinPoetDSL
Browse files Browse the repository at this point in the history
  • Loading branch information
deotimedev committed Dec 20, 2022
2 parents 1b106de + 61d9130 commit f32558f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/kotlin/me/deotime/kpoetdsl/Attributes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface Attributes {

interface Properties : Has {
fun property(assembler: Assembler<PropertyBuilder>)
fun property(name: String, assembler: Assembler<PropertyBuilder>)
}

interface Code : Has {
Expand Down Expand Up @@ -133,9 +134,12 @@ interface Attributes {
): Has.Properties =
object : Has.Properties, Sourced<S> by sourcedByCozy(cozy) {
override fun property(assembler: Assembler<PropertyBuilder>) {

holder(source).add(PropertyBuilder.cozy().buildWith(assembler))
}

override fun property(name: String, assembler: Assembler<PropertyBuilder>) {
holder(source).add(PropertyBuilder.cozy().apply { name(name) }.buildWith(assembler))
}
}

@JvmName("propertyVisitor_typed")
Expand All @@ -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))
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/me/deotime/kpoetdsl/TypeBuilder.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,8 +45,22 @@ class TypeBuilder private constructor(private val cozy: Cozy<TypeBuilder>) :
types.forEach(source::superclass)
}

fun inherit(vararg types: TypeName) {
types.forEach(source::superclass)
}

inline fun <reified T> inherit() = inherit(T::class)

fun implement(vararg interfaces: TypeName) {
interfaces.forEach(source::addSuperinterface)
}

fun implement(vararg interfaces: KClass<*>) {
interfaces.forEach(source::addSuperinterface)
}

inline fun <reified T> implement() = implement(T::class.asTypeName())

@JvmInline
value class Type private constructor(val init: (String) -> TypeSpec.Builder) {
object Selector {
Expand Down

0 comments on commit f32558f

Please sign in to comment.