com.antwerkz.critter.AnnotationHolder.kt Maven / Gradle / Ivy
package com.antwerkz.critter
interface AnnotationHolder {
val annotations: MutableList
fun getValue(ann: Class, defaultValue: String): String {
return annotations.firstOrNull { it.matches(ann) }
?.getValue() ?: defaultValue
}
fun hasAnnotation(aClass: Class): Boolean {
return annotations.any { it.matches(aClass) }
}
}
class CritterAnnotation(val name: String, val values: Map = mapOf()) {
var klass: Class? = null
init {
if (name.contains(".")) {
@Suppress("UNCHECKED_CAST")
try {
klass = Class.forName(name) as Class?
} catch(ignored: ClassNotFoundException) {
}
}
}
fun matches(aClass: Class): Boolean {
return aClass == klass || aClass.name == name
}
fun getValue(): String? {
return values["value"] as String?
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy