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_CLASSTheclassof java.lang.reflect.InaccessibleObjectException since JDK 9.static java.lang.StringINACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAMEThe class name of java.lang.reflect.InaccessibleObjectException since JDK 9static java.lang.StringSUN_REFLECT_REFLECTION_CLASS_NAMESun 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.StringgetCallerClassName()Get Caller classstatic booleanisInaccessibleObjectException(java.lang.Throwable failure)Determine whether the specifiedThrowableisjava.lang.reflect.InaccessibleObjectExceptionstatic booleanisSupportedSunReflectReflection()Is supported sun.reflect.Reflection or notstatic java.util.Map<java.lang.String,java.lang.Object>readFieldsAsMap(java.lang.Object object)Read fields value asMapstatic <T> java.util.List<T>toList(java.lang.Object array)ConvertArrayobject 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
Theclassof java.lang.reflect.InaccessibleObjectException since JDK 9. It may benullif the JDK version is less than 9.
-
-
Method Detail
-
isSupportedSunReflectReflection
public static boolean isSupportedSunReflectReflection()
Is supported sun.reflect.Reflection or not- Returns:
trueif 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:
nullif not found
-
toList
@Nonnull public static <T> java.util.List<T> toList(java.lang.Object array) throws java.lang.IllegalArgumentException
ConvertArrayobject 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 specifiedThrowableisjava.lang.reflect.InaccessibleObjectException- Parameters:
failure-Throwableinstance- Returns:
trueif the specifiedThrowableisjava.lang.reflect.InaccessibleObjectException
-
-