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(MethodHandles.Lookup lookup,
Binder source)
Construct a new Binder using the given Lookup and invokebinder.
|
Binder(MethodHandles.Lookup lookup,
MethodType start)
Construct a new Binder, starting from a given Lookup and MethodType.
|
Binder(MethodType start)
Construct a new Binder, starting from a given MethodType.
|
Modifier and Type | Method and Description |
---|---|
Binder |
append(boolean value)
Append to the argument list the given boolean value.
|
Binder |
append(byte value)
Append to the argument list the given byte value.
|
Binder |
append(char value)
Append to the argument list the given char value.
|
Binder |
append(Class[] types,
Object... values)
Append to the argument list the given argument value(s).
|
Binder |
append(double value)
Append to the argument list the given double value.
|
Binder |
append(float value)
Append to the argument list the given float value.
|
Binder |
append(int value)
Append to the argument list the given int value.
|
Binder |
append(long value)
Append to the argument list the given long value.
|
Binder |
append(Object... values)
Append to the argument list the given argument value(s).
|
Binder |
append(short value)
Append to the argument list the given short value.
|
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 |
dropLast()
Drop a single argument at the end of the argument list.
|
Binder |
dropLast(int count)
Drop from the end of the argument list 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.
|
Binder |
foldStatic(Class target,
String method)
Process the incoming arguments by calling the given static method on the
given class, inserting the result as the first argument.
|
Binder |
foldStatic(MethodHandles.Lookup lookup,
Class target,
String method)
Process the incoming arguments by calling the given static method on the
given class, inserting the result as the first argument.
|
Binder |
foldVirtual(MethodHandles.Lookup lookup,
String method)
Process the incoming arguments by calling the given method on the first
argument, inserting the result as the first argument.
|
Binder |
foldVirtual(String method)
Process the incoming arguments by calling the given method on the first
argument, inserting the result as the first argument.
|
Binder |
foldVoid(MethodHandle function) |
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(MethodHandles.Lookup lookup,
Binder start)
Construct a new Binder, starting from a given invokebinder.
|
static Binder |
from(MethodHandles.Lookup lookup,
Class returnType)
Construct a new Binder using a return type.
|
static Binder |
from(MethodHandles.Lookup lookup,
Class returnType,
Class[] argTypes)
Construct a new Binder using a return type and argument types.
|
static Binder |
from(MethodHandles.Lookup lookup,
Class returnType,
Class argType0,
Class... argTypes)
Construct a new Binder using a return type and argument types.
|
static Binder |
from(MethodHandles.Lookup lookup,
MethodType start)
Construct a new Binder, starting from a given MethodType.
|
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 |
invoker()
Produce a MethodHandle that invokes its leading MethodHandle argument
with the remaining arguments, returning the result.
|
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 |
prepend(boolean value)
Prepend to the argument list the given boolean value.
|
Binder |
prepend(byte value)
Prepend to the argument list the given byte value.
|
Binder |
prepend(char value)
Prepend to the argument list the given char value.
|
Binder |
prepend(double value)
Prepend to the argument list the given double value.
|
Binder |
prepend(float value)
Prepend to the argument list the given float value.
|
Binder |
prepend(int value)
Prepend to the argument list the given int value.
|
Binder |
prepend(long value)
Prepend to the argument list the given long value.
|
Binder |
prepend(Object... values)
Prepend to the argument list the given argument value(s).
|
Binder |
prepend(short value)
Prepend to the argument list the given short value.
|
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 array argument into the specified argument types.
|
Binder |
spread(int count)
Spread a trailing array argument into the given number of arguments of
the type of the array.
|
MethodHandle |
throwException()
Throw the current signature's sole Throwable argument.
|
Binder |
to(Binder other)
Join this binder to an existing one by applying its transformations after
this one.
|
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.
|
Binder |
withLookup(MethodHandles.Lookup lookup)
Use an alternate java.lang.invoke.MethodHandles.Lookup as the default for
any direct handles created.
|
public Binder(MethodType start)
start
- the starting MethodType, for calls entering the eventual chainpublic Binder(MethodHandles.Lookup lookup, MethodType start)
lookup
- the Lookup context to use for direct handlesstart
- the starting MethodType, for calls entering the eventual chainpublic Binder(Binder source)
public Binder(MethodHandles.Lookup lookup, Binder source)
lookup
- the Lookup context to use for direct handlessource
- the source Binderpublic Binder(Binder source, Transform transform)
source
- the source Bindertransform
- the additional Transformpublic Binder(Binder source, Transform transform, MethodType type)
source
- the source Bindertransform
- the additional Transformtype
- the new current type resulting from the transformpublic static Binder from(MethodType start)
start
- the starting MethodType, for calls entering the eventual chainpublic static Binder from(MethodHandles.Lookup lookup, MethodType start)
lookup
- the Lookup context to use for direct handlesstart
- 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(MethodHandles.Lookup lookup, Class returnType)
lookup
- the Lookup context to use for direct handlesreturnType
- 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(MethodHandles.Lookup lookup, Class returnType, Class[] argTypes)
lookup
- the Lookup context to use for direct handlesreturnType
- 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(MethodHandles.Lookup lookup, Class returnType, Class argType0, Class... argTypes)
lookup
- the Lookup context to use for direct handlesreturnType
- 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 static Binder from(MethodHandles.Lookup lookup, Binder start)
lookup
- the Lookup context to use for direct handlesstart
- the starting invokebinder; the new one will start with the current endpoint type
of the given invokebinderpublic Binder to(Binder other)
other
- the Binder containing the set of transformations to appendpublic Binder withLookup(MethodHandles.Lookup lookup)
lookup
- the new Lookup context to usepublic 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 append(boolean value)
value
- the value to appendpublic Binder append(byte value)
value
- the value to appendpublic Binder append(short value)
value
- the value to appendpublic Binder append(char value)
value
- the value to appendpublic Binder append(int value)
value
- the value to appendpublic Binder append(long value)
value
- the value to appendpublic Binder append(float value)
value
- the value to appendpublic Binder append(double value)
value
- the value to appendpublic Binder append(Object... values)
values
- the value(s) to appendpublic Binder prepend(boolean value)
value
- the value to prependpublic Binder prepend(byte value)
value
- the value to prependpublic Binder prepend(short value)
value
- the value to prependpublic Binder prepend(char value)
value
- the value to prependpublic Binder prepend(int value)
value
- the value to prependpublic Binder prepend(long value)
value
- the value to prependpublic Binder prepend(float value)
value
- the value to prependpublic Binder prepend(double value)
value
- the value to prependpublic Binder prepend(Object... values)
values
- the value(s) to prependpublic Binder append(Class[] types, Object... values)
types
- the actual types to use, rather than getClassvalues
- the value(s) to appendpublic 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 dropLast()
public Binder dropLast(int count)
count
- 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 spread(int count)
count
- the new count of arguments to spread from the trailing arraypublic 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 foldVoid(MethodHandle function)
public Binder foldStatic(MethodHandles.Lookup lookup, Class target, String method)
lookup
- the java.lang.invoke.MethodHandles.Lookup to usetarget
- the class on which the method is definedmethod
- the method to invoke on the first argumentpublic Binder foldStatic(Class target, String method)
target
- the class on which the method is definedmethod
- the method to invoke on the first argumentpublic Binder foldVirtual(MethodHandles.Lookup lookup, String method)
lookup
- the java.lang.invoke.MethodHandles.Lookup to usemethod
- the method to invoke on the first argumentpublic Binder foldVirtual(String method)
method
- the method to invoke on the first argumentpublic 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 handlepublic MethodHandle invoker()
Copyright © 2015. All rights reserved.