InstanceMethodDispatcher

class InstanceMethodDispatcher(instance: Any, methodName: String, matchNumbersLeniently: Boolean, matchClassesQualnames: Boolean, resolveAmbiguousSpecificity: Boolean) : FunctionDispatcher

Dynamic multiple dispatch for Any Kotlin instances by methodName.

Uses reflection to first find all members matching the expected method name, and then to call the correct method for given arguments.

See the FunctionDispatcher superclass for details on the method resolution strategy and configuration parameters.

Constructors

InstanceMethodDispatcher
Link copied to clipboard
fun InstanceMethodDispatcher(instance: Any, methodName: String, matchNumbersLeniently: Boolean = false, matchClassesQualnames: Boolean = false, resolveAmbiguousSpecificity: Boolean = false)

Functions

call
Link copied to clipboard
open override 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 override fun nounifyFunctions(): String
toString
Link copied to clipboard
open override fun toString(): String

Properties

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

List of functions against which to resolve calls.

instance
Link copied to clipboard
val instance: Any

The receiver on which to find and call a method.

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.

methodName
Link copied to clipboard
val methodName: String

The name of the method to resolve and call.

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.

Sources

jvm source
Link copied to clipboard