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

gsonpath.util.ElementExt.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package gsonpath.util

import javax.lang.model.element.Element

/**
 * Fetches the annotation from the element directly.
 *
 * Failing that it attempts to find any annotations that are annotated with the annotation type. The method then returns
 * that annotation. This allows easy annotation reuse.
 */
fun  Element.getAnnotationEx(annotationType: Class): A? {
    val immediateAnnotation = getAnnotation(annotationType)
    if (immediateAnnotation != null) {
        return immediateAnnotation
    }

    // See if there are any annotations that are themselves annotated by the annotation we want.
    return annotationMirrors
            .asSequence()
            .mapNotNull { it.annotationType.asElement().getAnnotation(annotationType) }
            .firstOrNull()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy