java.lang.Object
org.eclipse.jetty.websocket.core.internal.util.InvokerUtils

public class InvokerUtils extends Object
  • Field Details

  • Constructor Details

    • InvokerUtils

      public InvokerUtils()
  • Method Details

    • bindTo

      public static MethodHandle bindTo(MethodHandle methodHandle, Object... objs)
      Bind optional arguments to provided method handle
      Parameters:
      methodHandle - the method handle to bind to
      objs - the list of optional objects to bind to.
      Returns:
      the bound MethodHandle, or null if the provided methodHandle was null.
    • mutatedInvoker

      public static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?> targetClass, Method method, InvokerUtils.Arg... callingArgs)
      Build a MethodHandle that can call the method with the calling args provided.

      Might need to drop calling args and/or reorder the calling args to fit the actual method being called.

      Parameters:
      lookup - the MethodHandles.Lookup instance to use.
      targetClass - the target class for invocations of the resulting MethodHandle (also known as parameter 0)
      method - the method to invoke
      callingArgs - the calling arguments. This is the array of arguments that will always be passed into the returned MethodHandle. They will be present in the MethodHandle.type() in the order specified in this array.
    • mutatedInvoker

      public static MethodHandle mutatedInvoker(MethodHandles.Lookup lookup, Class<?> targetClass, Method method, InvokerUtils.ParamIdentifier paramIdentifier, String[] namedVariables, InvokerUtils.Arg... callingArgs)
      Create a MethodHandle that performs the following layers
      1. MethodHandles.permuteArguments(MethodHandle, MethodType, int...) - moving calling Args around to fit actual actual method parameter arguments (in proper order), with remaining (unused) calling args afterwords
      2. MethodHandles.dropArguments(MethodHandle, int, Class[]) - to drop the unused calling args
      3. MethodHandle.invoke(Object...) - to call the specific method

      The returned MethodHandle.MethodHandle.type() assumes the following:

      1. Return type will be what the provided Method has.
      2. The first parameter is the type of class provided in the targetClass.
      3. The next parameters are all of the found type's of the named arguments, or type String if not found in provided Method.
      4. The next parameters are all of the provided callingArg types
      Parameters:
      lookup - the MethodHandles.Lookup instance to use.
      targetClass - the target class for invocations of the resulting MethodHandle (also known as parameter 0)
      method - the method to invoke
      paramIdentifier - the mechanism to identify parameters in method
      namedVariables - the array of named variables. This is the array of named arguments that the target method might have. The resulting MethodHandle will include all of these namedVariables as the first non-object arguments in the MethodType found on the returned MethodHandle.type()
      callingArgs - the calling arguments. This is the array of arguments that will always be passed into the returned MethodHandle. They will be present in the MethodHandle.type() in the order specified in this array.
      Returns:
      the MethodHandle for this set of CallingArgs
      Throws:
      RuntimeException - when unable to fit Calling Args to Parameter Types
    • optionalMutatedInvoker

      public static MethodHandle optionalMutatedInvoker(MethodHandles.Lookup lookup, Class<?> targetClass, Method method, InvokerUtils.ParamIdentifier paramIdentifier, String[] namedVariables, InvokerUtils.Arg... callingArgs)
      Create an optional MethodHandle that performs the following layers.
      1. MethodHandles.permuteArguments(MethodHandle, MethodType, int...) - moving calling Args around to fit actual actual method parameter arguments (in proper order), with remaining (unused) calling args afterwords
      2. MethodHandles.dropArguments(MethodHandle, int, Class[]) - to drop the unused calling args
      3. MethodHandle.invoke(Object...) - to call the specific method
      Parameters:
      lookup - the MethodHandles.Lookup instance to use.
      targetClass - the target class for invocations of the resulting MethodHandle (also known as parameter 0)
      method - the method to invoke
      paramIdentifier - the mechanism to identify parameters in method
      namedVariables - the array of named variables. This is the array of named arguments that the target method might have. The resulting MethodHandle will include all of these namedVariables as the first non-object arguments in the MethodType found on the returned MethodHandle.type()
      callingArgs - the calling arguments. This is the array of arguments that will always be passed into the returned MethodHandle. They will be present in the MethodHandle.type() in the order specified in this array.
      Returns:
      the MethodHandle for this set of CallingArgs, or null if not possible to create MethodHandle with CallingArgs to provided method
    • optionalMutatedInvoker

      public static MethodHandle optionalMutatedInvoker(MethodHandles.Lookup lookup, Class<?> targetClass, Method method, InvokerUtils.Arg... callingArgs)