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

name.remal.kotlin.reflect.KProperty.kt Maven / Gradle / Ivy

The newest version!
package name.remal

import kotlin.reflect.KMutableProperty
import kotlin.reflect.KProperty
import kotlin.reflect.jvm.javaField
import kotlin.reflect.jvm.javaGetter
import kotlin.reflect.jvm.javaSetter

fun  KProperty<*>.getMetaAnnotations(type: Class): List {
    val result = mutableSetOf()
    javaField?.getMetaAnnotations(type)?.forEach { result.add(it) }
    javaGetter?.getMetaAnnotations(type)?.forEach { result.add(it) }
    if (this is KMutableProperty<*>) javaSetter?.getMetaAnnotations(type)?.forEach { result.add(it) }
    return result.toList()
}

fun  KProperty<*>.getMetaAnnotation(type: Class) = getMetaAnnotations(type).firstOrNull()
fun  KProperty<*>.hasMetaAnnotation(type: Class) = null != getMetaAnnotation(type)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy