Package io.microsphere.reflect
Class ReflectionUtils
- java.lang.Object
-
- io.microsphere.reflect.ReflectionUtils
-
- All Implemented Interfaces:
Utils
public abstract class ReflectionUtils extends java.lang.Object implements Utils
Reflection Utility class , generic methods are defined fromFieldUtils
,MethodUtils
,ConstructorUtils
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Method
,Field
,Constructor
,Array
,MethodUtils
,FieldUtils
,ConstructorUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Class<? extends java.lang.Throwable>
INACCESSIBLE_OBJECT_EXCEPTION_CLASS
Theclass
of java.lang.reflect.InaccessibleObjectException since JDK 9.static java.lang.String
INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME
The class name of java.lang.reflect.InaccessibleObjectException since JDK 9static java.lang.String
SUN_REFLECT_REFLECTION_CLASS_NAME
Sun JDK implementation class: full name of sun.reflect.Reflection
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Class<?>
getCallerClass()
Get caller classstatic java.lang.Class<?>
getCallerClass(int invocationFrame)
Get the caller classstatic java.lang.String
getCallerClassName()
Get Caller classstatic boolean
isInaccessibleObjectException(java.lang.Throwable failure)
Determine whether the specifiedThrowable
isjava.lang.reflect.InaccessibleObjectException
static boolean
isSupportedSunReflectReflection()
Is supported sun.reflect.Reflection or notstatic java.util.Map<java.lang.String,java.lang.Object>
readFieldsAsMap(java.lang.Object object)
Read fields value asMap
static <T> java.util.List<T>
toList(java.lang.Object array)
ConvertArray
object toList
-
-
-
Field Detail
-
SUN_REFLECT_REFLECTION_CLASS_NAME
public static final java.lang.String SUN_REFLECT_REFLECTION_CLASS_NAME
Sun JDK implementation class: full name of sun.reflect.Reflection- See Also:
- Constant Field Values
-
INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME
public static final java.lang.String INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME
The class name of java.lang.reflect.InaccessibleObjectException since JDK 9- See Also:
- Constant Field Values
-
INACCESSIBLE_OBJECT_EXCEPTION_CLASS
@Nullable public static final java.lang.Class<? extends java.lang.Throwable> INACCESSIBLE_OBJECT_EXCEPTION_CLASS
Theclass
of java.lang.reflect.InaccessibleObjectException since JDK 9. It may benull
if the JDK version is less than 9.
-
-
Method Detail
-
isSupportedSunReflectReflection
public static boolean isSupportedSunReflectReflection()
Is supported sun.reflect.Reflection or not- Returns:
true
if supported
-
getCallerClassName
@Nonnull public static java.lang.String getCallerClassName()
Get Caller class- Returns:
- Get the Class name that called the method
-
getCallerClass
@Nonnull public static java.lang.Class<?> getCallerClass() throws java.lang.IllegalStateException
Get caller class For instance,package com.acme; import ...; class Foo { public void bar(){ } }
- Returns:
- Get caller class
- Throws:
java.lang.IllegalStateException
- If the caller class cannot be found
-
getCallerClass
public static java.lang.Class<?> getCallerClass(int invocationFrame)
Get the caller class- Parameters:
invocationFrame
- The frame of method invocation- Returns:
null
if not found
-
toList
@Nonnull public static <T> java.util.List<T> toList(java.lang.Object array) throws java.lang.IllegalArgumentException
ConvertArray
object toList
- Parameters:
array
- array object- Returns:
List
- Throws:
java.lang.IllegalArgumentException
- if the object argument is not an array
-
readFieldsAsMap
@Nonnull public static java.util.Map<java.lang.String,java.lang.Object> readFieldsAsMap(java.lang.Object object)
Read fields value asMap
- Parameters:
object
- object to be read- Returns:
- fields value as
Map
-
isInaccessibleObjectException
public static boolean isInaccessibleObjectException(java.lang.Throwable failure)
Determine whether the specifiedThrowable
isjava.lang.reflect.InaccessibleObjectException
- Parameters:
failure
-Throwable
instance- Returns:
true
if the specifiedThrowable
isjava.lang.reflect.InaccessibleObjectException
-
-