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

main.net.jqwik.kotlin.internal.ParameterAnnotationEnhancer.kt Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.kotlin.internal

import net.jqwik.api.providers.TypeUsage
import java.lang.reflect.Parameter

/**
 * Annotations of a Kotlin's parameter's type (e.g. aParam: @MyAnnotation MyType) must be added explicitly.
 */
class ParameterAnnotationEnhancer : TypeUsage.Enhancer {

    override fun forParameter(original: TypeUsage, parameter: Parameter): TypeUsage {
        val parameterDeclaredInKotlinClass = parameter.declaringExecutable.declaringClass.isKotlinClass()
        if (!parameterDeclaredInKotlinClass) return original
        val typeAnnotations = parameter.annotatedType.annotations
        if (typeAnnotations.isEmpty()) {
            return original
        }
        return typeAnnotations.fold(original) { acc, annotation -> acc.withAnnotation(annotation) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy