Class ReflectUtil
- java.lang.Object
-
- com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil
-
public final class ReflectUtil extends Object
Class with reflection utilities
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReflectUtil.ReflectException
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 Rstatic <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 Rstatic <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 nothingstatic <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 nothingstatic Class<?>
copyClass(Class<?> clazz, ClassLoader cl)
Copy a class from one class loader to another.static Class<?>
getRawClass(Type type)
static <T> T
getStaticField(Class<?> clazz, String name, Class<? extends T> type)
static Class<?>
loadClass(ClassLoader cl, String name)
static <C> Functions.R0<C>
loadConstructor0(Class<? extends C> clazz, boolean setAccessible)
load default constructorstatic <A1,C>
Functions.R1<C,A1>loadConstructor1(Class<? extends C> clazz, boolean setAccessible, Class<? super A1> a1Type)
load constructor that takes 1 parameterstatic <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 parametersstatic <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 parametersstatic <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 parametersstatic <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 paramtersstatic <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 parametersstatic <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 Rstatic <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 Rstatic <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 anythingstatic <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 Rstatic <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 Rstatic <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 nothingstatic <T> Functions.R1<T,Object>
makeCaster(Class<? extends T> clazz)
static Functions.R1<Object,Object>
makeCaster(Type type)
static void
setStaticField(Class<?> clazz, String name, boolean setAccessible, Object value)
-
-
-
Method Detail
-
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 copycl
- class loader to copy class to- Returns:
- Class inside new classloader
- Throws:
UncheckedIOException
- if class cannot be copiedReflectUtil.ReflectException
- if class cannot be read after copying
-
loadClass
public static Class<?> loadClass(ClassLoader cl, String name)
-
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 typeR
- return type- Parameters:
clazz
- Class of instancename
- name of methodsetAccessible
- 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 typeA2
- argument 2 typeA3
- argument 3 typeA4
- argument 4 typeC
- instance class typeR
- return type- Parameters:
clazz
- class of instancename
- name of methodsetAccessible
- whether method is accessible (public vs private)rType
- class of return typea1Type
- argument 1 classa2Type
- argument 2 classa3Type
- argument 3 classa4Type
- 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:
C
- instance class typeA1
- argument 1 type- Parameters:
clazz
- class of instancename
- name of methodsetAccessible
- 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 typeR
- return type- Parameters:
instance
- instance to load method fromname
- method namesetAccessible
- 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:
C
- instance typeA1
- argument 1 typeR
- return type- Parameters:
instance
- instance to load method fromname
- method namesetAccessible
- whether method is accessible (public vs private)rType
- class of return typea1Type
- 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:
C
- instance typeA1
- argument 1 type- Parameters:
instance
- instance to load method fromname
- method namesetAccessible
- 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:
C
- instance typeA1
- argument 1 typeA2
- argument 2 type- Parameters:
instance
- instance to load method fromname
- method namesetAccessible
- whether method is accessible (public vs private)a1Type
- class of argument 1a2Type
- 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 fromname
- method namesetAccessible
- 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:
R
- return typeA1
- argument 1 type- Parameters:
clazz
- class to load static method fromname
- method namesetAccessible
- whether method is accessible (public vs private)rType
- class of return typea1Type
- 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 typeA2
- argument 2 type- Parameters:
clazz
- class to load static method fromname
- method namesetAccessible
- whether method is accessible (public vs private)a1Type
- argument 1 classa2Type
- 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 forsetAccessible
- 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:
C
- Class typeA1
- argument 1 type- Parameters:
clazz
- Class to load constructor forsetAccessible
- 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:
C
- Class typeA1
- argument 1 typeA2
- argument 2 type- Parameters:
clazz
- Class to load constructor forsetAccessible
- whether method is accessible (public vs private)a1Type
- argument 1 classa2Type
- 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 typeA1
- argument 1 typeA2
- argument 2 typeA3
- argument 3 type- Parameters:
clazz
- class to load constructor forsetAccessible
- whether method is accessible (public vs private)a1Type
- argument 1 classa2Type
- argument 2 classa3Type
- 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 typeA1
- argument 1 typeA2
- argument 2 typeA3
- argument 3 typeA4
- argument 4 type- Parameters:
clazz
- class to load constructor forsetAccessible
- whether method is accessible (public vs private)a1Type
- argument 1 classa2Type
- argument 2 classa3Type
- argument 3 classa4Type
- 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 typeA1
- argument 1 typeA2
- argument 2 typeA3
- argument 3 typeA4
- argument 4 typeA5
- argument 5 type- Parameters:
clazz
- class to load constructor forsetAccessible
- whether method is accessible (public vs private)a1Type
- argument 1 classa2Type
- argument 2 classa3Type
- argument 3 classa4Type
- argument 4 classa5Type
- 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 typeA1
- argument 1 typeA2
- argument 2 typeA3
- argument 3 typeA4
- argument 4 typeA5
- argument 5 typeA6
- argument 6 typeA7
- argument 7 typeA8
- argument 8 typeA9
- argument 9 type- Parameters:
a1Type
- argument 1 classa2Type
- argument 2 classa3Type
- argument 3 classa4Type
- argument 4 classa5Type
- argument 5 classa6Type
- argument 6 classa7Type
- argument 7 classa8Type
- argument 8 classa9type
- argument 9 class- Returns:
- function handle
-
getStaticField
public static <T> T getStaticField(Class<?> clazz, String name, Class<? extends T> type)
-
-