Class SmartBinder


  • public class SmartBinder
    extends java.lang.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​(java.lang.String[] names, java.lang.Class<?>[] types, java.lang.Object... values)
      Append the given arguments to the argument list, assigning them the given names.
      SmartBinder append​(java.lang.String name, boolean value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, byte value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, char value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, double value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, float value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, int value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, long value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, short value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)
      Append the given argument to the argument list, assigning it the given name.
      SmartBinder append​(java.lang.String name, java.lang.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​(java.lang.Class<?> returnType, java.lang.Class<?>... argTypes)
      Cast the incoming arguments to the return and argument types given.
      SmartBinder castArg​(java.lang.String name, java.lang.Class<?> type)
      Cast the named argument to the given type.
      SmartBinder castReturn​(java.lang.Class<?> type)
      Cast the return value to the given type.
      SmartBinder castVirtual​(java.lang.Class<?> returnType, java.lang.Class<?> firstArg, java.lang.Class<?>... restArgs)
      Cast the incoming arguments to the return, first argument type, and remaining argument types.
      SmartBinder collect​(java.lang.String outName, java.lang.String namePattern)
      Collect arguments matching namePattern into an trailing array argument named outName.
      SmartBinder drop​(java.lang.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​(java.lang.String... excludeNames)
      Permute all parameters except the names given.
      SmartBinder filter​(java.lang.String pattern, java.lang.invoke.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​(java.lang.invoke.MethodHandle filter)
      Use the given filter function to transform the return value at this point in the binder.
      SmartBinder fold​(java.lang.String newName, SmartHandle function)
      Pass all arguments to the given function and insert the resulting value as newName into the argument list.
      SmartBinder fold​(java.lang.String newName, java.lang.invoke.MethodHandle function)
      Pass all arguments to the given function and insert the resulting value as newName into the argument list.
      SmartBinder foldStatic​(java.lang.String newName, java.lang.Class<?> target, java.lang.String method)
      Acquire a public static folding function from the given target class, using the given name.
      SmartBinder foldStatic​(java.lang.String newName, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> target, java.lang.String method)
      Acquire a static folding function from the given target class, using the given name and Lookup.
      SmartBinder foldVirtual​(java.lang.String newName, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.String method)
      Acquire a virtual folding function from the first argument's class, using the given name and Lookup.
      SmartBinder foldVirtual​(java.lang.String newName, java.lang.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​(java.lang.invoke.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​(java.lang.Class<?> retType, java.lang.String[] names, java.lang.Class<?>... types)
      Create a new SmartBinder from the given types and argument names.
      static SmartBinder from​(java.lang.Class<?> retType, java.lang.String name, java.lang.Class<?> type)
      Create a new SmartBinder with from the given types and argument name.
      static SmartBinder from​(java.lang.invoke.MethodHandles.Lookup lookup, Signature inbound)
      Create a new SmartBinder from the given Signature, using the given Lookup for any handle lookups.
      static SmartBinder from​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> retType, java.lang.String[] names, java.lang.Class<?>... types)
      Create a new SmartBinder from the given types and argument names, using the given Lookup for any handle lookups.
      static SmartBinder from​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> retType, java.lang.String name, java.lang.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, java.lang.String[] names, java.lang.Class<?>[] types, java.lang.Object... values)
      Insert arguments into the argument list at the given index with the given names and values.
      SmartBinder insert​(int index, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.String name, java.lang.Class<?> type, java.lang.Object value)
      Insert an argument into the argument list at the given index with the given name and value.
      SmartBinder insert​(int index, java.lang.String name, java.lang.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​(java.lang.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​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> target, java.lang.String name)
      Terminate this binder by looking up the named static method on the given target type.
      SmartHandle invokeStaticQuiet​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> target, java.lang.String name)
      Terminate this binder by looking up the named static method on the given target type.
      SmartHandle invokeVirtual​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.String name)
      Terminate this binder by looking up the named virtual method on the first argument's type.
      SmartHandle invokeVirtualQuiet​(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.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​(java.lang.String... targetNames)
      Using the argument names and order in the given targetNames, permute the arguments in this SmartBinder.
      SmartBinder prepend​(java.lang.String[] names, java.lang.Class<?>[] types, java.lang.Object... values)
      Prepend the given arguments to the argument list, assigning them the given name.
      SmartBinder prepend​(java.lang.String name, boolean value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, byte value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, char value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, double value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, float value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, int value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, long value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, short value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)
      Prepend the given argument to the argument list, assigning it the given name.
      SmartBinder prepend​(java.lang.String name, java.lang.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​(java.io.PrintStream ps)
      Print this binder's current signature to the give PrintStream.
      Signature signature()
      Get the current Signature for this binder.
      SmartBinder spread​(java.lang.String[] spreadNames, java.lang.Class<?>... spreadTypes)
      Spread a trailing array into the specified argument types.
      SmartBinder spread​(java.lang.String baseName, int count)
      Spread a trailing array into count number of arguments, using the natural component type for the array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(java.lang.Class<?> retType,
                                       java.lang.String[] names,
                                       java.lang.Class<?>... types)
        Create a new SmartBinder from the given types and argument names.
        Parameters:
        retType - the type of the return value to start with
        names - the names of arguments
        types - the argument types
        Returns:
        a new SmartBinder
      • from

        public static SmartBinder from​(java.lang.Class<?> retType,
                                       java.lang.String name,
                                       java.lang.Class<?> type)
        Create a new SmartBinder with from the given types and argument name.
        Parameters:
        retType - the type of the return value to start with
        name - the name of the sole argument
        type - the sole argument's type
        Returns:
        a new SmartBinder
      • from

        public static SmartBinder from​(java.lang.invoke.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 lookups
        inbound - the Signature to start from
        Returns:
        a new SmartBinder
      • from

        public static SmartBinder from​(java.lang.invoke.MethodHandles.Lookup lookup,
                                       java.lang.Class<?> retType,
                                       java.lang.String[] names,
                                       java.lang.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 lookups
        retType - the type of the return value to start with
        names - the names of arguments
        types - the argument types
        Returns:
        a new SmartBinder
      • from

        public static SmartBinder from​(java.lang.invoke.MethodHandles.Lookup lookup,
                                       java.lang.Class<?> retType,
                                       java.lang.String name,
                                       java.lang.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 lookups
        retType - the type of the return value to start with
        name - the name of the sole arguments
        type - the sole argument's type
        Returns:
        a new SmartBinder
      • fold

        public SmartBinder fold​(java.lang.String newName,
                                java.lang.invoke.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 passed
        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
      • fold

        public SmartBinder fold​(java.lang.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 passed
        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​(java.lang.invoke.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​(java.lang.String newName,
                                      java.lang.invoke.MethodHandles.Lookup lookup,
                                      java.lang.Class<?> target,
                                      java.lang.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 passed
        lookup - the Lookup to use for acquiring a folding function
        target - the class on which to find the folding function
        method - the name of the method to become a folding function
        Returns:
        a new SmartBinder with the fold applied
      • foldStatic

        public SmartBinder foldStatic​(java.lang.String newName,
                                      java.lang.Class<?> target,
                                      java.lang.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 passed
        target - the class on which to find the folding function
        method - the name of the method to become a folding function
        Returns:
        a new SmartBinder with the fold applied
      • foldVirtual

        public SmartBinder foldVirtual​(java.lang.String newName,
                                       java.lang.invoke.MethodHandles.Lookup lookup,
                                       java.lang.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 passed
        lookup - the Lookup to use for acquiring a folding function
        method - the name of the method to become a folding function
        Returns:
        a new SmartBinder with the fold applied
      • foldVirtual

        public SmartBinder foldVirtual​(java.lang.String newName,
                                       java.lang.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 passed
        method - 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​(java.lang.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​(java.lang.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​(java.lang.String[] spreadNames,
                                  java.lang.Class<?>... spreadTypes)
        Spread a trailing array into the specified argument types.
        Parameters:
        spreadNames - the names for the spread out arguments
        spreadTypes - the types as which to spread the incoming array
        Returns:
        a new SmartBinder with the spread applied
      • spread

        public SmartBinder spread​(java.lang.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 names
        count - the count of arguments to spread
        Returns:
        a new SmartBinder with the spread applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.String name,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.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 argument
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.String name,
                                  java.lang.Class<?> type,
                                  java.lang.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 argument
        name - the name of the new argument
        type - the type to use in the new signature
        value - the value of the new argument
        Returns:
        a new SmartBinder with the insert applied
      • insert

        public SmartBinder insert​(int index,
                                  java.lang.String[] names,
                                  java.lang.Class<?>[] types,
                                  java.lang.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 arguments
        names - the names of the new arguments
        types - the types of the new arguments
        values - the values of the new arguments
        Returns:
        a new SmartBinder with the insert applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  java.lang.Object value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  boolean value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  byte value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  short value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  char value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  int value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  long value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  float value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  double value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String name,
                                  java.lang.Class<?> type,
                                  java.lang.Object value)
        Append the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        type - the type to use in the new signature
        value - the value of the new argument
        Returns:
        a new SmartBinder with the append applied
      • append

        public SmartBinder append​(java.lang.String[] names,
                                  java.lang.Class<?>[] types,
                                  java.lang.Object... values)
        Append the given arguments to the argument list, assigning them the given names.
        Parameters:
        names - the names of the new arguments
        types - the types to use in the new signature
        values - the values of the new arguments
        Returns:
        a new SmartBinder with the append applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   java.lang.Object value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   boolean value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   byte value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   short value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   char value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   int value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   long value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   float value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   double value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String name,
                                   java.lang.Class<?> type,
                                   java.lang.Object value)
        Prepend the given argument to the argument list, assigning it the given name.
        Parameters:
        name - the name of the new argument
        type - the type to use in the new signature
        value - the value of the new argument
        Returns:
        a new SmartBinder with the prepend applied
      • prepend

        public SmartBinder prepend​(java.lang.String[] names,
                                   java.lang.Class<?>[] types,
                                   java.lang.Object... values)
        Prepend the given arguments to the argument list, assigning them the given name.
        Parameters:
        names - the names of the new arguments
        types - the types to use in the new signature
        values - the values of the new arguments
        Returns:
        a new SmartBinder with the prepend applied
      • drop

        public SmartBinder drop​(java.lang.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​(java.lang.String outName,
                                   java.lang.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 argument
        namePattern - a pattern with which to match arguments for collecting
        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​(java.lang.Class<?> returnType,
                                java.lang.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 signature
        argTypes - the types of the arguments for the casted signature
        Returns:
        a new SmartBinder with the cast applied
      • castVirtual

        public SmartBinder castVirtual​(java.lang.Class<?> returnType,
                                       java.lang.Class<?> firstArg,
                                       java.lang.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 signature
        firstArg - the type of the first argument for the casted signature
        restArgs - the types of the remaining arguments for the casted signature
        Returns:
        a new SmartBinder with the cast applied.
      • castArg

        public SmartBinder castArg​(java.lang.String name,
                                   java.lang.Class<?> type)
        Cast the named argument to the given type.
        Parameters:
        name - the name of the argument to cast
        type - the type to which that argument will be cast
        Returns:
        a new SmartBinder with the cast applied
      • castReturn

        public SmartBinder castReturn​(java.lang.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​(java.lang.invoke.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​(java.lang.invoke.MethodHandles.Lookup lookup,
                                         java.lang.String name)
                                  throws java.lang.NoSuchMethodException,
                                         java.lang.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 lookups
        name - the name of the target virtual method
        Returns:
        a SmartHandle with this binder's starting signature, bound to the target method
        Throws:
        java.lang.NoSuchMethodException - if the named method with current signature's types does not exist
        java.lang.IllegalAccessException - if the named method is not accessible to the given Lookup
      • invokeVirtualQuiet

        public SmartHandle invokeVirtualQuiet​(java.lang.invoke.MethodHandles.Lookup lookup,
                                              java.lang.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 lookups
        name - 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​(java.lang.invoke.MethodHandles.Lookup lookup,
                                        java.lang.Class<?> target,
                                        java.lang.String name)
                                 throws java.lang.NoSuchMethodException,
                                        java.lang.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 lookups
        target - the type on which to find the static method
        name - the name of the target static method
        Returns:
        a SmartHandle with this binder's starting signature, bound to the target method
        Throws:
        java.lang.NoSuchMethodException - if the named method with current signature's types does not exist
        java.lang.IllegalAccessException - if the named method is not accessible to the given Lookup
      • invokeStaticQuiet

        public SmartHandle invokeStaticQuiet​(java.lang.invoke.MethodHandles.Lookup lookup,
                                             java.lang.Class<?> target,
                                             java.lang.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 lookups
        target - the type on which to find the static method
        name - 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​(java.lang.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​(java.io.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​(java.lang.String pattern,
                                  java.lang.invoke.MethodHandle filter)
        Filter the arguments matching the given pattern using the given filter function.
        Parameters:
        pattern - the regular expression pattern to match arguments
        filter - the MethodHandle to use to filter the arguments
        Returns:
        a new SmartBinder with the filter applied