All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spi.KotlinCodeGenerationContext.kt Maven / Gradle / Ivy

There is a newer version: 0.1.0
Show newest version
package io.toolisticon.kotlin.generation.spi

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import kotlin.reflect.KClass

/**
 * Context used for SPI execution, providing additional information that is not transported via the `input`
 * work item. Might hold mutable state shared by strategies and processors to transport data on the fly.
 *
 * Required because all spi-instances have to be generated via default-constructor, so all state data
 * we would normally store in a property has to be passed to every function call.
 *
 * Hint: for implementing a concrete context, use the [io.toolisticon.kotlin.generation.spi.context.KotlinCodeGenerationContextBase].
 */
@ExperimentalKotlinPoetApi
interface KotlinCodeGenerationContext> {

  /**
   * SELF type of the context implementation, used to verify against [io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi.contextType].
   */
  val contextType: KClass

  /**
   * The registry holding strategies and processors so implementations can nest calls to other instances.
   */
  val registry: KotlinCodeGenerationSpiRegistry

  /**
   * Convenience access to [io.toolisticon.kotlin.generation.spi.strategy.KotlinCodeGenerationStrategyList.filterIsInstance].
   */
  fun , CONTEXT : KotlinCodeGenerationContext, INPUT : Any, SPEC : Any> strategies(
    strategyType: KClass
  ): List = registry.strategies.filterIsInstance(strategyType.java)

  /**
   * Convenience access to [io.toolisticon.kotlin.generation.spi.processor.KotlinCodeGenerationProcessorList.filterIsInstance].
   */
  fun , CONTEXT : KotlinCodeGenerationContext, INPUT : Any, BUILDER : Any> processors(
    processorType: KClass
  ): List = registry.processors.filterIsInstance(processorType.java)
}

/**
 * Factory to create generation context.
 */
@OptIn(ExperimentalKotlinPoetApi::class)
fun interface KotlinCodeGenerationContextFactory, INPUT : Any> : (INPUT) -> CONTEXT




© 2015 - 2024 Weber Informatics LLC | Privacy Policy