Package io.swagger.util
Class ReflectionUtils
- java.lang.Object
-
- io.swagger.util.ReflectionUtils
-
public class ReflectionUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Method
findMethod(Method methodToFind, Class<?> cls)
Searches the method methodToFind in given class cls.static <A extends Annotation>
AgetAnnotation(Class<?> cls, Class<A> annotationClass)
static <A extends Annotation>
AgetAnnotation(Method method, Class<A> annotationClass)
Returns an annotation by type from a method.static List<Field>
getDeclaredFields(Class<?> cls)
Returns the list of declared fields from the classcls
and its superclasses excludingObject
class.static Method
getOverriddenMethod(Method method)
Returns overridden method from superclass if it exists.static Annotation[][]
getParameterAnnotations(Method method)
static boolean
isConstructorCompatible(Constructor<?> constructor)
static boolean
isInject(List<Annotation> annotations)
static boolean
isOverriddenMethod(Method methodToFind, Class<?> cls)
Checks if the method methodToFind is the overridden method from the superclass or superinterface.static boolean
isVoid(Type type)
Checks if the type is void.static Class<?>
loadClassByName(String className)
Load Class by class name.static Object
safeInvoke(Method method, Object obj, Object... args)
static Type
typeFromString(String type)
-
-
-
Method Detail
-
loadClassByName
public static Class<?> loadClassByName(String className) throws ClassNotFoundException
Load Class by class name. If class not found in it's Class loader or one of the parent class loaders - delegate to the Thread's ContextClassLoader- Parameters:
className
- Canonical class name- Returns:
- Class definition of className
- Throws:
ClassNotFoundException
-
isOverriddenMethod
public static boolean isOverriddenMethod(Method methodToFind, Class<?> cls)
Checks if the method methodToFind is the overridden method from the superclass or superinterface.- Parameters:
methodToFind
- is method to checkcls
- is method class- Returns:
- true if the method is overridden method
-
getOverriddenMethod
public static Method getOverriddenMethod(Method method)
Returns overridden method from superclass if it exists. If method was not found returns null.- Parameters:
method
- is method to find- Returns:
- overridden method from superclass
-
findMethod
public static Method findMethod(Method methodToFind, Class<?> cls)
Searches the method methodToFind in given class cls. If the method is found returns it, else return null.- Parameters:
methodToFind
- is the method to searchcls
- is the class or interface where to search- Returns:
- method if it is found
-
isInject
public static boolean isInject(List<Annotation> annotations)
-
isConstructorCompatible
public static boolean isConstructorCompatible(Constructor<?> constructor)
-
getDeclaredFields
public static List<Field> getDeclaredFields(Class<?> cls)
Returns the list of declared fields from the classcls
and its superclasses excludingObject
class. If the field from child class hides the field from superclass, the field from superclass won't be added to the result list.- Parameters:
cls
- is the processing class- Returns:
- list of Fields
-
getAnnotation
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass)
Returns an annotation by type from a method.- Type Parameters:
A
- is the type of annotation- Parameters:
method
- is the method to findannotationClass
- is the type of annotation- Returns:
- annotation if it is found
-
getAnnotation
public static <A extends Annotation> A getAnnotation(Class<?> cls, Class<A> annotationClass)
-
getParameterAnnotations
public static Annotation[][] getParameterAnnotations(Method method)
-
isVoid
public static boolean isVoid(Type type)
Checks if the type is void.- Parameters:
type
- is the type to check- Returns:
- true if the type is void
-
-