Package org.easymock.internal
Class ReflectionUtils
java.lang.Object
org.easymock.internal.ReflectionUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Method
findDefaultMethod
(Class<?> searchedClass, String name, Class<?>[] paramTypes) static Method
findMethod
(Class<?> clazz, String name, Predicate<Method> filter) Attempt to find aMethod
on the supplied class with the supplied name and no parameters.static Method
Attempt to find aMethod
on the supplied class with the supplied name and parameter types.static <T> Constructor<T>
getConstructor
(Class<T> clazz, Object... objs) Returns a constructor that containsobjs
as arguments.static Method
getDeclaredMethod
(Class<?> clazz, String name, Class<?>... paramTypes) Basically calls getDeclaredMethod on a Class but wraps the NoSuchMethodException into a Runtime.getDefaultMethods
(Class<?> clazz) Return all default methods of an interface and it's inherited interface.static boolean
isClassAvailable
(String className) Tells if a class is available in the classpathprivate static boolean
isMatchingConstructor
(Constructor<?> classConstructor, Object... objs) Returns true if objects inobjs
are eligible to be passed toclassConstructor
.private static Class<?>
wrapPrimitive
(Class<?> parameterType) Given a primitive type, returns its boxed equivalent.
-
Field Details
-
NOT_PRIVATE
-
primitiveToWrapperType
-
OBJECT_EQUALS
-
OBJECT_HASHCODE
-
OBJECT_TOSTRING
-
OBJECT_FINALIZE
-
-
Constructor Details
-
ReflectionUtils
private ReflectionUtils()
-
-
Method Details
-
findMethod
Attempt to find aMethod
on the supplied class with the supplied name and no parameters. Searches all superclasses up toObject
. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case they are totally ignored and can't clash with a non-ignored one to cause ambiguity.Returns
null
if noMethod
can be found.- Parameters:
clazz
- the class to introspectname
- the name of the methodfilter
- tells what methods to ignore in the research- Returns:
- the Method object, or
null
if none found
-
findMethod
public static Method findMethod(Class<?> clazz, String name, Predicate<Method> filter, Class<?>... paramTypes) Attempt to find aMethod
on the supplied class with the supplied name and parameter types. Searches all superclasses up toObject
. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case they are totally ignored and can't clash with a non-ignored one to cause ambiguity.Returns
null
if noMethod
can be found.- Parameters:
clazz
- the class to introspectname
- the name of the methodfilter
- tells what methods to ignore in the researchparamTypes
- the parameter types of the method (may benull
to indicate any signature)- Returns:
- the Method object, or
null
if none found
-
findDefaultMethod
-
getConstructor
public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... objs) throws NoSuchMethodException Returns a constructor that containsobjs
as arguments.We could not do something like
clazz.getConstructor(objs.class())
because that would require casting all the passed arguments to the exact parameter types of the desired constructor.- Type Parameters:
T
- type of the class searched- Parameters:
clazz
- class on which we are searching the constructorobjs
- list of arguments of the constructor- Returns:
- a constructor with the arguments in
objs
- Throws:
NoSuchMethodException
- when the constructor withargs
does not exist or is ambiguous
-
isMatchingConstructor
Returns true if objects inobjs
are eligible to be passed toclassConstructor
. -
wrapPrimitive
Given a primitive type, returns its boxed equivalent. For instance, givenint
, returnsInteger
.- Parameters:
parameterType
- the primitive type- Returns:
- the boxed equivalent
-
getDeclaredMethod
Basically calls getDeclaredMethod on a Class but wraps the NoSuchMethodException into a Runtime.- Parameters:
clazz
- class on which the getDeclaredMethod is calledname
- method nameparamTypes
- method parameters- Returns:
- the method searched
-
isClassAvailable
Tells if a class is available in the classpath- Parameters:
className
- full class name- Returns:
- true if the class was found
-
getDefaultMethods
Return all default methods of an interface and it's inherited interface.- Parameters:
clazz
- class for which we want the default method- Returns:
- all default methods
-