public class Binder extends Object
MethodHandle mh = Binder .from(String.class, String.class, String.class) // String w(String, String) .drop(1, String.class) // String x(String) .insert(0, 'hello') // String y(String, String) .cast(String.class, CharSequence.class, Object.class) // String z(CharSequence, Object)String .invoke(someTargetHandle);
Constructor and Description |
---|
Binder(Binder source)
Construct a new Binder using the given invokebinder.
|
Binder(Binder source,
Transform transform)
Construct a new Binder using the given invokebinder plus an additional transform
|
Binder(Binder source,
Transform transform,
MethodType type)
Construct a new Binder using the given invokebinder plus an additional transform and current type
|
Binder(MethodType start)
Construct a new Binder, starting from a given MethodType.
|
Modifier and Type | Method and Description |
---|---|
MethodHandle |
arrayGet()
Apply the chain of transforms and bind them to an array element get.
|
MethodHandle |
arraySet()
Apply the chain of transforms and bind them to an array element set.
|
MethodHandle |
branch(MethodHandle test,
MethodHandle truePath,
MethodHandle falsePath)
Apply the chain of transforms and bind them to a boolean branch as from
java.lang.invoke.MethodHandles.guardWithTest.
|
Binder |
cast(Class returnType,
Class... argTypes)
Cast the incoming arguments to the given MethodType.
|
Binder |
cast(MethodType type)
Cast the incoming arguments to the given MethodType.
|
Binder |
catchException(Class<? extends Throwable> throwable,
MethodHandle function)
Catch the given exception type from the downstream chain and handle it with the
given function.
|
Binder |
collect(int index,
Class type)
Box all incoming arguments from the given position onward into the given array type.
|
MethodHandle |
constant(Object value)
Apply the tranforms, binding them to a constant value that will
propagate back through the chain.
|
Binder |
convert(Class returnType,
Class... argTypes)
Convert the incoming arguments to the given MethodType.
|
Binder |
convert(MethodType target)
Convert the incoming arguments to the given MethodType.
|
Binder |
drop(int index)
Drop a single argument at the given index.
|
Binder |
drop(int index,
int count)
Drop from the given index a number of arguments.
|
Binder |
filter(int index,
MethodHandle... functions)
Filter incoming arguments, starting at the given index, replacing each with the
result of calling the associated function in the given list.
|
Binder |
filterReturn(MethodHandle function)
Filter return value, using a function that produces the current return type
from another type.
|
Binder |
fold(MethodHandle function)
Process the incoming arguments using the given handle, inserting the result
as the first argument.
|
static Binder |
from(Binder start)
Construct a new Binder, starting from a given invokebinder.
|
static Binder |
from(Class returnType)
Construct a new Binder using a return type.
|
static Binder |
from(Class returnType,
Class[] argTypes)
Construct a new Binder using a return type and argument types.
|
static Binder |
from(Class returnType,
Class argType0,
Class... argTypes)
Construct a new Binder using a return type and argument types.
|
static Binder |
from(MethodType start)
Construct a new Binder, starting from a given MethodType.
|
MethodHandle |
getField(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to an object field retrieval specified
using the end signature plus the given class and name.
|
MethodHandle |
getFieldQuiet(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to an object field retrieval specified
using the end signature plus the given class and name.
|
MethodHandle |
getStatic(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to a static field retrieval specified
using the end signature plus the given class and name.
|
MethodHandle |
getStaticQuiet(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to a static field retrieval specified
using the end signature plus the given class and name.
|
MethodHandle |
identity()
Apply the tranforms, binding them to a handle that will simply return its sole
argument as its return value.
|
Binder |
insert(int index,
boolean value)
Insert at the given index the given boolean value.
|
Binder |
insert(int index,
byte value)
Insert at the given index the given byte value.
|
Binder |
insert(int index,
char value)
Insert at the given index the given char value.
|
Binder |
insert(int index,
Class[] types,
Object... values)
Insert at the given index the given argument value(s).
|
Binder |
insert(int index,
double value)
Insert at the given index the given double value.
|
Binder |
insert(int index,
float value)
Insert at the given index the given float value.
|
Binder |
insert(int index,
int value)
Insert at the given index the given int value.
|
Binder |
insert(int index,
long value)
Insert at the given index the given long value.
|
Binder |
insert(int index,
Object... values)
Insert at the given index the given argument value(s).
|
Binder |
insert(int index,
short value)
Insert at the given index the given short value.
|
MethodHandle |
invoke(MethodHandle target)
Apply the chain of transforms with the target method handle as the final
endpoint.
|
MethodHandle |
invoke(MethodHandles.Lookup lookup,
Method method)
Apply the chain of transforms and bind them to a static method specified
using the end signature plus the given class and method.
|
MethodHandle |
invokeConstructor(MethodHandles.Lookup lookup,
Class target)
Apply the chain of transforms and bind them to a constructor specified
using the end signature plus the given class.
|
MethodHandle |
invokeConstructorQuiet(MethodHandles.Lookup lookup,
Class target)
Apply the chain of transforms and bind them to a constructor specified
using the end signature plus the given class.
|
MethodHandle |
invokeQuiet(MethodHandles.Lookup lookup,
Method method)
Apply the chain of transforms and bind them to a static method specified
using the end signature plus the given class and method.
|
MethodHandle |
invokeSpecial(MethodHandles.Lookup lookup,
String name,
Class caller)
Apply the chain of transforms and bind them to a special method specified
using the end signature plus the given class and name.
|
MethodHandle |
invokeSpecialQuiet(MethodHandles.Lookup lookup,
String name,
Class caller)
Apply the chain of transforms and bind them to a special method specified
using the end signature plus the given class and name.
|
MethodHandle |
invokeStatic(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to a static method specified
using the end signature plus the given class and name.
|
MethodHandle |
invokeStaticQuiet(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to a static method specified
using the end signature plus the given class and name.
|
MethodHandle |
invokeVirtual(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to a virtual method specified
using the end signature plus the given class and name.
|
MethodHandle |
invokeVirtualQuiet(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to a virtual method specified
using the end signature plus the given class and name.
|
Binder |
logType()
Log the current MethodType as info.
|
MethodHandle |
nop()
Apply all transforms to an endpoint that does absolutely nothing.
|
Binder |
permute(int... reorder)
Permute the incoming arguments to a new sequence specified by the given values.
|
Binder |
printType()
Println the current MethodType to stdout.
|
Binder |
printType(PrintStream ps)
Println the current MethodType to the given stream.
|
MethodHandle |
setField(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to an object field assignment specified
using the end signature plus the given class and name.
|
MethodHandle |
setFieldQuiet(MethodHandles.Lookup lookup,
String name)
Apply the chain of transforms and bind them to an object field assignment specified
using the end signature plus the given class and name.
|
MethodHandle |
setStatic(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to an object field assignment specified
using the end signature plus the given class and name.
|
MethodHandle |
setStaticQuiet(MethodHandles.Lookup lookup,
Class target,
String name)
Apply the chain of transforms and bind them to an object field assignment specified
using the end signature plus the given class and name.
|
Binder |
spread(Class... spreadTypes)
Spread a trailing Object[] into the specified argument types.
|
MethodHandle |
throwException()
Throw the current signature's sole Throwable argument.
|
Binder |
tryFinally(MethodHandle post)
Apply transforms to run the given handle's logic as a "finally" block.
|
MethodType |
type()
The current MethodType, were the handle chain to terminate at this point.
|
Binder |
varargs(int index,
Class type)
Box all incoming arguments from the given position onward into the given array type.
|
public Binder(MethodType start)
start
- the starting MethodType, for calls entering the eventual chainpublic Binder(Binder source)
public Binder(Binder source, Transform transform)
public Binder(Binder source, Transform transform, MethodType type)
public static Binder from(MethodType start)
start
- the starting MethodType, for calls entering the eventual chainpublic static Binder from(Class returnType)
returnType
- the return type of the incoming signaturepublic static Binder from(Class returnType, Class[] argTypes)
returnType
- the return type of the incoming signatureargTypes
- the argument types of the incoming signaturepublic static Binder from(Class returnType, Class argType0, Class... argTypes)
returnType
- the return type of the incoming signatureargType0
- the first argument type of the incoming signatureargTypes
- the remaining argument types of the incoming signaturepublic static Binder from(Binder start)
start
- the starting invokebinder; the new one will start with the current endpoint type
of the given invokebinderpublic MethodType type()
public Binder printType(PrintStream ps)
public Binder printType()
public Binder logType()
public Binder insert(int index, boolean value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, byte value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, short value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, char value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, int value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, long value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, float value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, double value)
index
- the index at which to insert the argument valuevalue
- the value to insertpublic Binder insert(int index, Object... values)
index
- the index at which to insert the argument valuevalues
- the value(s) to insertpublic Binder insert(int index, Class[] types, Object... values)
index
- the index at which to insert the argument valuetypes
- the actual types to use, rather than getClassvalues
- the value(s) to insertpublic Binder drop(int index)
index
- the index at which to drop an argumentpublic Binder drop(int index, int count)
index
- the index at which to start droppingcount
- the number of arguments to droppublic Binder convert(MethodType target)
target
- the target MethodTypepublic Binder convert(Class returnType, Class... argTypes)
returnType
- the target return typeargTypes
- the target argument typespublic Binder cast(MethodType type)
type
- the target MethodTypepublic Binder cast(Class returnType, Class... argTypes)
returnType
- the target return typeargTypes
- the target argument typespublic Binder spread(Class... spreadTypes)
spreadTypes
- the types into which to spread the incoming Object[]public Binder collect(int index, Class type)
index
- the index from which to start boxing argstype
- the array type into which the args will be boxedpublic Binder varargs(int index, Class type)
index
- the index from which to start boxing argstype
- the array type into which the args will be boxedpublic Binder permute(int... reorder)
reorder
- the int offsets of the incoming arguments in the desired permutationpublic Binder fold(MethodHandle function)
function
- the function that will process the incoming arguments. Its
signature must match the current signature's arguments exactly.public Binder filter(int index, MethodHandle... functions)
index
- the index of the first argument to filterfunctions
- the array of functions to transform the argumentspublic Binder filterReturn(MethodHandle function)
function
- the array of functions to transform the argumentspublic Binder tryFinally(MethodHandle post)
post
- the logic that would live inside the "finally" blockpublic Binder catchException(Class<? extends Throwable> throwable, MethodHandle function)
throwable
- the exception type to catchfunction
- the function to use for handling the exceptionpublic MethodHandle nop()
public MethodHandle throwException()
public MethodHandle constant(Object value)
value
- the constant value to put at the end of the chainpublic MethodHandle identity()
public MethodHandle invoke(MethodHandle target)
target
- the endpoint handle to bind topublic MethodHandle invoke(MethodHandles.Lookup lookup, Method method) throws IllegalAccessException
lookup
- the MethodHandles.Lookup to use to unreflect the methodmethod
- the Method to unreflectIllegalAccessException
public MethodHandle invokeQuiet(MethodHandles.Lookup lookup, Method method)
lookup
- the MethodHandles.Lookup to use to unreflect the methodmethod
- the Method to unreflectpublic MethodHandle invokeStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchMethodException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to unreflect the methodtarget
- the class in which to find the methodname
- the name of the method to invokeNoSuchMethodException
IllegalAccessException
public MethodHandle invokeStaticQuiet(MethodHandles.Lookup lookup, Class target, String name)
lookup
- the MethodHandles.Lookup to use to look up the methodtarget
- the class in which to find the methodname
- the name of the method to invokepublic MethodHandle invokeVirtual(MethodHandles.Lookup lookup, String name) throws NoSuchMethodException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the methodname
- the name of the method to invokeNoSuchMethodException
IllegalAccessException
public MethodHandle invokeVirtualQuiet(MethodHandles.Lookup lookup, String name)
lookup
- the MethodHandles.Lookup to use to look up the methodname
- the name of the method to invokepublic MethodHandle invokeSpecial(MethodHandles.Lookup lookup, String name, Class caller) throws NoSuchMethodException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the methodname
- the name of the method to invokecaller
- the calling classNoSuchMethodException
IllegalAccessException
public MethodHandle invokeSpecialQuiet(MethodHandles.Lookup lookup, String name, Class caller)
lookup
- the MethodHandles.Lookup to use to look up the methodname
- the name of the method to invokecaller
- the calling classpublic MethodHandle invokeConstructor(MethodHandles.Lookup lookup, Class target) throws NoSuchMethodException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the constructortarget
- the constructor's classNoSuchMethodException
IllegalAccessException
public MethodHandle invokeConstructorQuiet(MethodHandles.Lookup lookup, Class target)
lookup
- the MethodHandles.Lookup to use to look up the constructortarget
- the constructor's classpublic MethodHandle getField(MethodHandles.Lookup lookup, String name) throws NoSuchFieldException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the fieldname
- the field's nameNoSuchFieldException
IllegalAccessException
public MethodHandle getFieldQuiet(MethodHandles.Lookup lookup, String name)
lookup
- the MethodHandles.Lookup to use to look up the fieldname
- the field's namepublic MethodHandle getStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the fieldtarget
- the class in which the field is definedname
- the field's nameNoSuchFieldException
IllegalAccessException
public MethodHandle getStaticQuiet(MethodHandles.Lookup lookup, Class target, String name)
lookup
- the MethodHandles.Lookup to use to look up the fieldtarget
- the class in which the field is definedname
- the field's namepublic MethodHandle setField(MethodHandles.Lookup lookup, String name) throws NoSuchFieldException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the fieldname
- the field's nameNoSuchFieldException
IllegalAccessException
public MethodHandle setFieldQuiet(MethodHandles.Lookup lookup, String name)
lookup
- the MethodHandles.Lookup to use to look up the fieldname
- the field's namepublic MethodHandle setStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException
lookup
- the MethodHandles.Lookup to use to look up the fieldtarget
- the class in which the field is definedname
- the field's nameNoSuchFieldException
IllegalAccessException
public MethodHandle setStaticQuiet(MethodHandles.Lookup lookup, Class target, String name)
lookup
- the MethodHandles.Lookup to use to look up the fieldtarget
- the class in which the field is definedname
- the field's namepublic MethodHandle arraySet()
public MethodHandle arrayGet()
public MethodHandle branch(MethodHandle test, MethodHandle truePath, MethodHandle falsePath)
test
- the test handletruePath
- the target handlefalsePath
- the fallback handleCopyright © 2018. All rights reserved.