diff --git a/_build/parent/pom.xml b/_build/parent/pom.xml index d2e4ed2..9afe23d 100644 --- a/_build/parent/pom.xml +++ b/_build/parent/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-root - 0.0.7 + 0.0.8 ../../pom.xml diff --git a/_build/report-generator/pom.xml b/_build/report-generator/pom.xml index dfd8b52..debe14e 100644 --- a/_build/report-generator/pom.xml +++ b/_build/report-generator/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-parent - 0.0.7 + 0.0.8 ../parent/pom.xml diff --git a/_itest/builder-itest/pom.xml b/_itest/builder-itest/pom.xml index d980e4c..2660b12 100644 --- a/_itest/builder-itest/pom.xml +++ b/_itest/builder-itest/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-itest-root - 0.0.7 + 0.0.8 io.toolisticon.kotlin.generation.itest diff --git a/_itest/pom.xml b/_itest/pom.xml index 5c205ed..45b62ca 100644 --- a/_itest/pom.xml +++ b/_itest/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-parent - 0.0.7 + 0.0.8 ../_build/parent/pom.xml diff --git a/_itest/spi-itest/pom.xml b/_itest/spi-itest/pom.xml index 23a552c..4d6dc19 100644 --- a/_itest/spi-itest/pom.xml +++ b/_itest/spi-itest/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-itest-root - 0.0.7 + 0.0.8 io.toolisticon.kotlin.generation.itest diff --git a/kotlin-code-generation-bom/pom.xml b/kotlin-code-generation-bom/pom.xml index faf9143..2a9440c 100644 --- a/kotlin-code-generation-bom/pom.xml +++ b/kotlin-code-generation-bom/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-root - 0.0.7 + 0.0.8 io.toolisticon.kotlin.generation diff --git a/kotlin-code-generation-test/pom.xml b/kotlin-code-generation-test/pom.xml index 18f12ab..c60f1d4 100644 --- a/kotlin-code-generation-test/pom.xml +++ b/kotlin-code-generation-test/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-parent - 0.0.7 + 0.0.8 ../_build/parent/pom.xml diff --git a/kotlin-code-generation-test/src/main/kotlin/model/KotlinCompilationCommand.kt b/kotlin-code-generation-test/src/main/kotlin/model/KotlinCompilationCommand.kt index 235d8c8..746e988 100644 --- a/kotlin-code-generation-test/src/main/kotlin/model/KotlinCompilationCommand.kt +++ b/kotlin-code-generation-test/src/main/kotlin/model/KotlinCompilationCommand.kt @@ -3,7 +3,7 @@ package io.toolisticon.kotlin.generation.test.model import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi import com.tschuchort.compiletesting.SourceFile import io.toolisticon.kotlin.generation.spec.KotlinFileSpec -import io.toolisticon.kotlin.generation.spec.KotlinFileSpecs +import io.toolisticon.kotlin.generation.spec.KotlinFileSpecList import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest.sourceFile import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi @@ -13,10 +13,10 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi @ExperimentalKotlinPoetApi @ExperimentalCompilerApi data class KotlinCompilationCommand( - val fileSpecs: KotlinFileSpecs + val fileSpecs: KotlinFileSpecList ) { - constructor(fileSpec: KotlinFileSpec) : this(KotlinFileSpecs(fileSpec)) + constructor(fileSpec: KotlinFileSpec) : this(KotlinFileSpecList(fileSpec)) operator fun plus(fileSpec: KotlinFileSpec) = copy(fileSpecs = fileSpecs + fileSpec) diff --git a/kotlin-code-generation/pom.xml b/kotlin-code-generation/pom.xml index f5b74a6..f0c815c 100644 --- a/kotlin-code-generation/pom.xml +++ b/kotlin-code-generation/pom.xml @@ -5,7 +5,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-parent - 0.0.7 + 0.0.8 ../_build/parent/pom.xml diff --git a/kotlin-code-generation/src/main/kotlin/KotlinCodeGeneration.kt b/kotlin-code-generation/src/main/kotlin/KotlinCodeGeneration.kt index 1e62afd..0d28eb7 100644 --- a/kotlin-code-generation/src/main/kotlin/KotlinCodeGeneration.kt +++ b/kotlin-code-generation/src/main/kotlin/KotlinCodeGeneration.kt @@ -21,20 +21,21 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.builder.propertyBui import io.toolisticon.kotlin.generation.KotlinCodeGeneration.builder.runtimeExceptionClassBuilder import io.toolisticon.kotlin.generation.KotlinCodeGeneration.builder.typeAliasBuilder import io.toolisticon.kotlin.generation.KotlinCodeGeneration.builder.valueClassBuilder -import io.toolisticon.kotlin.generation.KotlinCodeGeneration.className import io.toolisticon.kotlin.generation.builder.* import io.toolisticon.kotlin.generation.builder.extra.* import io.toolisticon.kotlin.generation.builder.extra.DelegateMapValueClassSpecBuilder.Companion.DEFAULT_KEY_TYPE import io.toolisticon.kotlin.generation.poet.FormatSpecifier.asCodeBlock import io.toolisticon.kotlin.generation.spec.* import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext +import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContextFactory import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpiRegistry +import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationStrategy import io.toolisticon.kotlin.generation.spi.registry.KotlinCodeGenerationServiceLoader -import io.toolisticon.kotlin.generation.spi.strategy.KotlinFileSpecStrategy import io.toolisticon.kotlin.generation.spi.strategy.executeAll import io.toolisticon.kotlin.generation.support.SUPPRESS_MEMBER_VISIBILITY_CAN_BE_PRIVATE import mu.KLogging import kotlin.reflect.KClass +import kotlin.reflect.full.isSubclassOf /** * Kotlin Code Generation is a wrapper lib for kotlin poet. This is the central class that allows access to builders and tools via simple static helpers. @@ -559,34 +560,65 @@ object KotlinCodeGeneration : KLogging() { const val NBSP = "ยท" } + /** + * Generator Function that takes a context and an input, finds matching strategies and generates source file(s). + * + * Invokes the contextFactory and calls `generateFiles(context, input)`. + * + * @param INPUT the type of the input (base source of generation) + * @param CONTEXT the context (containing registry, ...) used for generation. + * @param input the instance of the input + * @param contextFactory factory fn to create the context (containing the spi registry) used for generation from input + * @return [KotlinFileSpecList] containing the generated files + * @throws IllegalStateException when no matching strategy is found. + */ + inline fun , reified INPUT : Any> generateFiles( + contextFactory: KotlinCodeGenerationContextFactory, + input: INPUT + ): KotlinFileSpecList = generateFiles(context = contextFactory.invoke(input), input = input) /** - * Generator Function that takes an input and generates source file(s). + * Generator Function that takes a context and an input, finds matching strategies and generates source file(s). * * @param INPUT the type of the input (base source of generation) * @param CONTEXT the context (containing registry, ...) used for generation. - * @param STRATEGY the [KotlinFileSpecStrategy] to apply (using `executeAll()` * @param input the instance of the input - * @param contextFactory fn that creates the context based on input. - * @return list of [KotlinFileSpec] - * @throws IllegalStateException when no strategy is found. - */ - inline fun , - reified STRATEGY : KotlinFileSpecStrategy> generateFiles( - input: INPUT, - contextFactory: (INPUT) -> CONTEXT, - ): List { - val context = contextFactory.invoke(input) - val strategies: List = context.registry.strategies.filter(STRATEGY::class).mapNotNull { + * @param context the context (containing the spi registry) used for generation + * @return [KotlinFileSpecList] containing the generated files + * @throws IllegalStateException when no matching strategy is found. + */ + inline fun , reified INPUT : Any> generateFiles( + context: CONTEXT, + input: INPUT + ): KotlinFileSpecList { + + val strategyCandidates = context.registry.strategies.filter { it.specType.isSubclassOf(KotlinFileSpecIterable::class) } + .filter { it.contextType.isSubclassOf(CONTEXT::class) } + .filter { it.inputType.isSubclassOf(INPUT::class) } + .map { + @Suppress("UNCHECKED_CAST") + it as KotlinCodeGenerationStrategy + } + + // find all matching strategies + val matchingStrategies: List> = strategyCandidates.mapNotNull { if (it.test(context, input)) { it } else { logger.info { "strategy-filter: removing ${it.name}" } null } + }.also { + check(it.isNotEmpty()) { "No applicable strategy found/filtered for context=`${CONTEXT::class.simpleName}`, input=`${input::class.simpleName}`." } + } + + // generate files + val sourceFiles = matchingStrategies.executeAll(context, input).flatten().also { + check(it.isNotEmpty()) { "No files where generated for context=`${CONTEXT::class.simpleName}`, input=`${input::class.simpleName}`." } } - check(strategies.isNotEmpty()) { "No applicable strategy found/filtered for `${STRATEGY::class}`." } - return context.registry.strategies.filter(STRATEGY::class).executeAll(context, input) + + // wrap to spec list + return KotlinFileSpecList(sourceFiles) } + } diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationClassSpec.kt index f14e7df..d6ed8a7 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationClassSpec.kt @@ -4,15 +4,16 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi import com.squareup.kotlinpoet.TypeSpec import io.toolisticon.kotlin.generation.poet.KDoc -import io.toolisticon.kotlin.generation.poet.TypeSpecSupplier import kotlin.reflect.KClass +/** + * Represents an annotation class. + */ @ExperimentalKotlinPoetApi data class KotlinAnnotationClassSpec( override val className: ClassName, private val spec: TypeSpec -) : KotlinGeneratorTypeSpec, TypeSpecSupplier, KotlinAnnotationClassSpecSupplier, - KotlinDocumentableSpec { +) : KotlinGeneratorTypeSpec, KotlinAnnotationClassSpecSupplier, KotlinDocumentableSpec { override fun tag(type: KClass): T? = get().tag(type) override fun spec(): KotlinAnnotationClassSpec = this @@ -20,6 +21,9 @@ data class KotlinAnnotationClassSpec( override val kdoc: KDoc get() = KDoc(spec.kdoc) } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinAnnotationClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationSpec.kt index 3981824..bbbe1c1 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnnotationSpec.kt @@ -7,6 +7,9 @@ import com.squareup.kotlinpoet.TypeName import io.toolisticon.kotlin.generation.builder.KotlinAnnotationSpecBuilder import io.toolisticon.kotlin.generation.poet.AnnotationSpecSupplier +/** + * Represents an annotation, added to annotatable specs. + */ data class KotlinAnnotationSpec( private val spec: AnnotationSpec ) : KotlinGeneratorSpec, KotlinAnnotationSpecSupplier { @@ -26,9 +29,15 @@ data class KotlinAnnotationSpec( } } +/** + * Marks the builder and the spec so they are interchangeable. + */ interface KotlinAnnotationSpecSupplier : KotlinGeneratorSpecSupplier, AnnotationSpecSupplier { override fun get(): AnnotationSpec = spec().get() } +/** + * Create builder from spec. + */ @ExperimentalKotlinPoetApi fun KotlinAnnotationSpec.toBuilder() = KotlinAnnotationSpecBuilder.from(spec = this) diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnonymousClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnonymousClassSpec.kt index 36c4dc3..379f366 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinAnonymousClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinAnonymousClassSpec.kt @@ -6,11 +6,13 @@ import io.toolisticon.kotlin.generation.poet.KDoc import io.toolisticon.kotlin.generation.poet.TypeSpecSupplier import kotlin.reflect.KClass -@JvmInline +/** + * Represents an anonymous class. + */ @ExperimentalKotlinPoetApi -value class KotlinAnonymousClassSpec(private val spec: TypeSpec) : KotlinGeneratorTypeSpec, - KotlinAnonymousClassSpecSupplier, - KotlinDocumentableSpec { +data class KotlinAnonymousClassSpec( + private val spec: TypeSpec +) : KotlinGeneratorTypeSpec, KotlinAnonymousClassSpecSupplier, KotlinDocumentableSpec { override fun tag(type: KClass): T? = get().tag(type) override val kdoc: KDoc get() = KDoc(spec.kdoc) @@ -18,6 +20,9 @@ value class KotlinAnonymousClassSpec(private val spec: TypeSpec) : KotlinGenerat override fun get(): TypeSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinAnonymousClassSpecSupplier : KotlinGeneratorSpecSupplier, TypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinClassSpec.kt index 1917607..e1b159f 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinClassSpec.kt @@ -6,6 +6,9 @@ import com.squareup.kotlinpoet.TypeSpec import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents a class. + */ @ExperimentalKotlinPoetApi data class KotlinClassSpec( override val className: ClassName, @@ -18,11 +21,9 @@ data class KotlinClassSpec( override fun get(): TypeSpec = spec } -//fun KotlinDataClassSpec.toBuilder() = KotlinDataClassSpecBuilder.builder(spec = this) -//fun KotlinDataClassSpec.toFileSpec() = KotlinFileBuilder.builder(this).build() -// TODO fun KotlinDataClassSpec.toBuilder() = KotlinDataClassBuilder.from(spec = this) -// TODO fun KotlinDataClassSpec.toFileSpec() = KotlinFileSpecBuilder.builder(this).build() - +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinCompanionObjectSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinCompanionObjectSpec.kt index 7748bde..44374e9 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinCompanionObjectSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinCompanionObjectSpec.kt @@ -6,6 +6,9 @@ import io.toolisticon.kotlin.generation.poet.KDoc import io.toolisticon.kotlin.generation.poet.TypeSpecSupplier import kotlin.reflect.KClass +/** + * Represents a companion object. + */ @ExperimentalKotlinPoetApi data class KotlinCompanionObjectSpec( private val spec: TypeSpec @@ -17,6 +20,9 @@ data class KotlinCompanionObjectSpec( override fun get(): TypeSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinCompanionObjectSpecSupplier : KotlinGeneratorSpecSupplier, TypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinConstructorPropertySpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinConstructorPropertySpec.kt index ed30e54..6878576 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinConstructorPropertySpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinConstructorPropertySpec.kt @@ -5,6 +5,10 @@ import com.squareup.kotlinpoet.TypeName import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents a constructor property, wraps parameter and property for easier + * creation of constructors with property.. + */ @ExperimentalKotlinPoetApi data class KotlinConstructorPropertySpec( val property: KotlinPropertySpec, @@ -19,6 +23,9 @@ data class KotlinConstructorPropertySpec( override fun spec(): KotlinConstructorPropertySpec = this } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinConstructorPropertySpecSupplier : KotlinGeneratorSpecSupplier { /** @@ -27,5 +34,8 @@ interface KotlinConstructorPropertySpecSupplier : KotlinGeneratorSpecSupplier) : List = constructorProperties.map(KotlinConstructorPropertySpecSupplier::spec).toList() +internal fun toList(constructorProperties: Collection): List = constructorProperties.map(KotlinConstructorPropertySpecSupplier::spec).toList() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinDataClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinDataClassSpec.kt index c6b1739..d9e1dcf 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinDataClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinDataClassSpec.kt @@ -3,17 +3,18 @@ package io.toolisticon.kotlin.generation.spec import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi import com.squareup.kotlinpoet.TypeSpec -import io.toolisticon.kotlin.generation.KotlinCodeGeneration import io.toolisticon.kotlin.generation.KotlinCodeGeneration.typeSpec.isDataClass import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents a data class. + */ @ExperimentalKotlinPoetApi data class KotlinDataClassSpec( override val className: ClassName, private val spec: TypeSpec -) : KotlinGeneratorTypeSpec, KotlinDataClassSpecSupplier, - KotlinDocumentableSpec { +) : KotlinGeneratorTypeSpec, KotlinDataClassSpecSupplier, KotlinDocumentableSpec { init { require(spec.isDataClass) { "Not a dataClass spec: $spec." } @@ -26,15 +27,9 @@ data class KotlinDataClassSpec( override fun get(): TypeSpec = spec } -//fun KotlinDataClassSpec.toBuilder() = KotlinDataClassSpecBuilder.builder(spec = this) -//fun KotlinDataClassSpec.toFileSpec() = KotlinFileBuilder.builder(this).build() -// TODO fun KotlinDataClassSpec.toBuilder() = KotlinDataClassBuilder.from(spec = this) - -@ExperimentalKotlinPoetApi -fun KotlinDataClassSpecSupplier.toFileSpec() = KotlinCodeGeneration.buildFile(this.className) { - addType(this@toFileSpec) -} - +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinDataClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinEnumClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinEnumClassSpec.kt index fcb5d08..31da260 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinEnumClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinEnumClassSpec.kt @@ -6,6 +6,9 @@ import com.squareup.kotlinpoet.TypeSpec import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents an enum class. + */ @ExperimentalKotlinPoetApi data class KotlinEnumClassSpec( override val className: ClassName, @@ -22,6 +25,9 @@ data class KotlinEnumClassSpec( override fun get(): TypeSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinEnumClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinFileSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinFileSpec.kt index f7de3a8..321611a 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinFileSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinFileSpec.kt @@ -6,9 +6,12 @@ import io.toolisticon.kotlin.generation.WithClassName import io.toolisticon.kotlin.generation.poet.FileSpecSupplier import kotlin.reflect.KClass +/** + * Represents a file. + */ data class KotlinFileSpec( private val spec: FileSpec -) : KotlinGeneratorSpec, KotlinFileSpecSupplier, TaggableSpec { +) : KotlinGeneratorSpec, KotlinFileSpecSupplier, TaggableSpec, KotlinFileSpecIterable { val packageName: String = spec.packageName val rootName: String = spec.name @@ -17,10 +20,15 @@ data class KotlinFileSpec( val fqn: String = "$packageName.$rootName" val fileName: String = "$fqn.kt" + override fun iterator(): Iterator = listOf(this).listIterator() + override fun spec(): KotlinFileSpec = this override fun get(): FileSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ interface KotlinFileSpecSupplier : KotlinGeneratorSpecSupplier, FileSpecSupplier, WithClassName { override fun get(): FileSpec = spec().get() } @@ -29,14 +37,48 @@ interface KotlinFileSpecSupplier : KotlinGeneratorSpecSupplier, * List that contains multiple [KotlinFileSpec]s. */ @JvmInline -value class KotlinFileSpecs(private val fileSpecs: List) : List by fileSpecs { +value class KotlinFileSpecList(private val fileSpecs: List) : List by fileSpecs, KotlinFileSpecIterable { companion object { - val EMPTY = KotlinFileSpecs(emptyList()) - fun collect(vararg fns: () -> KotlinFileSpec) = fns.fold(EMPTY) { acc, cur -> acc + cur() } + /** + * Empty Specs. + */ + val EMPTY = KotlinFileSpecList(emptyList()) + + /** + * Create [KotlinFileSpecList] from given vararg iterables. + */ + fun of(vararg iterables: KotlinFileSpecIterable) = of(iterables.toList()) + + + /** + * Create [KotlinFileSpecList] from given iterables. + */ + fun of(iterables: List) = KotlinFileSpecList(iterables.flatten()) + + /** + * Collect file spec suppliers + */ + fun collect(vararg fns: () -> KotlinFileSpec) = collect(fns.toList()) + + /** + * Collect file spec suppliers. + */ + fun collect(specs: List<() -> KotlinFileSpec>) = specs.fold(EMPTY) { acc, cur -> acc + cur() } } - constructor(fileSpec : KotlinFileSpec) : this(listOf(fileSpec)) + /** + * Create new instance from single spec. + */ + constructor(fileSpec: KotlinFileSpec) : this(listOf(fileSpec)) - operator fun plus(fileSpec : KotlinFileSpec): KotlinFileSpecs = KotlinFileSpecs(fileSpecs + fileSpec) + /** + * Create copy of this list and add new spec(s). + */ + operator fun plus(fileSpec: KotlinFileSpecIterable) = KotlinFileSpecList(fileSpecs + fileSpec) } + +/** + * Iterable that provides instances of [KotlinFileSpec]. + */ +sealed interface KotlinFileSpecIterable : Iterable diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinFunSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinFunSpec.kt index 08f5536..95c16da 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinFunSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinFunSpec.kt @@ -6,12 +6,13 @@ import io.toolisticon.kotlin.generation.poet.FunSpecSupplier import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents a function. + */ @ExperimentalKotlinPoetApi data class KotlinFunSpec( private val spec: FunSpec -) : KotlinGeneratorSpec, - KotlinFunSpecSupplier, - KotlinDocumentableSpec { +) : KotlinGeneratorSpec, KotlinFunSpecSupplier, KotlinDocumentableSpec { override val kdoc: KDoc get() = KDoc(spec.kdoc) @@ -20,6 +21,9 @@ data class KotlinFunSpec( override fun get(): FunSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinFunSpecSupplier : KotlinGeneratorSpecSupplier, FunSpecSupplier { override fun get(): FunSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinInterfaceSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinInterfaceSpec.kt index b39aad2..4cb196d 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinInterfaceSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinInterfaceSpec.kt @@ -6,6 +6,9 @@ import com.squareup.kotlinpoet.TypeSpec import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents an interface. + */ @ExperimentalKotlinPoetApi data class KotlinInterfaceSpec( override val className: ClassName, @@ -18,6 +21,9 @@ data class KotlinInterfaceSpec( override fun get(): TypeSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinInterfaceSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinObjectSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinObjectSpec.kt index 30e2cc1..6205eab 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinObjectSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinObjectSpec.kt @@ -6,6 +6,9 @@ import com.squareup.kotlinpoet.TypeSpec import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents an object. + */ @ExperimentalKotlinPoetApi data class KotlinObjectSpec( override val className: ClassName, @@ -18,6 +21,9 @@ data class KotlinObjectSpec( override fun get(): TypeSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinObjectSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinParameterSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinParameterSpec.kt index 1512086..cc23b9d 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinParameterSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinParameterSpec.kt @@ -7,15 +7,13 @@ import io.toolisticon.kotlin.generation.poet.KDoc import io.toolisticon.kotlin.generation.poet.ParameterSpecSupplier import kotlin.reflect.KClass -@JvmInline +/** + * Represents a parameter. + */ @ExperimentalKotlinPoetApi -value class KotlinParameterSpec( +data class KotlinParameterSpec( private val spec: ParameterSpec -) : KotlinGeneratorSpec, - KotlinParameterSpecSupplier, - KotlinDocumentableSpec { +) : KotlinGeneratorSpec, KotlinParameterSpecSupplier, KotlinDocumentableSpec { val name: String get() = spec.name val type: TypeName get() = spec.type @@ -27,6 +25,9 @@ value class KotlinParameterSpec( override fun get(): ParameterSpec = this.spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinParameterSpecSupplier : KotlinGeneratorSpecSupplier, ParameterSpecSupplier { override fun get(): ParameterSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinPropertySpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinPropertySpec.kt index 03e2e55..9533821 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinPropertySpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinPropertySpec.kt @@ -7,11 +7,13 @@ import io.toolisticon.kotlin.generation.poet.KDoc import io.toolisticon.kotlin.generation.poet.PropertySpecSupplier import kotlin.reflect.KClass -@JvmInline +/** + * Represents a property. + */ @ExperimentalKotlinPoetApi -value class KotlinPropertySpec(private val spec: PropertySpec) : KotlinGeneratorSpec, +data class KotlinPropertySpec( + private val spec: PropertySpec +) : KotlinGeneratorSpec, KotlinPropertySpecSupplier, KotlinDocumentableSpec { @@ -26,20 +28,11 @@ value class KotlinPropertySpec(private val spec: PropertySpec) : KotlinGenerator override fun spec(): KotlinPropertySpec = this override fun get(): PropertySpec = spec - //override val annotations: List get() = KotlinAnnotationSpec.of(spec.annotations) - -// override val kdoc: CodeBlock = builder.kdoc.build() -// public val modifiers: Set = builder.modifiers.toImmutableSet() -// public val typeVariables: List = builder.typeVariables.toImmutableList() -// public val initializer: CodeBlock? = builder.initializer -// public val delegated: Boolean = builder.delegated -// public val getter: FunSpec? = builder.getter -// public val setter: FunSpec? = builder.setter -// public val receiverType: TypeName? = builder.receiverType } -// TODO fun KotlinPropertySpec.toBuilder() = KotlinPropertyBuilder.builder(spec = this) - +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinPropertySpecSupplier : KotlinGeneratorSpecSupplier, PropertySpecSupplier { override fun get(): PropertySpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinTypeAliasSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinTypeAliasSpec.kt index c201b51..18e34e7 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinTypeAliasSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinTypeAliasSpec.kt @@ -6,14 +6,13 @@ import io.toolisticon.kotlin.generation.poet.KDoc import io.toolisticon.kotlin.generation.poet.TypeAliasSpecSupplier import kotlin.reflect.KClass - +/** + * Represents a typealias. + */ @ExperimentalKotlinPoetApi -@JvmInline -value class KotlinTypeAliasSpec(private val spec: TypeAliasSpec) : KotlinGeneratorSpec, - KotlinTypeAliasSpecSupplier, - KotlinDocumentableSpec { +data class KotlinTypeAliasSpec( + private val spec: TypeAliasSpec +) : KotlinGeneratorSpec, KotlinTypeAliasSpecSupplier, KotlinDocumentableSpec { override fun tag(type: KClass): T? = get().tag(type) override val kdoc: KDoc get() = KDoc(spec.kdoc) @@ -22,6 +21,9 @@ value class KotlinTypeAliasSpec(private val spec: TypeAliasSpec) : KotlinGenerat override fun get(): TypeAliasSpec = spec } +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinTypeAliasSpecSupplier : KotlinGeneratorSpecSupplier, TypeAliasSpecSupplier { override fun get(): TypeAliasSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spec/KotlinValueClassSpec.kt b/kotlin-code-generation/src/main/kotlin/spec/KotlinValueClassSpec.kt index 85d1cf3..4746e48 100644 --- a/kotlin-code-generation/src/main/kotlin/spec/KotlinValueClassSpec.kt +++ b/kotlin-code-generation/src/main/kotlin/spec/KotlinValueClassSpec.kt @@ -7,6 +7,9 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.typeSpec.isValueCla import io.toolisticon.kotlin.generation.poet.KDoc import kotlin.reflect.KClass +/** + * Represents a value class. + */ @ExperimentalKotlinPoetApi data class KotlinValueClassSpec( override val className: ClassName, @@ -23,7 +26,9 @@ data class KotlinValueClassSpec( override fun get(): TypeSpec = spec } -// fun KotlinValueClassSpec.toBuilder() = KotlinValueClassBuilder.builder(spec = this) +/** + * Marks the builder and the spec so they are interchangeable. + */ @ExperimentalKotlinPoetApi interface KotlinValueClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier { override fun get(): TypeSpec = spec().get() diff --git a/kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationContext.kt b/kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationContext.kt index 54afedd..da4d300 100644 --- a/kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationContext.kt +++ b/kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationContext.kt @@ -39,3 +39,9 @@ interface KotlinCodeGenerationContext> processorType: KClass ): List = registry.processors.filterIsInstance(processorType.java) } + +/** + * Factory to create generation context. + */ +@OptIn(ExperimentalKotlinPoetApi::class) +fun interface KotlinCodeGenerationContextFactory, INPUT : Any> : (INPUT) -> CONTEXT diff --git a/kotlin-code-generation/src/main/kotlin/spi/processor/KotlinCodeGenerationProcessorList.kt b/kotlin-code-generation/src/main/kotlin/spi/processor/KotlinCodeGenerationProcessorList.kt index 2b6d546..0249c41 100644 --- a/kotlin-code-generation/src/main/kotlin/spi/processor/KotlinCodeGenerationProcessorList.kt +++ b/kotlin-code-generation/src/main/kotlin/spi/processor/KotlinCodeGenerationProcessorList.kt @@ -3,7 +3,6 @@ package io.toolisticon.kotlin.generation.spi.processor import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationProcessor -import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationStrategy import io.toolisticon.kotlin.generation.spi.UnboundKotlinCodeGenerationProcessor import kotlin.reflect.KClass @@ -12,15 +11,18 @@ import kotlin.reflect.KClass */ @ExperimentalKotlinPoetApi @JvmInline -value class KotlinCodeGenerationProcessorList(val list: List) : - List by list { +value class KotlinCodeGenerationProcessorList( + @PublishedApi + internal val list: List +) : List by list { constructor(vararg processors: UnboundKotlinCodeGenerationProcessor) : this(processors.toList()) /** * Filter the current list and return instances of given type. - * @param strategyType defining which concrete implementations to use - * @return list containing only instances of given [strategyType] + * + * @param processorType defining which concrete implementations to use + * @return list containing only instances of given [processorType] */ fun , CONTEXT : KotlinCodeGenerationContext, INPUT : Any, BUILDER : Any> filter( processorType: KClass @@ -28,6 +30,13 @@ value class KotlinCodeGenerationProcessorList(val list: List, CONTEXT : KotlinCodeGenerationContext, INPUT : Any, SPEC : Any> filter() = filter(PROCESSOR::class) + + override fun toString(): String = "KotlinCodeGenerationProcessorList(processors=${list.map { it.name }})" } diff --git a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinCodeGenerationStrategyList.kt b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinCodeGenerationStrategyList.kt index 2cb5627..6abaf98 100644 --- a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinCodeGenerationStrategyList.kt +++ b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinCodeGenerationStrategyList.kt @@ -11,13 +11,16 @@ import kotlin.reflect.KClass */ @ExperimentalKotlinPoetApi @JvmInline -value class KotlinCodeGenerationStrategyList(private val list: List) : - List by list { +value class KotlinCodeGenerationStrategyList( + @PublishedApi + internal val list: List +) : List by list { constructor(vararg strategy: UnboundKotlinCodeGenerationStrategy) : this(strategy.toList()) /** * Filter the current list and return instances of given type. + * * @param strategyType defining which concrete implementations to use * @return list containing only instances of given [strategyType] */ @@ -27,6 +30,12 @@ value class KotlinCodeGenerationStrategyList(private val list: List, CONTEXT : KotlinCodeGenerationContext, INPUT : Any, SPEC : Any> filter() = filter(STRATEGY::class) + override fun toString(): String = "KotlinCodeGenerationStrategyList(strategies=${list.map { it.name }})" } @@ -40,6 +49,4 @@ fun , CONTEXT : Ko fun , CONTEXT : KotlinCodeGenerationContext, INPUT : Any, SPEC : Any> List.executeAll( context: CONTEXT, input: INPUT -): List = map { - it.execute(context, input) -}.filterNotNull() +): List = mapNotNull { it.execute(context, input) } diff --git a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecsStrategy.kt b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecListStrategy.kt similarity index 66% rename from kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecsStrategy.kt rename to kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecListStrategy.kt index 96747a2..b9a58db 100644 --- a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecsStrategy.kt +++ b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecListStrategy.kt @@ -1,31 +1,33 @@ package io.toolisticon.kotlin.generation.spi.strategy import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi -import io.toolisticon.kotlin.generation.spec.KotlinFileSpecs +import io.toolisticon.kotlin.generation.spec.KotlinFileSpecList import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi import kotlin.reflect.KClass /** * Used to implement a [io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationStrategy] - * that will generate multiple [io.toolisticon.kotlin.generation.spec.KotlinFileSpec]s wrapped in [KotlinFileSpecs]. + * that will generate multiple [io.toolisticon.kotlin.generation.spec.KotlinFileSpec]s wrapped in [KotlinFileSpecList]. * * Implementations should override the `invoke` function to call multiple [KotlinFileSpecStrategy]s and collect the * results. */ @ExperimentalKotlinPoetApi -abstract class KotlinFileSpecsStrategy, INPUT : Any>( +abstract class KotlinFileSpecListStrategy, INPUT : Any>( contextType: KClass, override val inputType: KClass, order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER, -) : KotlinCodeGenerationStrategyBase( +) : KotlinFileSpecIterableStrategy( contextType = contextType, inputType = inputType, - specType = KotlinFileSpecs::class, + specType = KotlinFileSpecList::class, order = order ) { - abstract override fun invoke(context: CONTEXT, input: INPUT): KotlinFileSpecs + abstract override fun invoke(context: CONTEXT, input: INPUT): KotlinFileSpecList override fun test(context: CONTEXT, input: Any): Boolean = super.test(context, input) + + override fun execute(context: CONTEXT, input: INPUT): KotlinFileSpecList = super.execute(context, input) ?: KotlinFileSpecList.EMPTY } diff --git a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecStrategy.kt b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecStrategy.kt index 0d8ab73..b121077 100644 --- a/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecStrategy.kt +++ b/kotlin-code-generation/src/main/kotlin/spi/strategy/KotlinFileSpecStrategy.kt @@ -15,7 +15,7 @@ abstract class KotlinFileSpecStrategy, override val inputType: KClass, order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER, -) : KotlinCodeGenerationStrategyBase( +) : KotlinFileSpecIterableStrategy( contextType = contextType, inputType = inputType, specType = KotlinFileSpec::class, diff --git a/kotlin-code-generation/src/main/kotlin/spi/strategy/_abstract.kt b/kotlin-code-generation/src/main/kotlin/spi/strategy/_abstract.kt new file mode 100644 index 0000000..aa29b45 --- /dev/null +++ b/kotlin-code-generation/src/main/kotlin/spi/strategy/_abstract.kt @@ -0,0 +1,29 @@ +package io.toolisticon.kotlin.generation.spi.strategy + +import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi +import io.toolisticon.kotlin.generation.spec.KotlinFileSpecIterable +import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext +import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi +import kotlin.reflect.KClass + +/** + * Base class for [KotlinFileSpecStrategy] and [KotlinFileSpecListStrategy] so we can join single and multi results + * during generation. + */ +@ExperimentalKotlinPoetApi +sealed class KotlinFileSpecIterableStrategy, INPUT : Any, SPEC : KotlinFileSpecIterable>( + contextType: KClass, + override val inputType: KClass, + specType: KClass, + order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER, +) : KotlinCodeGenerationStrategyBase( + contextType = contextType, + inputType = inputType, + specType = specType, + order = order +) { + + abstract override fun invoke(context: CONTEXT, input: INPUT): SPEC + + override fun test(context: CONTEXT, input: Any): Boolean = super.test(context, input) +} diff --git a/kotlin-code-generation/src/test/kotlin/KotlinCodeGenerationTest.kt b/kotlin-code-generation/src/test/kotlin/KotlinCodeGenerationTest.kt index 1f3f2ae..bb2a1bc 100644 --- a/kotlin-code-generation/src/test/kotlin/KotlinCodeGenerationTest.kt +++ b/kotlin-code-generation/src/test/kotlin/KotlinCodeGenerationTest.kt @@ -1,4 +1,3 @@ - package io.toolisticon.kotlin.generation import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi @@ -7,11 +6,10 @@ import io.toolisticon.kotlin.generation.KotlinCodeGeneration.generateFiles import io.toolisticon.kotlin.generation.KotlinCodeGeneration.name.asCodeBlock import io.toolisticon.kotlin.generation.KotlinCodeGeneration.name.asMemberName import io.toolisticon.kotlin.generation._test.MutableSpiRegistry -import io.toolisticon.kotlin.generation._test.TestContext import io.toolisticon.kotlin.generation._test.TestDeclaration import io.toolisticon.kotlin.generation._test.TestDeclarationFileStrategy import io.toolisticon.kotlin.generation._test.TestInput -import io.toolisticon.kotlin.generation.spi.strategy.KotlinFileSpecStrategy +import io.toolisticon.kotlin.generation._test.testContextFactory import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Nested @@ -40,19 +38,16 @@ internal class KotlinCodeGenerationTest { private val testInput = TestInput().put("name", String::class) private val testDeclaration = TestDeclaration(className, testInput) + @Test fun `fail when no strategy registered`() { assertThat(registry.strategies).isEmpty() assertThatThrownBy { - generateFiles>( - input = testDeclaration, - contextFactory = { TestContext(it.rootClassName, registry) } - ) + generateFiles(input = testDeclaration, contextFactory = testContextFactory(registry)) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( - "No applicable strategy found/filtered for " + - "`class io.toolisticon.kotlin.generation.spi.strategy.KotlinFileSpecStrategy`." + "No applicable strategy found/filtered for context=`TestContext`, input=`TestDeclaration`." ) } @@ -64,14 +59,10 @@ internal class KotlinCodeGenerationTest { assertThat(registry.strategies).isNotEmpty() assertThatThrownBy { - generateFiles>( - input = testDeclaration, - contextFactory = { TestContext(it.rootClassName, registry) } - ) + generateFiles(input = testDeclaration, contextFactory = testContextFactory(registry)) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( - "No applicable strategy found/filtered for " + - "`class io.toolisticon.kotlin.generation.spi.strategy.KotlinFileSpecStrategy`." + "No applicable strategy found/filtered for context=`TestContext`, input=`TestDeclaration`." ) } @@ -83,10 +74,7 @@ internal class KotlinCodeGenerationTest { assertThat(registry.strategies).isNotEmpty() - val file = generateFiles>( - input = testDeclaration, - contextFactory = { TestContext(it.rootClassName, registry) } - ).single() + val file = generateFiles(input = testDeclaration, contextFactory = testContextFactory(registry)).single() assertThat(file.code).isEqualToIgnoringWhitespace( """ diff --git a/kotlin-code-generation/src/test/kotlin/_test/TestContext.kt b/kotlin-code-generation/src/test/kotlin/_test/TestContext.kt index 4011999..9cf294e 100644 --- a/kotlin-code-generation/src/test/kotlin/_test/TestContext.kt +++ b/kotlin-code-generation/src/test/kotlin/_test/TestContext.kt @@ -1,9 +1,9 @@ - package io.toolisticon.kotlin.generation._test import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContext +import io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationContextFactory @OptIn(ExperimentalKotlinPoetApi::class) class TestContext( @@ -12,3 +12,8 @@ class TestContext( ) : KotlinCodeGenerationContext { override val contextType = TestContext::class } + +@OptIn(ExperimentalKotlinPoetApi::class) +fun testContextFactory(registry: MutableSpiRegistry): KotlinCodeGenerationContextFactory = KotlinCodeGenerationContextFactory { + TestContext(rootClassName = it.rootClassName, registry = registry) +} diff --git a/pom.xml b/pom.xml index a1e783d..4f20a4a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ io.toolisticon.kotlin.generation._ kotlin-code-generation-root - 0.0.7 + 0.0.8 pom: ${project.artifactId} Root of kotlin-code-generation