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

spec.KotlinAnnotationSpec.kt Maven / Gradle / Ivy

The newest version!
package io.toolisticon.kotlin.generation.spec

import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
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 {

  companion object {
    fun of(annotations: List): List = annotations.map { KotlinAnnotationSpec(it) }
  }

  val typeName: TypeName get() = spec.typeName
  val members: List get() = spec.members

  override fun get(): AnnotationSpec = spec
  override fun spec(): KotlinAnnotationSpec = this

  override fun toString(): String {
    return "KotlinAnnotationSpec(typeName=$typeName, members=$members)"
  }
}

/**
 * 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)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy