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

se.ansman.kotshi.kapt.MetadataAccessor.kt Maven / Gradle / Ivy

Go to download

An annotations processor that generates Moshi adapters from Kotlin data classes

There is a newer version: 3.0.0
Show newest version
package se.ansman.kotshi.kapt

import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.metadata.ImmutableKmClass
import com.squareup.kotlinpoet.metadata.specs.ClassInspector
import com.squareup.kotlinpoet.metadata.specs.toTypeSpec
import com.squareup.kotlinpoet.metadata.toImmutableKmClass
import javax.lang.model.element.Element

class MetadataAccessor(private val classInspector: ClassInspector) {
    private val metadataPerType = mutableMapOf()
    private val typeSpecPerType = mutableMapOf()

    fun getMetadata(type: Element): ImmutableKmClass =
        metadataPerType.getOrPut(type) {
            type.metadata.toImmutableKmClass()
        }

    fun getTypeSpec(type: Element): TypeSpec =
        typeSpecPerType.getOrPut(type) {
            getMetadata(type).toTypeSpec(classInspector)
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy