Skip to content

toolisticon/kotlin-code-generation

Repository files navigation

kotlin-code-generation

The one-stop lib for code generation for kotlin (jvm) and code generation testing. Based on kotlin-poet.

stable Maven Central Version Build Status Codacy Badge codecov Kotlin sponsored javadoc

Usage:

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.toolisticon.kotlin.generation</groupId>
        <artifactId>kotlin-code-generation-bom</artifactId>
        <version>LATEST_VERSION</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

Documentation

This code generation lib wraps the fantastic kotlin-poet framework. The documentation is based on the kotlin-poet documentation.

Getting started

Core concept are Strategies and Processors.

Load SPI

  • Implement and list your strategies and processors in the META-INF/services/io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi. Both interfaces are loaded via the same ServiceLoader mechanism, and later filtered for the specific type of strategy or processor.
  • Load the services via val spi = KotlinCodeGeneration.spi.load()
  • Define your context by extending the KotlinCodeGenerationContext class. This context is passed to the strategies and processors, so they can use more data than just the input item in the loop.
    • You probably want to filter the loaded list you provide to your specific context.

Features

  • KotlinAnnotationSpec
    • KotlinAnnotationSpecBuilder
  • KotlinFileSpec
    • KotlinFileSpecBuilder
  • KotlinFunSpec
    • KotlinFunSpecBuilder
  • KotlinParameterSpec
    • KotlinParameterSpecBuilder
  • KotlinPropertySpec
    • KotlinPropertySpecBuilder

Roadmap

Specs to support

  • com/squareup/kotlinpoet/TypeAliasSpec
  • com/squareup/kotlinpoet/TypeSpec

Builders to implement

  • com/squareup/kotlinpoet/AnnotationSpec$Builder
    • Taggable.Builder
  • com/squareup/kotlinpoet/CodeBlock$Builder
    • None
  • com/squareup/kotlinpoet/FileSpec$Builder
    • Annotatable.Builder
    • Taggable.Builder
    • TypeSpecHolder.Builder
  • com/squareup/kotlinpoet/FunSpec$Builder
    • Annotatable.Builder
    • ContextReceivable.Builder
    • Documentable.Builder
    • Taggable.Builder
    • OriginatingElementsHolder.Builder
  • com/squareup/kotlinpoet/ParameterSpec$Builder
    • Annotatable.Builder
    • Documentable.Builder
    • Taggable.Builder
  • com/squareup/kotlinpoet/PropertySpec$Builder
    • Annotatable.Builder
    • ContextReceivable.Builder
    • Documentable.Builder
    • OriginatingElementsHolder.Builder
    • Taggable.Builder
  • com/squareup/kotlinpoet/TypeAliasSpec$Builder
    • Annotatable.Builder
    • Documentable.Builder
    • Taggable.Builder

About

Opinionated setup for kotlin-poet code generator projects

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages