com.antwerkz.critter.CritterField.kt Maven / Gradle / Ivy
package com.antwerkz.critter
import com.antwerkz.critter.Visibility.PUBLIC
import org.mongodb.morphia.annotations.Embedded
import org.mongodb.morphia.annotations.Id
import org.mongodb.morphia.annotations.Property
class CritterField(val name: String, val type: String) : AnnotationHolder,/* Comparable,*/ Visible {
companion object {
val NUMERIC_TYPES =
listOf("Float", "Double", "Long", "Integer", "Byte", "Short", "Number")
.map { listOf(it, "${it}?", "java.lang.${it}", "java.lang.${it}?", "kotlin.${it}", "kotlin.${it}?") }
.flatMap { it } + "Int"
val CONTAINER_TYPES =
listOf("List", "Set")
.map { listOf(it, "java.util.$it", "Mutable$it")}
.flatMap { it }
}
val shortParameterTypes = mutableListOf()
val fullParameterTypes = mutableListOf()
override val annotations = mutableListOf()
var isStatic = false
var isFinal = false
var stringLiteralInitializer: String? = null
override var visibility: Visibility = PUBLIC
var parameterizedType = type
fun isContainer() = type.substringBefore("<") in CritterField.CONTAINER_TYPES
fun isNumeric() = CritterField.NUMERIC_TYPES.contains(type)
fun mappedName(): String {
return if (hasAnnotation(Id::class.java)) {
"\"_id\""
} else {
getValue(Embedded::class.java, getValue(Property::class.java, "\"${name}\""))
}
}
override fun toString(): String {
return "CritterField(name='$name', type='$type', parameterizedType='$fullParameterTypes')"
}
}
fun String.nameCase(): String {
return substring(0, 1).toUpperCase() + substring(1)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy