public interface KotlinFunction
This class is thread-safe, as it is immutable and uses synchronization for lazy reflection fetching.
| Modifier and Type | Method and Description |
|---|---|
<T> T |
call(@Nullable java.lang.Object instance,
@NotNull java.util.List<java.lang.Object> arguments,
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Calls the function with the given arguments.
|
<T> T |
callByIndices(@Nullable java.lang.Object instance,
@NotNull java.util.Map<java.lang.Integer,java.lang.Object> arguments,
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Calls the function with the given arguments, mapped by the index
of each parameter.
|
<T> T |
callByNames(@Nullable java.lang.Object instance,
@NotNull java.util.Map<java.lang.String,java.lang.Object> arguments,
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Calls the function with the given arguments, mapped by the name
of each parameter.
|
<T> T |
callByParameters(@Nullable java.lang.Object instance,
@NotNull java.util.Map<java.lang.reflect.Parameter,java.lang.Object> arguments,
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Calls the function with the given arguments, mapped by
the
Parameter object representing each parameter. |
@Nullable CallableMethod |
getDefaultSyntheticMethod()
Returns the synthetic method generated by the Kotlin compiler
for invoking a function with the default values.
|
@NotNull CallableMethod |
getMethod()
Returns the method that this function wraps
|
@NotNull java.lang.reflect.Parameter |
getParameter(int index)
Returns the parameter by the given index, otherwise throws
an
IndexOutOfBoundsException |
@NotNull java.lang.reflect.Parameter |
getParameter(@NotNull java.lang.String name)
Returns the parameter by the given name, otherwise throws
an
IllegalArgumentException |
@Unmodifiable @NotNull java.util.List<java.lang.reflect.Parameter> |
getParameters()
Returns the real function parameters, as declared in the Kotlin source.
|
@Unmodifiable @NotNull java.util.Map<java.lang.String,java.lang.reflect.Parameter> |
getParametersByName()
Returns the real function parameters and their names, as declared
in the Kotlin source.
|
boolean |
isSuspend()
Tests whether is this function suspend or not
|
static @NotNull KotlinFunction |
wrap(@NotNull java.lang.reflect.Method method)
Generates a
KotlinFunction for the given Method. |
@NotNull static @NotNull KotlinFunction wrap(@NotNull @NotNull java.lang.reflect.Method method)
KotlinFunction for the given Method.method - The method to wrapKotlinFunctionboolean isSuspend()
<T> T call(@Nullable
@Nullable java.lang.Object instance,
@NotNull
@NotNull java.util.List<java.lang.Object> arguments,
@NotNull
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
To use the default value of a parameter, pass a null in its place.
T - The function return typeinstance - Instance to call the function witharguments - The arguments to invoke withisOptional - A function that guides this invocation
into knowing which parameters are optional,
so it can use their default values, and which
ones are not, so it can report errors as appropriate
when missing.
This should either test for a certain annotation if you have access to the source function, or check against a pre-defined list of parameter names assembled by the developer, or any other strategy that correctly reports whether a parameter is optional or not.
This parameter is necessary as it allows us to drop the dependency on kotlin-reflect.
<T> T callByIndices(@Nullable
@Nullable java.lang.Object instance,
@NotNull
@NotNull java.util.Map<java.lang.Integer,java.lang.Object> arguments,
@NotNull
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
For example, if a function has three parameters, where the second is optional, it can be invoked with
callByIndices(map(
0, "value 1", // first parameter
2, "value 3" // third parameter
))
in which the second parameter will use its default value.T - The function return typeinstance - Instance to call the function witharguments - The arguments to invoke withisOptional - A function that guides this invocation
into knowing which parameters are optional,
so it can use their default values, and which
ones are not, so it can report errors as appropriate
when missing.
This should either test for a certain annotation if you have access to the source function, or check against a pre-defined list of parameter names assembled by the developer, or any other strategy that correctly reports whether a parameter is optional or not.
This parameter is necessary as it allows us to drop the dependency on kotlin-reflect.
<T> T callByParameters(@Nullable
@Nullable java.lang.Object instance,
@NotNull
@NotNull java.util.Map<java.lang.reflect.Parameter,java.lang.Object> arguments,
@NotNull
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Parameter object representing each parameter.
This allows flexibility in controlling which parameters to specify,
without having to rely on names or indexes. See getParameters()
and getParametersByName().
T - The function return typeinstance - Instance to call the function witharguments - The arguments to invoke withisOptional - A function that guides this invocation
into knowing which parameters are optional,
so it can use their default values, and which
ones are not, so it can report errors as appropriate
when missing.
This should either test for a certain annotation if you have access to the source function, or check against a pre-defined list of parameter names assembled by the developer, or any other strategy that correctly reports whether a parameter is optional or not.
This parameter is necessary as it allows us to drop the dependency on kotlin-reflect.
<T> T callByNames(@Nullable
@Nullable java.lang.Object instance,
@NotNull
@NotNull java.util.Map<java.lang.String,java.lang.Object> arguments,
@NotNull
@NotNull java.util.function.Function<java.lang.reflect.Parameter,java.lang.Boolean> isOptional)
Note: Parameter names at runtime may not necessarily match the ones at compile-time, in which cases, the function will throw an exception if an invalid name was provided.
T - The function return typeinstance - Instance to call the function witharguments - The arguments to invoke withisOptional - A function that guides this invocation
into knowing which parameters are optional,
so it can use their default values, and which
ones are not, so it can report errors as appropriate
when missing.
This should either test for a certain annotation if you have access to the source function, or check against a pre-defined list of parameter names assembled by the developer, or any other strategy that correctly reports whether a parameter is optional or not.
This parameter is necessary as it allows us to drop the dependency on kotlin-reflect.
@NotNull @NotNull CallableMethod getMethod()
@Nullable @Nullable CallableMethod getDefaultSyntheticMethod()
Note that the synthetic method is searched for on demand only. This function will attempt to find one on the first call.
@NotNull @Unmodifiable @NotNull java.util.List<java.lang.reflect.Parameter> getParameters()
This will not include the leading parameter in object functions,
which is generated by the compiler.
This list is unmodifiable.
@NotNull @Unmodifiable @NotNull java.util.Map<java.lang.String,java.lang.reflect.Parameter> getParametersByName()
This will not include the leading parameter in object functions,
which is generated by the compiler.
This list is unmodifiable.
@NotNull
@NotNull java.lang.reflect.Parameter getParameter(@NotNull
@NotNull java.lang.String name)
IllegalArgumentExceptionname - The parameter name.@NotNull
@NotNull java.lang.reflect.Parameter getParameter(int index)
throws java.lang.IndexOutOfBoundsException
IndexOutOfBoundsExceptionindex - The parameter index.java.lang.IndexOutOfBoundsException - if out of bounds