Class ReflectUtil

java.lang.Object
com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil

public final class ReflectUtil extends Object
Class with reflection utilities
  • Method Details

    • copyClass

      public static Class<?> copyClass(Class<?> clazz, ClassLoader cl)
      Copy a class from one class loader to another. Was previously used in AwsJackson class to do some crazy passing of classes from class loader to class loader. When that class was removed due to excessive complexity, this method was retained for potential future use.
      Parameters:
      clazz - class to copy
      cl - class loader to copy class to
      Returns:
      Class inside new classloader
      Throws:
      UncheckedIOException - if class cannot be copied
      ReflectUtil.ReflectException - if class cannot be read after copying
    • loadClass

      public static Class<?> loadClass(ClassLoader cl, String name)
    • getRawClass

      public static Class<?> getRawClass(Type type)
    • makeCaster

      public static Functions.R1<Object,Object> makeCaster(Type type)
    • makeCaster

      public static <T> Functions.R1<T,Object> makeCaster(Class<? extends T> clazz)
    • loadInstanceR0

      public static <C,R> Functions.R1<R,C> loadInstanceR0(Class<? super C> clazz, String name, boolean setAccessible, Class<? extends R> rType)
      load instance method that takes no parameters and returns type R
      Type Parameters:
      C - instance class type
      R - return type
      Parameters:
      clazz - Class of instance
      name - name of method
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      Returns:
      function handle
    • loadInstanceR4

      public static <A1,A2,A3,A4,C,R> Functions.R5<R,C,A1,A2,A3,A4> loadInstanceR4(Class<? super C> clazz, String name, boolean setAccessible, Class<? extends R> rType, Class<? super A1> a1Type, Class<? super A2> a2Type, Class<? super A3> a3Type, Class<? super A4> a4Type)
      load instance method that takes 4 parameters and return type R
      Type Parameters:
      A1 - argument 1 type
      A2 - argument 2 type
      A3 - argument 3 type
      A4 - argument 4 type
      C - instance class type
      R - return type
      Parameters:
      clazz - class of instance
      name - name of method
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      a1Type - argument 1 class
      a2Type - argument 2 class
      a3Type - argument 3 class
      a4Type - argument 4 class
      Returns:
      function handle
    • loadInstanceV1

      public static <A1,C> Functions.V2<C,A1> loadInstanceV1(Class<? super C> clazz, String name, boolean setAccessible, Class<? super A1> a1Type)
      load an instance method that take 1 parameter and does not return anything
      Type Parameters:
      A1 - argument 1 type
      C - instance class type
      Parameters:
      clazz - class of instance
      name - name of method
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      Returns:
      function handle
    • bindInstanceR0

      public static <C,R> Functions.R0<R> bindInstanceR0(C instance, String name, boolean setAccessible, Class<? extends R> rType)
      load an instance method that takes no parameters and return type R
      Type Parameters:
      C - instance type
      R - return type
      Parameters:
      instance - instance to load method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      Returns:
      function handle
    • bindInstanceR1

      public static <A1,C,R> Functions.R1<R,A1> bindInstanceR1(C instance, String name, boolean setAccessible, Class<? extends R> rType, Class<? super A1> a1Type)
      load an instance method that takes 1 parameter and returns type R
      Type Parameters:
      A1 - argument 1 type
      C - instance type
      R - return type
      Parameters:
      instance - instance to load method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      a1Type - class of argument 1
      Returns:
      function handle
    • bindInstanceV1

      public static <A1,C> Functions.V1<A1> bindInstanceV1(C instance, String name, boolean setAccessible, Class<? super A1> a1Type)
      * load an instance method that takes 1 parameter and returns nothing
      Type Parameters:
      A1 - argument 1 type
      C - instance type
      Parameters:
      instance - instance to load method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      a1Type - class of argument 1
      Returns:
      function handle
    • bindInstanceV2

      public static <A1,A2,C> Functions.V2<A1,A2> bindInstanceV2(C instance, String name, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type)
      load an instance method that takes 2 parameter and returns nothing
      Type Parameters:
      A1 - argument 1 type
      A2 - argument 2 type
      C - instance type
      Parameters:
      instance - instance to load method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      a1Type - class of argument 1
      a2Type - class of argument 2
      Returns:
      function handle
    • loadStaticR0

      public static <R> Functions.R0<R> loadStaticR0(Class<?> clazz, String name, boolean setAccessible, Class<? extends R> rType)
      load static method that takes no parameters and returns type R
      Type Parameters:
      R - return type
      Parameters:
      clazz - class to load static method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      Returns:
      function handle
    • loadStaticR1

      public static <A1,R> Functions.R1<R,A1> loadStaticR1(Class<?> clazz, String name, boolean setAccessible, Class<? extends R> rType, Class<? super A1> a1Type)
      load static method that takes one parameter and returns type R
      Type Parameters:
      A1 - argument 1 type
      R - return type
      Parameters:
      clazz - class to load static method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      rType - class of return type
      a1Type - argument 1 class
      Returns:
      function handle
    • loadStaticV2

      public static <A1,A2> Functions.V2<A1,A2> loadStaticV2(Class<?> clazz, String name, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type)
      load static method that takes two parameters and return nothing
      Type Parameters:
      A1 - argument 1 type
      A2 - argument 2 type
      Parameters:
      clazz - class to load static method from
      name - method name
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      a2Type - argument 2 class
      Returns:
      function handle
    • loadConstructor0

      public static <C> Functions.R0<C> loadConstructor0(Class<? extends C> clazz, boolean setAccessible)
      load default constructor
      Type Parameters:
      C - Class type
      Parameters:
      clazz - Class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      Returns:
      function handle
    • loadConstructor1

      public static <A1,C> Functions.R1<C,A1> loadConstructor1(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type)
      load constructor that takes 1 parameter
      Type Parameters:
      A1 - argument 1 type
      C - Class type
      Parameters:
      clazz - Class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      Returns:
      function handle
    • loadConstructor2

      public static <A1,A2,C> Functions.R2<C,A1,A2> loadConstructor2(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type)
      load constructor that takes 2 parameters
      Type Parameters:
      A1 - argument 1 type
      A2 - argument 2 type
      C - Class type
      Parameters:
      clazz - Class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      a2Type - argument 2 class
      Returns:
      function handle
    • loadConstuctor3

      public static <C,A1,A2,A3> Functions.R3<C,A1,A2,A3> loadConstuctor3(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type, Class<? super A3> a3Type)
      load constuctor that takes 3 parameters
      Type Parameters:
      C - Class type
      A1 - argument 1 type
      A2 - argument 2 type
      A3 - argument 3 type
      Parameters:
      clazz - class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      a2Type - argument 2 class
      a3Type - argument 3 class
      Returns:
      function handle
    • loadConstuctor4

      public static <C,A1,A2,A3,A4> Functions.R4<C,A1,A2,A3,A4> loadConstuctor4(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type, Class<? super A3> a3Type, Class<? super A4> a4Type)
      loads constructor that takes 4 parameters
      Type Parameters:
      C - Class type
      A1 - argument 1 type
      A2 - argument 2 type
      A3 - argument 3 type
      A4 - argument 4 type
      Parameters:
      clazz - class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      a2Type - argument 2 class
      a3Type - argument 3 class
      a4Type - argument 4 class
      Returns:
      function handle
    • loadConstuctor5

      public static <C,A1,A2,A3,A4,A5> Functions.R5<C,A1,A2,A3,A4,A5> loadConstuctor5(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type, Class<? super A3> a3Type, Class<? super A4> a4Type, Class<? super A5> a5Type)
      loads constructor that takes 5 paramters
      Type Parameters:
      C - Class type
      A1 - argument 1 type
      A2 - argument 2 type
      A3 - argument 3 type
      A4 - argument 4 type
      A5 - argument 5 type
      Parameters:
      clazz - class to load constructor for
      setAccessible - whether method is accessible (public vs private)
      a1Type - argument 1 class
      a2Type - argument 2 class
      a3Type - argument 3 class
      a4Type - argument 4 class
      a5Type - argument 5 class
      Returns:
      function handle
    • loadConstuctor9

      public static <C,A1,A2,A3,A4,A5,A6,A7,A8,A9> Functions.R9<C,A1,A2,A3,A4,A5,A6,A7,A8,A9> loadConstuctor9(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type, Class<? super A2> a2Type, Class<? super A3> a3Type, Class<? super A4> a4Type, Class<? super A5> a5Type, Class<? super A6> a6Type, Class<? super A7> a7Type, Class<? super A8> a8Type, Class<? super A9> a9type)
      load constuctor that takes 9 parameters
      Type Parameters:
      C - Class type
      A1 - argument 1 type
      A2 - argument 2 type
      A3 - argument 3 type
      A4 - argument 4 type
      A5 - argument 5 type
      A6 - argument 6 type
      A7 - argument 7 type
      A8 - argument 8 type
      A9 - argument 9 type
      Parameters:
      a1Type - argument 1 class
      a2Type - argument 2 class
      a3Type - argument 3 class
      a4Type - argument 4 class
      a5Type - argument 5 class
      a6Type - argument 6 class
      a7Type - argument 7 class
      a8Type - argument 8 class
      a9type - argument 9 class
      Returns:
      function handle
    • getStaticField

      public static <T> T getStaticField(Class<?> clazz, String name, Class<? extends T> type)
    • setStaticField

      public static void setStaticField(Class<?> clazz, String name, boolean setAccessible, Object value)