Promote findAnnotations to Stable #KT-51470
This commit is contained in:
@@ -36,8 +36,9 @@ inline fun <reified T : Annotation> KAnnotatedElement.hasAnnotation(): Boolean =
|
|||||||
* in Java reflection ([java.lang.reflect.AnnotatedElement.getAnnotationsByType]). This is supported both for Kotlin-repeatable
|
* in Java reflection ([java.lang.reflect.AnnotatedElement.getAnnotationsByType]). This is supported both for Kotlin-repeatable
|
||||||
* ([kotlin.annotation.Repeatable]) and Java-repeatable ([java.lang.annotation.Repeatable]) annotation classes.
|
* ([kotlin.annotation.Repeatable]) and Java-repeatable ([java.lang.annotation.Repeatable]) annotation classes.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.5")
|
@SinceKotlin("1.7")
|
||||||
@ExperimentalStdlibApi
|
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
@WasExperimental(ExperimentalStdlibApi::class)
|
||||||
inline fun <reified T : Annotation> KAnnotatedElement.findAnnotations(): List<T> =
|
inline fun <reified T : Annotation> KAnnotatedElement.findAnnotations(): List<T> =
|
||||||
findAnnotations(T::class)
|
findAnnotations(T::class)
|
||||||
|
|
||||||
@@ -49,9 +50,9 @@ inline fun <reified T : Annotation> KAnnotatedElement.findAnnotations(): List<T>
|
|||||||
* in Java reflection ([java.lang.reflect.AnnotatedElement.getAnnotationsByType]). This is supported both for Kotlin-repeatable
|
* in Java reflection ([java.lang.reflect.AnnotatedElement.getAnnotationsByType]). This is supported both for Kotlin-repeatable
|
||||||
* ([kotlin.annotation.Repeatable]) and Java-repeatable ([java.lang.annotation.Repeatable]) annotation classes.
|
* ([kotlin.annotation.Repeatable]) and Java-repeatable ([java.lang.annotation.Repeatable]) annotation classes.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@SinceKotlin("1.7")
|
||||||
@SinceKotlin("1.5")
|
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
@ExperimentalStdlibApi
|
@WasExperimental(ExperimentalStdlibApi::class)
|
||||||
fun <T : Annotation> KAnnotatedElement.findAnnotations(klass: KClass<T>): List<T> {
|
fun <T : Annotation> KAnnotatedElement.findAnnotations(klass: KClass<T>): List<T> {
|
||||||
val filtered = annotations.filterIsInstance(klass.java)
|
val filtered = annotations.filterIsInstance(klass.java)
|
||||||
if (filtered.isNotEmpty()) return filtered
|
if (filtered.isNotEmpty()) return filtered
|
||||||
@@ -62,6 +63,7 @@ fun <T : Annotation> KAnnotatedElement.findAnnotations(klass: KClass<T>): List<T
|
|||||||
if (container != null) {
|
if (container != null) {
|
||||||
// A repeatable annotation container must have a method "value" returning the array of repeated annotations.
|
// A repeatable annotation container must have a method "value" returning the array of repeated annotations.
|
||||||
val valueMethod = container::class.java.getMethod("value")
|
val valueMethod = container::class.java.getMethod("value")
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
return (valueMethod(container) as Array<T>).asList()
|
return (valueMethod(container) as Array<T>).asList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user