se.ansman.kotshi.model.GeneratableJsonAdapter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler Show documentation
Show all versions of compiler Show documentation
An annotations processor that generates Moshi adapters from Kotlin data classes
The newest version!
package se.ansman.kotshi.model
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.TypeVariableName
sealed class GeneratableJsonAdapter {
abstract val targetPackageName: String
abstract val targetSimpleNames: List
open val targetTypeVariables: List get() = emptyList()
val rawTargetType by lazy {
ClassName(targetPackageName, targetSimpleNames)
}
val targetType: TypeName by lazy {
if (targetTypeVariables.isEmpty()) {
rawTargetType
} else {
rawTargetType.parameterizedBy(targetTypeVariables)
}
}
val adapterClassName by lazy {
ClassName(targetPackageName, "Kotshi${targetSimpleNames.joinToString("_")}JsonAdapter")
}
val adapterTypeName by lazy {
val variables = targetTypeVariables
if (variables.isEmpty()) {
adapterClassName
} else {
adapterClassName.parameterizedBy(variables)
}
}
val adapterName: String get() = adapterClassName.simpleName
}