io.github.databob.LanguageConstructsGenerator.kt Maven / Gradle / Ivy
package io.github.databob
import io.github.databob.Databob
import io.github.databob.Generator
import io.github.databob.Generators
import java.lang.reflect.Type
class LanguageConstructsGenerator : Generator {
private val generator = CompositeGenerator(
Generators.ofType { d -> Exception(d.mk()) },
Generators.ofType { d -> RuntimeException(d.mk()) },
object : Generator {
override fun mk(type: Type, databob: Databob): Any? = when {
Class.forName(type.typeName).isEnum -> Class.forName(type.typeName).enumConstants[0]
else -> null
}
}
)
override fun mk(type: Type, databob: Databob): Any? = generator.mk(type, databob)
}