// A signature that only wants the "context" and "args" arguments
public static final Signature ARG_COUNT_CHECK_FOLD = Signature
.returning(void.class)
.appendArg("args", Object[].class);
// The actual target signature for arg count checking, with min and max ints
public static final Signature ARG_COUNT_CHECK_SIGNATURE = Signature
.returning(int.class)
.appendArg("args", Object[].class)
.appendArg("min", int.class)
.appendArg("max", int.class);
// A SmartHandle for the arity-checking method, using the fold and signature
// from above and inserting 1, 3 for min, max
SmartHandle arityCheck = SmartBinder
.from(ARITY_CHECK_FOLD)
.append("min", 1)
.append("max", 3)
.cast(ARITY_CHECK_SIGNATURE)
.invokeStaticQuiet(LOOKUP, ArgCountChecker.class, "checkArgumentCount");
// The variable-arity call contaings other arguments plus the Object[] args.
// Here, we can just fold with our arityCheck SmartHandle, which drops args
// we are not interested in, passes along the args array, and ignores the
// return value.
variableCall = SmartBinder
.from(VARIABLE_ARITY_SIGNATURE)
.foldVoid(arityCheck)
.invoke(directCall);
| Modifier and Type | Field and Description |
|---|---|
| private final MethodHandle | handle
The MethodHandle associated with this smart handle |
| private final Signature | signature
The signature associated with this smart handle |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public SmartHandle | |
| public SmartHandle | |
| public SmartHandle | |
| public SmartHandle | |
| public SmartHandle | Returns: a new SmartHandle that accepts the given argument typesthe target MethodType from which arguments will be converted incoming)Create a new SmartHandle that casts arguments from the given type to the current signature's type, using the same argument names. |
| public SmartHandle | |
| public SmartHandle | Returns: a new SmartHandle that accepts the given argument typesthe return type of the new handle returnType, Class<?>... the argument types of the new handle argTypes)Create a new SmartHandle that casts arguments from the given return type and argument types to the current signature's type, using the same argument names. |
| public SmartHandle | Returns: a new SmartHandle that accepts the given argument typesthe target MethodType from which arguments will be converted incoming)Create a new SmartHandle that converts arguments from the given type to the current signature's type, using the same argument names. |
| public SmartHandle | Returns: a new SmartHandle that accepts the given argument typesthe return type of the new handle returnType, Class<?>... the argument types of the new handle argTypes)Create a new SmartHandle that converts arguments from the given return type and argument types to the current signature's type, using the same argument names. |
| public SmartHandle | |
| public SmartHandle | |
| public SmartHandle | |
| public SmartHandle | |
| public static SmartHandle | Returns: a new SmartHandle based on the signature and looked-up MethodHandlethe MethodHandles.Lookup object to use lookup,the class where the method is located target, String the name of the method name, Signature the signature of the method signature)Create a new SmartHandle by performing a lookup on the given target class for the given method name with the given signature. |
| public static SmartHandle | Returns: a new SmartHandlethe signature for the new smart handle signature, MethodHandle the method handle for the new smart handle handle)Create a new SmartHandle from the given Signature and MethodHandle. |
| public MethodHandle | Returns: a MethodHandle that performs the test and branchthe "true" path for this handle's test target, MethodHandle the "false" path for this handle's test fallback)Use this SmartHandle as a test to guard target and fallback handles. |
| public SmartHandle | Returns: a new SmartHandle that performs the test and branchthe "true" path for this handle's test target, SmartHandle the "false" path for this handle's test fallback)Use this SmartHandle as a test to guard target and fallback handles. |
| public MethodHandle | |
| public SmartHandle | Returns: a new SmartHandle that returns the given valuethe type for the new return value type, Object the new value to return value)Replace the return value with the given value, performing no other processing of the original value. |
| public Signature | |
| public String | Returns: a String representation of this handleOverrides java. |
| handle | back to summary |
|---|---|
| private final MethodHandle handle The MethodHandle associated with this smart handle | |
| signature | back to summary |
|---|---|
| private final Signature signature The signature associated with this smart handle | |
| SmartHandle | back to summary |
|---|---|
| pack-priv SmartHandle(Signature signature, MethodHandle handle) | |
| apply | back to summary |
|---|---|
| public SmartHandle apply(int index, Object arg) Apply an argument into the handle at the given index, returning a new SmartHandle. The new handle will use the given value for the argument at the given index, accepting one fewer argument as a result. In other words, fix that argument (partial application) into the given handle.
| |
| apply | back to summary |
|---|---|
| public SmartHandle apply(String name, Object arg) Apply an argument into the handle at the given name, returning a new SmartHandle. The new handle will use the given value for the argument at the given index, accepting one fewer argument as a result. In other words, fix that argument (partial application) into the given handle.
| |
| applyLast | back to summary |
|---|---|
| public SmartHandle applyLast(Object arg) Apply an argument into the handle at the end, returning a new SmartHandle. The new handle will use the given value for the last argument, accepting one fewer argument as a result. In other words, fix that argument (partial application) into the given handle.
| |
| bindTo | back to summary |
|---|---|
| public SmartHandle bindTo(Object obj) Bind the first argument of this SmartHandle to the given object, returning a new adapted handle.
| |
| cast | back to summary |
|---|---|
| public SmartHandle cast(MethodType incoming) Create a new SmartHandle that casts arguments from the given type to the current signature's type, using the same argument names. This casting is equivalent to MethodHandles#explicitCastArguments.
| |
| cast | back to summary |
|---|---|
| public SmartHandle cast(Signature incoming) Create a new SmartHandle that casts arguments from the given signature to the current signature's type with the new argument names. This casting is equivalent to MethodHandle#asType.
| |
| cast | back to summary |
|---|---|
| public SmartHandle cast(Class<?> returnType, Class<?>... argTypes) Create a new SmartHandle that casts arguments from the given return type and argument types to the current signature's type, using the same argument names. This casting is equivalent to MethodHandle#asType.
| |
| convert | back to summary |
|---|---|
| public SmartHandle convert(MethodType incoming) Create a new SmartHandle that converts arguments from the given type to the current signature's type, using the same argument names. This conversion is equivalent to MethodHandle#asType.
| |
| convert | back to summary |
|---|---|
| public SmartHandle convert(Class<?> returnType, Class<?>... argTypes) Create a new SmartHandle that converts arguments from the given return type and argument types to the current signature's type, using the same argument names. This conversion is equivalent to MethodHandle#asType.
| |
| convert | back to summary |
|---|---|
| public SmartHandle convert(Signature incoming) Create a new SmartHandle that converts arguments from the given signature to the current signature's type with the new argument names. This conversion is equivalent to MethodHandle#asType.
| |
| drop | back to summary |
|---|---|
| public SmartHandle drop(String beforeName, String newName, Class<?> type) Drop an argument name and type from the handle at the given index, returning a new SmartHandle.
| |
| drop | back to summary |
|---|---|
| public SmartHandle drop(int index, String newName, Class<?> type) Drop an argument from the handle at the given index, returning a new SmartHandle.
| |
| dropLast | back to summary |
|---|---|
| public SmartHandle dropLast(String newName, Class<?> type) Drop an argument from the handle at the end, returning a new SmartHandle.
| |
| findStaticQuiet | back to summary |
|---|---|
| public static SmartHandle findStaticQuiet(MethodHandles. Create a new SmartHandle by performing a lookup on the given target class for the given method name with the given signature.
| |
| from | back to summary |
|---|---|
| public static SmartHandle from(Signature signature, MethodHandle handle) Create a new SmartHandle from the given Signature and MethodHandle.
| |
| guard | back to summary |
|---|---|
| public MethodHandle guard(MethodHandle target, MethodHandle fallback) Use this SmartHandle as a test to guard target and fallback handles.
| |
| guard | back to summary |
|---|---|
| public SmartHandle guard(SmartHandle target, SmartHandle fallback) Use this SmartHandle as a test to guard target and fallback handles.
| |
| handle | back to summary |
|---|---|
| public MethodHandle handle() Get the MethodHandle of this SmartHandle.
| |
| returnValue | back to summary |
|---|---|
| public SmartHandle returnValue(Class<?> type, Object value) Replace the return value with the given value, performing no other processing of the original value.
| |
| signature | back to summary |
|---|---|
| public Signature signature() Get the Signature of this SmartHandle.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. A human-readable String representation of this SamrtHandle. | |