Package com.headius.invokebinder
Class SmartBinder
- java.lang.Object
-
- com.headius.invokebinder.SmartBinder
-
public class SmartBinder extends Object
Maintains both a Binder, for building a series of transformations, and a current Signature that maps symbolic names to arguments. Transformations normally performed with Binder using argument indices can be done instead using argument names and wildcards. TODO: Examples, or links to wiki examples.- Author:
- headius
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SmartBinder
append(String[] names, Class<?>[] types, Object... values)
Append the given arguments to the argument list, assigning them the given names.SmartBinder
append(String name, boolean value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, byte value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, char value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, double value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, float value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, int value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, long value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, short value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, Class<?> type, Object value)
Append the given argument to the argument list, assigning it the given name.SmartBinder
append(String name, Object value)
Append the given argument to the argument list, assigning it the given name.SmartHandle
arrayGet()
Terminate this binder by setting an array element based on the current signature.SmartHandle
arraySet()
Terminate this binder by getting an array element based on the current signature.Signature
baseSignature()
Get the signature this binder started with.Binder
binder()
Get the Binder instance associated with this SmartBinder.SmartBinder
cast(Signature target)
Cast the incoming arguments to the types in the given signature.SmartBinder
cast(Class<?> returnType, Class<?>... argTypes)
Cast the incoming arguments to the return and argument types given.SmartBinder
castArg(String name, Class<?> type)
Cast the named argument to the given type.SmartBinder
castReturn(Class<?> type)
Cast the return value to the given type.SmartBinder
castVirtual(Class<?> returnType, Class<?> firstArg, Class<?>... restArgs)
Cast the incoming arguments to the return, first argument type, and remaining argument types.SmartBinder
collect(String outName, String namePattern)
Collect arguments matching namePattern into an trailing array argument named outName.SmartBinder
collect(String outName, String namePattern, MethodHandle collector)
Collect arguments matching namePattern into an trailing array argument named outName, using collector to construct the array object.SmartBinder
drop(String name)
Drop the argument with the given name.SmartBinder
dropFirst()
Drop the first argument.SmartBinder
dropFirst(int count)
Drop the first N arguments.SmartBinder
dropLast()
Drop the last argument.SmartBinder
dropLast(int count)
Drop the last N arguments.SmartBinder
exclude(String... excludeNames)
Permute all parameters except the names given.SmartBinder
filter(String pattern, MethodHandle filter)
Filter the arguments matching the given pattern using the given filter function.SmartBinder
filterReturn(SmartHandle filter)
Use the given filter function to transform the return value at this point in the binder.SmartBinder
filterReturn(MethodHandle filter)
Use the given filter function to transform the return value at this point in the binder.SmartBinder
fold(String newName, SmartHandle function)
Pass all arguments to the given function and insert the resulting value as newName into the argument list.SmartBinder
fold(String newName, MethodHandle function)
Pass all arguments to the given function and insert the resulting value as newName into the argument list.SmartBinder
foldStatic(String newName, Class<?> target, String method)
Acquire a public static folding function from the given target class, using the given name.SmartBinder
foldStatic(String newName, MethodHandles.Lookup lookup, Class<?> target, String method)
Acquire a static folding function from the given target class, using the given name and Lookup.SmartBinder
foldVirtual(String newName, MethodHandles.Lookup lookup, String method)
Acquire a virtual folding function from the first argument's class, using the given name and Lookup.SmartBinder
foldVirtual(String newName, String method)
Acquire a public virtual folding function from the first argument's class, using the given name and Lookup.SmartBinder
foldVoid(SmartHandle function)
Pass all arguments to the given function and drop any result.SmartBinder
foldVoid(MethodHandle function)
Pass all arguments to the given function and drop any result.static SmartBinder
from(Signature inbound)
Create a new SmartBinder from the given Signature.static SmartBinder
from(Class<?> retType, String[] names, Class<?>... types)
Create a new SmartBinder from the given types and argument names.static SmartBinder
from(Class<?> retType, String name, Class<?> type)
Create a new SmartBinder with from the given types and argument name.static SmartBinder
from(MethodHandles.Lookup lookup, Signature inbound)
Create a new SmartBinder from the given Signature, using the given Lookup for any handle lookups.static SmartBinder
from(MethodHandles.Lookup lookup, Class<?> retType, String[] names, Class<?>... types)
Create a new SmartBinder from the given types and argument names, using the given Lookup for any handle lookups.static SmartBinder
from(MethodHandles.Lookup lookup, Class<?> retType, String name, Class<?> type)
Create a new SmartBinder from the given types and argument name, using the given Lookup for any handle lookups.SmartHandle
identity()
Terminate this binder by returning its sole remaining argument.SmartBinder
insert(int index, String[] names, Class<?>[] types, Object... values)
Insert arguments into the argument list at the given index with the given names and values.SmartBinder
insert(int index, String name, boolean value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, byte value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, char value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, double value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, float value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, int value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, long value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, short value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, Class<?> type, Object value)
Insert an argument into the argument list at the given index with the given name and value.SmartBinder
insert(int index, String name, Object value)
Insert an argument into the argument list at the given index with the given name and value.SmartHandle
invoke(SmartHandle target)
Terminate this binder by invoking the given target handle.SmartHandle
invoke(MethodHandle target)
Terminate this binder by invoking the given target handle.SmartHandle
invoker()
Produce a SmartHandle from this binder that invokes a leading MethodHandle argument with the remaining arguments.SmartHandle
invokeStatic(MethodHandles.Lookup lookup, Class<?> target, String name)
Terminate this binder by looking up the named static method on the given target type.SmartHandle
invokeStaticQuiet(MethodHandles.Lookup lookup, Class<?> target, String name)
Terminate this binder by looking up the named static method on the given target type.SmartHandle
invokeVirtual(MethodHandles.Lookup lookup, String name)
Terminate this binder by looking up the named virtual method on the first argument's type.SmartHandle
invokeVirtualQuiet(MethodHandles.Lookup lookup, String name)
Terminate this binder by looking up the named virtual method on the first argument's type.SmartBinder
permute(Signature target)
Using the argument names and order in the target Signature, permute the arguments in this SmartBinder.SmartBinder
permute(String... targetNames)
Using the argument names and order in the given targetNames, permute the arguments in this SmartBinder.SmartBinder
prepend(String[] names, Class<?>[] types, Object... values)
Prepend the given arguments to the argument list, assigning them the given name.SmartBinder
prepend(String name, boolean value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, byte value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, char value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, double value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, float value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, int value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, long value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, short value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, Class<?> type, Object value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
prepend(String name, Object value)
Prepend the given argument to the argument list, assigning it the given name.SmartBinder
printSignature()
Print this binder's current signature to System.out.SmartBinder
printSignature(PrintStream ps)
Print this binder's current signature to the give PrintStream.Signature
signature()
Get the current Signature for this binder.SmartBinder
spread(String[] spreadNames, Class<?>... spreadTypes)
Spread a trailing array into the specified argument types.SmartBinder
spread(String baseName, int count)
Spread a trailing array into count number of arguments, using the natural component type for the array.SmartBinder
tryFinally(MethodHandle post)
-
-
-
Method Detail
-
signature
public Signature signature()
Get the current Signature for this binder.- Returns:
- this binder's current Signature
-
baseSignature
public Signature baseSignature()
Get the signature this binder started with.- Returns:
- the signature this binder started with.
-
binder
public Binder binder()
Get the Binder instance associated with this SmartBinder.- Returns:
- this SmartBinder's Binder instance
-
from
public static SmartBinder from(Signature inbound)
Create a new SmartBinder from the given Signature.- Parameters:
inbound
- the Signature to start from- Returns:
- a new SmartBinder
-
from
public static SmartBinder from(Class<?> retType, String[] names, Class<?>... types)
Create a new SmartBinder from the given types and argument names.- Parameters:
retType
- the type of the return value to start withnames
- the names of argumentstypes
- the argument types- Returns:
- a new SmartBinder
-
from
public static SmartBinder from(Class<?> retType, String name, Class<?> type)
Create a new SmartBinder with from the given types and argument name.- Parameters:
retType
- the type of the return value to start withname
- the name of the sole argumenttype
- the sole argument's type- Returns:
- a new SmartBinder
-
from
public static SmartBinder from(MethodHandles.Lookup lookup, Signature inbound)
Create a new SmartBinder from the given Signature, using the given Lookup for any handle lookups.- Parameters:
lookup
- the Lookup to use for handle lookupsinbound
- the Signature to start from- Returns:
- a new SmartBinder
-
from
public static SmartBinder from(MethodHandles.Lookup lookup, Class<?> retType, String[] names, Class<?>... types)
Create a new SmartBinder from the given types and argument names, using the given Lookup for any handle lookups.- Parameters:
lookup
- the Lookup to use for handle lookupsretType
- the type of the return value to start withnames
- the names of argumentstypes
- the argument types- Returns:
- a new SmartBinder
-
from
public static SmartBinder from(MethodHandles.Lookup lookup, Class<?> retType, String name, Class<?> type)
Create a new SmartBinder from the given types and argument name, using the given Lookup for any handle lookups.- Parameters:
lookup
- the Lookup to use for handle lookupsretType
- the type of the return value to start withname
- the name of the sole argumentstype
- the sole argument's type- Returns:
- a new SmartBinder
-
fold
public SmartBinder fold(String newName, MethodHandle function)
Pass all arguments to the given function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedfunction
- a function which will receive all arguments and have its return value inserted into the call chain- Returns:
- a new SmartBinder with the fold applied
-
fold
public SmartBinder fold(String newName, SmartHandle function)
Pass all arguments to the given function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedfunction
- a function which will receive all arguments and have its return value inserted into the call chain- Returns:
- a new SmartBinder with the fold applied
-
foldVoid
public SmartBinder foldVoid(MethodHandle function)
Pass all arguments to the given function and drop any result.- Parameters:
function
- a function which will receive all arguments and have its return value inserted into the call chain- Returns:
- a new SmartBinder with the fold applied
-
foldVoid
public SmartBinder foldVoid(SmartHandle function)
Pass all arguments to the given function and drop any result.- Parameters:
function
- a function which will receive all arguments and have its return value inserted into the call chain- Returns:
- a new SmartBinder with the fold applied
-
foldStatic
public SmartBinder foldStatic(String newName, MethodHandles.Lookup lookup, Class<?> target, String method)
Acquire a static folding function from the given target class, using the given name and Lookup. Pass all arguments to that function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedlookup
- the Lookup to use for acquiring a folding functiontarget
- the class on which to find the folding functionmethod
- the name of the method to become a folding function- Returns:
- a new SmartBinder with the fold applied
-
foldStatic
public SmartBinder foldStatic(String newName, Class<?> target, String method)
Acquire a public static folding function from the given target class, using the given name. Pass all arguments to that function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedtarget
- the class on which to find the folding functionmethod
- the name of the method to become a folding function- Returns:
- a new SmartBinder with the fold applied
-
foldVirtual
public SmartBinder foldVirtual(String newName, MethodHandles.Lookup lookup, String method)
Acquire a virtual folding function from the first argument's class, using the given name and Lookup. Pass all arguments to that function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedlookup
- the Lookup to use for acquiring a folding functionmethod
- the name of the method to become a folding function- Returns:
- a new SmartBinder with the fold applied
-
foldVirtual
public SmartBinder foldVirtual(String newName, String method)
Acquire a public virtual folding function from the first argument's class, using the given name and Lookup. Pass all arguments to that function and insert the resulting value as newName into the argument list.- Parameters:
newName
- the name of the new first argument where the fold function's result will be passedmethod
- the name of the method to become a folding function- Returns:
- a new SmartBinder with the fold applied
-
permute
public SmartBinder permute(Signature target)
Using the argument names and order in the target Signature, permute the arguments in this SmartBinder. Arguments may be duplicated or omitted in the target Signature, but all arguments in the target must be defined in this SmartBinder .- Parameters:
target
- the Signature from which to derive a new argument list- Returns:
- a new SmartBinder with the permute applied
-
permute
public SmartBinder permute(String... targetNames)
Using the argument names and order in the given targetNames, permute the arguments in this SmartBinder. Arguments may be duplicated or omitted in the targetNames array, but all arguments in the target must be defined in this SmartBinder.- Parameters:
targetNames
- the array of names from which to derive a new argument list- Returns:
- a new SmartBinder with the permute applied
-
exclude
public SmartBinder exclude(String... excludeNames)
Permute all parameters except the names given. Blacklisting to #permute's whitelisting.- Parameters:
excludeNames
- parameter patterns to exclude- Returns:
- a new SmartBinder with the exclude applied
-
spread
public SmartBinder spread(String[] spreadNames, Class<?>... spreadTypes)
Spread a trailing array into the specified argument types.- Parameters:
spreadNames
- the names for the spread out argumentsspreadTypes
- the types as which to spread the incoming array- Returns:
- a new SmartBinder with the spread applied
-
spread
public SmartBinder spread(String baseName, int count)
Spread a trailing array into count number of arguments, using the natural component type for the array. Build names for the arguments using the given baseName plus the argument's index. Example: Current binder has a signature of (int, String[])void. We want to spread the strings into five arguments named "str".binder = binder.spread("str", 5)
The resulting signature will have five trailing arguments named "arg0" through "arg4".- Parameters:
baseName
- the base name from which to create the new argument namescount
- the count of arguments to spread- Returns:
- a new SmartBinder with the spread applied
-
insert
public SmartBinder insert(int index, String name, Object value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, boolean value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, byte value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, short value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, char value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, int value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, long value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, float value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, double value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String name, Class<?> type, Object value)
Insert an argument into the argument list at the given index with the given name and value.- Parameters:
index
- the index at which to insert the argumentname
- the name of the new argumenttype
- the type to use in the new signaturevalue
- the value of the new argument- Returns:
- a new SmartBinder with the insert applied
-
insert
public SmartBinder insert(int index, String[] names, Class<?>[] types, Object... values)
Insert arguments into the argument list at the given index with the given names and values.- Parameters:
index
- the index at which to insert the argumentsnames
- the names of the new argumentstypes
- the types of the new argumentsvalues
- the values of the new arguments- Returns:
- a new SmartBinder with the insert applied
-
append
public SmartBinder append(String name, Object value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, boolean value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, byte value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, short value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, char value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, int value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, long value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, float value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, double value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String name, Class<?> type, Object value)
Append the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumenttype
- the type to use in the new signaturevalue
- the value of the new argument- Returns:
- a new SmartBinder with the append applied
-
append
public SmartBinder append(String[] names, Class<?>[] types, Object... values)
Append the given arguments to the argument list, assigning them the given names.- Parameters:
names
- the names of the new argumentstypes
- the types to use in the new signaturevalues
- the values of the new arguments- Returns:
- a new SmartBinder with the append applied
-
prepend
public SmartBinder prepend(String name, Object value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, boolean value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, byte value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, short value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, char value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, int value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, long value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, float value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, double value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumentvalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String name, Class<?> type, Object value)
Prepend the given argument to the argument list, assigning it the given name.- Parameters:
name
- the name of the new argumenttype
- the type to use in the new signaturevalue
- the value of the new argument- Returns:
- a new SmartBinder with the prepend applied
-
prepend
public SmartBinder prepend(String[] names, Class<?>[] types, Object... values)
Prepend the given arguments to the argument list, assigning them the given name.- Parameters:
names
- the names of the new argumentstypes
- the types to use in the new signaturevalues
- the values of the new arguments- Returns:
- a new SmartBinder with the prepend applied
-
drop
public SmartBinder drop(String name)
Drop the argument with the given name.- Parameters:
name
- the name of the argument to drop- Returns:
- a new SmartBinder with the drop applied
-
dropLast
public SmartBinder dropLast()
Drop the last argument.- Returns:
- a new SmartBinder with the drop applied
-
dropLast
public SmartBinder dropLast(int count)
Drop the last N arguments.- Parameters:
count
- the count of arguments to drop- Returns:
- a new SmartBinder with the drop applied
-
dropFirst
public SmartBinder dropFirst()
Drop the first argument.- Returns:
- a new SmartBinder with the drop applied
-
dropFirst
public SmartBinder dropFirst(int count)
Drop the first N arguments.- Parameters:
count
- the count of arguments to drop- Returns:
- a new SmartBinder with the drop applied
-
collect
public SmartBinder collect(String outName, String namePattern)
Collect arguments matching namePattern into an trailing array argument named outName. The namePattern is a standard regular expression.- Parameters:
outName
- the name of the new array argumentnamePattern
- a pattern with which to match arguments for collecting- Returns:
- a new SmartBinder with the collect applied
-
collect
public SmartBinder collect(String outName, String namePattern, MethodHandle collector)
Collect arguments matching namePattern into an trailing array argument named outName, using collector to construct the array object. The collector signature should match (T1, ..., Tn) where T is the type of the arguments being collected and n is the number of arguments being collected. The namePattern is a standard regular expression.- Parameters:
outName
- the name of the new array argumentnamePattern
- a pattern with which to match arguments for collectingcollector
- a function to use for collecting the arguments- Returns:
- a new SmartBinder with the collect applied
-
cast
public SmartBinder cast(Signature target)
Cast the incoming arguments to the types in the given signature. The argument count must match, but the names in the target signature are ignored.- Parameters:
target
- the Signature to which arguments should be cast- Returns:
- a new SmartBinder with the cast applied
-
cast
public SmartBinder cast(Class<?> returnType, Class<?>... argTypes)
Cast the incoming arguments to the return and argument types given. The argument count must match.- Parameters:
returnType
- the return type for the casted signatureargTypes
- the types of the arguments for the casted signature- Returns:
- a new SmartBinder with the cast applied
-
castVirtual
public SmartBinder castVirtual(Class<?> returnType, Class<?> firstArg, Class<?>... restArgs)
Cast the incoming arguments to the return, first argument type, and remaining argument types. Provide for convenience when dealing with virtual method argument lists, which frequently omit the target object.- Parameters:
returnType
- the return type for the casted signaturefirstArg
- the type of the first argument for the casted signaturerestArgs
- the types of the remaining arguments for the casted signature- Returns:
- a new SmartBinder with the cast applied.
-
castArg
public SmartBinder castArg(String name, Class<?> type)
Cast the named argument to the given type.- Parameters:
name
- the name of the argument to casttype
- the type to which that argument will be cast- Returns:
- a new SmartBinder with the cast applied
-
castReturn
public SmartBinder castReturn(Class<?> type)
Cast the return value to the given type. Example: Our current signature is (String)String but the method this handle will eventually call returns CharSequence.binder = binder.castReturn(CharSequence.class);
Our handle will now successfully find and call the target method and propagate the returned CharSequence as a String.- Parameters:
type
- the new type for the return value- Returns:
- a new SmartBinder
-
filterReturn
public SmartBinder filterReturn(MethodHandle filter)
Use the given filter function to transform the return value at this point in the binder. The filter will be inserted into the handle, and return values will pass through it before continuing. The filter's argument must match the expected return value downstream from this point in the binder, and the return value must match the return value at this point in the binder.- Parameters:
filter
- the function to use to transform the return value at this point- Returns:
- a new SmartBinder with the filter applied
-
filterReturn
public SmartBinder filterReturn(SmartHandle filter)
Use the given filter function to transform the return value at this point in the binder. The filter will be inserted into the handle, and return values will pass through it before continuing. The filter's argument must match the expected return value downstream from this point in the binder, and the return value must match the return value at this point in the binder.- Parameters:
filter
- the function to use to transform the return value at this point- Returns:
- a new SmartBinder with the filter applied
-
invokeVirtual
public SmartHandle invokeVirtual(MethodHandles.Lookup lookup, String name) throws NoSuchMethodException, IllegalAccessException
Terminate this binder by looking up the named virtual method on the first argument's type. Perform the actual method lookup using the given Lookup object.- Parameters:
lookup
- the Lookup to use for handle lookupsname
- the name of the target virtual method- Returns:
- a SmartHandle with this binder's starting signature, bound to the target method
- Throws:
NoSuchMethodException
- if the named method with current signature's types does not existIllegalAccessException
- if the named method is not accessible to the given Lookup
-
invokeVirtualQuiet
public SmartHandle invokeVirtualQuiet(MethodHandles.Lookup lookup, String name)
Terminate this binder by looking up the named virtual method on the first argument's type. Perform the actual method lookup using the given Lookup object. If the lookup fails, a RuntimeException will be raised, containing the actual reason. This method is for convenience in (for example) field declarations, where checked exceptions noise up code that can't recover anyway. Use this in situations where you would not expect your library to be usable if the target method can't be acquired.- Parameters:
lookup
- the Lookup to use for handle lookupsname
- the name of the target virtual method- Returns:
- a SmartHandle with this binder's starting signature, bound to the target method
-
invokeStatic
public SmartHandle invokeStatic(MethodHandles.Lookup lookup, Class<?> target, String name) throws NoSuchMethodException, IllegalAccessException
Terminate this binder by looking up the named static method on the given target type. Perform the actual method lookup using the given Lookup object.- Parameters:
lookup
- the Lookup to use for handle lookupstarget
- the type on which to find the static methodname
- the name of the target static method- Returns:
- a SmartHandle with this binder's starting signature, bound to the target method
- Throws:
NoSuchMethodException
- if the named method with current signature's types does not existIllegalAccessException
- if the named method is not accessible to the given Lookup
-
invokeStaticQuiet
public SmartHandle invokeStaticQuiet(MethodHandles.Lookup lookup, Class<?> target, String name)
Terminate this binder by looking up the named static method on the given target type. Perform the actual method lookup using the given Lookup object. If the lookup fails, a RuntimeException will be raised, containing the actual reason. This method is for convenience in (for example) field declarations, where checked exceptions noise up code that can't recover anyway. Use this in situations where you would not expect your library to be usable if the target method can't be acquired.- Parameters:
lookup
- the Lookup to use for handle lookupstarget
- the type on which to find the static methodname
- the name of the target static method- Returns:
- a SmartHandle with this binder's starting signature, bound to the target method
-
invoke
public SmartHandle invoke(SmartHandle target)
Terminate this binder by invoking the given target handle. The signature of this binder is not compared to the signature of the given SmartHandle.- Parameters:
target
- the handle to invoke- Returns:
- a new SmartHandle with this binder's starting signature, bound through to the given handle
-
invoke
public SmartHandle invoke(MethodHandle target)
Terminate this binder by invoking the given target handle.- Parameters:
target
- the handle to invoke- Returns:
- a new SmartHandle with this binder's starting signature, bound through to the given handle
-
arrayGet
public SmartHandle arrayGet()
Terminate this binder by setting an array element based on the current signature. The signature should have the array as its first argument, an integer index as its second, and an appropriately-typed value as its third. It should have a void return value. Invoking the resulting handle will (eventually) perform the array assignment.- Returns:
- a new SmartHandle with this binder's starting signature, bound to an array assignment operation
-
arraySet
public SmartHandle arraySet()
Terminate this binder by getting an array element based on the current signature. The signature should have the array as its first argument and an integer index as its second, and an appropriately-typed return value. Invoking the resulting handle will (eventually) perform the array assignment.- Returns:
- a new SmartHandle with this binder's starting signature, bound to an array dereference operation
-
identity
public SmartHandle identity()
Terminate this binder by returning its sole remaining argument. The signature must take only one argument whose type matches the return type. Invoking the resulting handle will (eventually) return the argument passed in at this point.- Returns:
- a new SmartHandle with this binder's starting signature that simply returns its sole received argument
-
printSignature
public SmartBinder printSignature()
Print this binder's current signature to System.out.- Returns:
- this SmartBinder
-
printSignature
public SmartBinder printSignature(PrintStream ps)
Print this binder's current signature to the give PrintStream.- Returns:
- this SmartBinder
-
invoker
public SmartHandle invoker()
Produce a SmartHandle from this binder that invokes a leading MethodHandle argument with the remaining arguments.- Returns:
- a SmartHandle that invokes its leading MethodHandle argument
-
filter
public SmartBinder filter(String pattern, MethodHandle filter)
Filter the arguments matching the given pattern using the given filter function.- Parameters:
pattern
- the regular expression pattern to match argumentsfilter
- the MethodHandle to use to filter the arguments- Returns:
- a new SmartBinder with the filter applied
-
tryFinally
public SmartBinder tryFinally(MethodHandle post)
- See Also:
Binder.tryFinally(MethodHandle)
-
-