io.orangebuffalo.testcontainers.playwright.junit.AnnotationsUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testcontainers-playwright Show documentation
Show all versions of testcontainers-playwright Show documentation
Testcontainers-based container for Playwright
package io.orangebuffalo.testcontainers.playwright.junit
import java.lang.reflect.AnnotatedElement
import kotlin.reflect.KClass
internal fun hasAnnotation(element: AnnotatedElement, annotationClass: KClass): Boolean {
return findAnnotation(element, annotationClass) != null
|| findMetaAnnotation(element, annotationClass) != null
}
internal fun getAnnotation(element: AnnotatedElement, annotationClass: KClass): A? {
return findAnnotation(element, annotationClass)
?: findMetaAnnotation(element, annotationClass)
}
private fun findAnnotation(element: AnnotatedElement, annotationClass: KClass): A? {
return element.getAnnotation(annotationClass.java)
}
@Suppress("UNCHECKED_CAST")
private fun findMetaAnnotation(
element: AnnotatedElement,
annotationClass: KClass,
visited: MutableSet = mutableSetOf()
): A? {
val annotations = element.annotations
for (annotation in annotations) {
if (annotation.annotationClass == annotationClass) {
return annotation as A
}
val next = annotation.annotationClass.java
if (visited.add(next)) {
val nextResult = findMetaAnnotation(next, annotationClass, visited)
if (nextResult != null) {
return nextResult
}
}
}
return null
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy