-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generateFiles via KotlinFileSpecIterable
- Loading branch information
1 parent
2f5277a
commit 274551f
Showing
11 changed files
with
142 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
...n/spi/strategy/KotlinFileSpecsStrategy.kt → ...pi/strategy/KotlinFileSpecListStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CONTEXT : KotlinCodeGenerationContext<CONTEXT>, INPUT : Any>( | ||
abstract class KotlinFileSpecListStrategy<CONTEXT : KotlinCodeGenerationContext<CONTEXT>, INPUT : Any>( | ||
contextType: KClass<CONTEXT>, | ||
override val inputType: KClass<INPUT>, | ||
order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER, | ||
) : KotlinCodeGenerationStrategyBase<CONTEXT, INPUT, KotlinFileSpecs>( | ||
) : KotlinFileSpecIterableStrategy<CONTEXT, INPUT, KotlinFileSpecList>( | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
kotlin-code-generation/src/main/kotlin/spi/strategy/_abstract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CONTEXT : KotlinCodeGenerationContext<CONTEXT>, INPUT : Any, SPEC : KotlinFileSpecIterable>( | ||
contextType: KClass<CONTEXT>, | ||
override val inputType: KClass<INPUT>, | ||
specType: KClass<SPEC>, | ||
order: Int = KotlinCodeGenerationSpi.DEFAULT_ORDER, | ||
) : KotlinCodeGenerationStrategyBase<CONTEXT, INPUT, SPEC>( | ||
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) | ||
} |
Oops, something went wrong.