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

commonMain.io.kotest.mpp.reflection.kt Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package io.kotest.mpp

import kotlin.reflect.KClass

/**
 * Returns the longest possible name available for this class.
 * That is, in order, the FQN, the simple name, or .
 */
fun KClass<*>.bestName(): String = fqn() ?: simpleName ?: this.toString()

/**
 * Returns the fully qualified name for this class, or null
 */
expect fun KClass<*>.fqn(): String?

/**
 * Returns the annotations on this class or empty list if not supported
 */
expect fun KClass<*>.annotations(): List

/**
 * Finds the first annotation of type T on this class, or returns null if annotations
 * are not supported on this platform or the annotation is missing.
 */
inline fun  KClass<*>.annotation(): T? = annotations().filterIsInstance().firstOrNull()

inline fun  KClass<*>.hasAnnotation(): Boolean = annotations().filterIsInstance().isNotEmpty()

/**
 * Returns true if this KClass is a data class, false if it is not, or null if the functionality
 * is not supported on the platform.
 */
expect val  KClass.isDataClass: Boolean?

/**
 * Returns the names of the parameters if supported. Eg, for `fun foo(a: String, b: Boolean)` on the JVM
 * it would return [a, b] and on unsupported platforms an empty list.
 */
expect val Function<*>.paramNames: List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy