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

spec.KotlinValueClassSpec.kt Maven / Gradle / Ivy

There is a newer version: 0.1.0
Show newest version
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.typeSpec.isValueClass
import io.toolisticon.kotlin.generation.poet.KDoc
import kotlin.reflect.KClass

/**
 * Represents a value class.
 */
@ExperimentalKotlinPoetApi
data class KotlinValueClassSpec(
  override val className: ClassName,
  private val spec: TypeSpec
) : KotlinGeneratorTypeSpec, KotlinValueClassSpecSupplier, KotlinDocumentableSpec {

  init {
    require(spec.isValueClass) { "Not a valueClass spec: $spec." }
  }

  override fun  tag(type: KClass): T? = get().tag(type)
  override val kdoc: KDoc get() = KDoc(spec.kdoc)
  override fun spec(): KotlinValueClassSpec = this
  override fun get(): TypeSpec = spec
}

/**
 * Marks the builder and the spec so they are interchangeable.
 */
@ExperimentalKotlinPoetApi
interface KotlinValueClassSpecSupplier : KotlinGeneratorSpecSupplier, ToFileTypeSpecSupplier {
  override fun get(): TypeSpec = spec().get()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy