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

io.github.graphglue.graphql.extensions.kClassExtensions.kt Maven / Gradle / Ivy

Go to download

A library to develop annotation-based code-first GraphQL servers using GraphQL Kotlin, Spring Boot and Neo4j - excluding Spring GraphQL server dependencies

There is a newer version: 7.0.5
Show newest version
package io.github.graphglue.graphql.extensions

import org.springframework.core.annotation.AnnotatedElementUtils
import org.springframework.core.annotation.AnnotationUtils
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1

/**
 * Uses [AnnotationUtils.findAnnotation] to find an annotation of type [A]
 *
 * @param A the type of the [Annotation] to find
 * @return the found [Annotation] or `null` if not found
 */
inline fun  KClass<*>.springFindAnnotation(): A? {
    return AnnotationUtils.findAnnotation(this.java, A::class.java)
}

/**
 * Uses [AnnotatedElementUtils.findMergedRepeatableAnnotations] to find all repeatable annotations of type [A]
 * Includes annotations on superclasses
 *
 * @param A the type of the [Annotation]s to find
 * @return the found [Annotation]s (can be empty)
 */
inline fun  KClass<*>.springFindRepeatableAnnotations(): Collection {
    return AnnotatedElementUtils.findMergedRepeatableAnnotations(this.java, A::class.java)
}

/**
 * Uses [AnnotatedElementUtils.getMergedRepeatableAnnotations] to find all repeatable annotations of type [A]
 * Excludes annotations on superclasses
 *
 * @param A the type of the [Annotation]s to find
 * @return the found [Annotation]s (can be empty)
 */
inline fun  KClass<*>.springGetRepeatableAnnotations(): Collection {
    return AnnotatedElementUtils.getMergedRepeatableAnnotations(this.java, A::class.java)
}

/**
 * Finds a property by name
 *
 * @param property the name of the property
 * @return the found property
 */
fun KClass<*>.findProperty(property: String): KProperty1<*, *> {
    return this.members.filterIsInstance>().first { it.name == property }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy