FunctionDispatcher

open class FunctionDispatcher(functions: Collection<KCallable<Any?>>, matchNumbersLeniently: Boolean, matchClassesQualnames: Boolean, resolveAmbiguousSpecificity: Boolean)

Dynamic dispatch to one of multiple KCallables.

Uses reflection to narrow down functions to the one(s) that have the correct signature for a given array of arguments

Varargs can be used, but they must be supplied as a single correctly typed array instead of as separate arguments.

Constructors

FunctionDispatcher
Link copied to clipboard
fun FunctionDispatcher(functions: Collection<KCallable<Any?>>, matchNumbersLeniently: Boolean = false, matchClassesQualnames: Boolean = false, resolveAmbiguousSpecificity: Boolean = false)

Functions

call
Link copied to clipboard
open fun <R> call(arguments: Array<Any?>): R

Call the correct function for a given array of arguments.

checkCallableMatches
Link copied to clipboard
private fun checkCallableMatches(callable: KCallable<Any?>, arguments: Array<Any?>, paramKtypeAppends: HashMap<KCallable<Any?>, ArrayList<KType>>): Boolean
checkParameterMatches
Link copied to clipboard
private fun checkParameterMatches(kparam: KParameter, arg: Any?, paramKtypeAppend: ArrayList<KType>): Boolean
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
getMatchingCallables
Link copied to clipboard
private fun getMatchingCallables(arguments: Array<Any?>, paramKtypeAppends: HashMap<KCallable<Any?>, ArrayList<KType>>): List<KCallable<Any?>>
getMostSpecificCallable
Link copied to clipboard
private fun getMostSpecificCallable(matches: List<KCallable<Any?>>, paramKtypes: Map<KCallable<Any?>, ArrayList<KType>>): KCallable<Any?>?
hashCode
Link copied to clipboard
open fun hashCode(): Int
nounifyFunctions
Link copied to clipboard
open fun nounifyFunctions(): String
toString
Link copied to clipboard
open fun toString(): String

Properties

functions
Link copied to clipboard
val functions: Collection<KCallable<Any?>>

List of functions against which to resolve calls.

matchClassesQualnames
Link copied to clipboard
val matchClassesQualnames: Boolean = false

Whether to treat classes as the same if they have the same qualifiedName. Useful for E.G. ignoring the invariant arrays representing vararg parameters. Adds small extra step to some calls.

matchNumbersLeniently
Link copied to clipboard
val matchNumbersLeniently: Boolean = false

Whether to treat all numeric types as the same. Useful for E.G. untyped deserialized data. Adds small extra step to most calls.

resolveAmbiguousSpecificity
Link copied to clipboard
val resolveAmbiguousSpecificity: Boolean = false

Whether to try to resolve multiple ambiguous matching signatures by finding one that strictly subtypes all others. Rules for this are documented under getMostSpecificCallable. Does not add any extra steps unless needed; Increases function domain properly handled but does not decrease performance in other uses.

Inheritors

Reflection
Link copied to clipboard

Sources

jvm source
Link copied to clipboard