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

se.ansman.kotshi.model.GeneratedAdapter.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.model

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.TypeSpec
import se.ansman.kotshi.KotshiConstructor
import se.ansman.kotshi.ProguardConfig
import se.ansman.kotshi.renderer.AdapterRenderer


data class GeneratedAdapter(
    val adapter: GeneratableJsonAdapter,
    val fileSpec: FileSpec,
    val proguardConfig: ProguardConfig?
) : Comparable {
    private val adapterClassName: ClassName = ClassName(adapter.targetPackageName, adapter.adapterName)

    private val typeSpec = fileSpec.members.filterIsInstance().single()
    internal val constructor = KotshiConstructor(
        moshiParameterName = typeSpec.primaryConstructor
            ?.parameters
            ?.find { it.name == AdapterRenderer.moshiParameterName }
            ?.name,
        typesParameterName = typeSpec.primaryConstructor
            ?.parameters
            ?.find { it.name == AdapterRenderer.typesParameterName }
            ?.name,
    )

    override fun compareTo(other: GeneratedAdapter): Int = adapterClassName.compareTo(other.adapterClassName)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy