public class MemberMatcher
extends java.lang.Object
Constructor and Description |
---|
MemberMatcher() |
Modifier and Type | Method and Description |
---|---|
static <T> java.lang.reflect.Constructor<T> |
constructor(java.lang.Class<T> declaringClass)
Returns any one constructor specified in declaringClass.
|
static <T> java.lang.reflect.Constructor<T> |
constructor(java.lang.Class<T> declaringClass,
java.lang.Class<?>... parameterTypes)
Returns a constructor specified in declaringClass.
|
static java.lang.reflect.Constructor<?>[] |
constructors(java.lang.reflect.Constructor<?> constructor,
java.lang.reflect.Constructor<?>... additionalConstructors)
Convenience method to get a constructor from a class.
|
static java.lang.reflect.Constructor<?>[] |
constructorsDeclaredIn(java.lang.Class<?> cls,
java.lang.Class<?>... additionalClasses)
Get all constructors in the supplied class(es).
|
static <T> java.lang.reflect.Constructor<T> |
defaultConstructorIn(java.lang.Class<T> declaringClass)
Returns the default constructor in
declaringClass |
static java.lang.reflect.AccessibleObject[] |
everythingDeclaredIn(java.lang.Class<?> cls,
java.lang.Class<?>... additionalClasses)
Get all constructors and methods in the supplied class(es).
|
static java.lang.reflect.Field |
field(java.lang.Class<?> declaringClass,
java.lang.String fieldName)
Get a field from a class.
|
static java.lang.reflect.Field[] |
fields(java.lang.Class<?> clazz)
Get all fields in a class hierarchy.
|
static java.lang.reflect.Field[] |
fields(java.lang.Class<?> clazz,
java.lang.String[] fieldNames)
Get an array of
Field 's that matches the supplied list of field
names. |
static java.lang.reflect.Field[] |
fields(java.lang.Class<?> clazz,
java.lang.String firstFieldName,
java.lang.String... additionalfieldNames)
Get an array of
Field 's that matches the supplied list of field
names. |
static java.lang.reflect.Field[] |
fields(java.lang.reflect.Field field,
java.lang.reflect.Field... additionalFields)
Get an array of
Field 's. |
private static java.lang.reflect.Constructor<?>[] |
merge(java.lang.reflect.Constructor<?> first,
java.lang.reflect.Constructor<?>... additional) |
private static java.lang.reflect.Field[] |
merge(java.lang.reflect.Field first,
java.lang.reflect.Field... additional) |
private static java.lang.reflect.Method[] |
merge(java.lang.reflect.Method first,
java.lang.reflect.Method... additional) |
private static java.lang.String[] |
merge(java.lang.String first,
java.lang.String... additional) |
static java.lang.reflect.Method |
method(java.lang.Class<?> declaringClass,
java.lang.Class<?>... parameterTypes)
Get a method without having to specify the method name.
|
static java.lang.reflect.Method |
method(java.lang.Class<?> declaringClass,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
Get a method when it cannot be determined by methodName or parameter
types only.
|
static java.lang.reflect.Method[] |
methods(java.lang.Class<?> clazz,
java.lang.String[] methodNames)
Get an array of
Method 's that matches the supplied list of method
names. |
static java.lang.reflect.Method[] |
methods(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.String... additionalMethodNames)
Get an array of
Method 's that matches the supplied list of method
names. |
static java.lang.reflect.Method[] |
methods(java.lang.reflect.Method method,
java.lang.reflect.Method... additionalMethods)
Get an array of
Field 's. |
static java.lang.reflect.Method[] |
methodsDeclaredIn(java.lang.Class<?> cls,
java.lang.Class<?>... additionalClasses)
Get all methods in a class hierarchy of the supplied classes.
|
public static java.lang.reflect.Method[] methodsDeclaredIn(java.lang.Class<?> cls, java.lang.Class<?>... additionalClasses)
cls
- The class whose methods to get.additionalClasses
- Additional classes whose methods to get.public static java.lang.reflect.Method method(java.lang.Class<?> declaringClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
The method will first try to look for a declared method in the same
class. If the method is not declared in this class it will look for the
method in the super class. This will continue throughout the whole class
hierarchy. If the method is not found an IllegalArgumentException
is thrown.
declaringClass
- The declaringClass of the class where the method is located.methodName
- The method names.parameterTypes
- All parameter types of the method (may be null
).java.lang.reflect.Method
.MethodNotFoundException
- If a method cannot be found in the hierarchy.public static java.lang.reflect.Method method(java.lang.Class<?> declaringClass, java.lang.Class<?>... parameterTypes)
The method will first try to look for a declared method in the same
class. If the method is not declared in this class it will look for the
method in the super class. This will continue throughout the whole class
hierarchy. If the method is not found an IllegalArgumentException
is thrown. Since the method name is not specified an
IllegalArgumentException
is thrown if two or more methods matches
the same parameter types in the same class.
declaringClass
- The declaringClass of the class where the method is located.parameterTypes
- All parameter types of the method (may be null
).java.lang.reflect.Method
.MethodNotFoundException
- If a method cannot be found in the hierarchy.TooManyMethodsFoundException
- If several methods were found.public static java.lang.reflect.Method[] methods(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.String... additionalMethodNames)
Method
's that matches the supplied list of method
names. Both instance and static methods are taken into account.clazz
- The class that should contain the methods.methodName
- The name of the first method.additionalMethodNames
- Additional names of the methods that will be returned.null
.MethodNotFoundException
- If no method was found.public static java.lang.reflect.Method[] methods(java.lang.reflect.Method method, java.lang.reflect.Method... additionalMethods)
Field
's.method
- The first field.additionalMethods
- Additional fieldsField
.public static java.lang.reflect.Method[] methods(java.lang.Class<?> clazz, java.lang.String[] methodNames)
Method
's that matches the supplied list of method
names. Both instance and static methods are taken into account.clazz
- The class that should contain the methods.methodNames
- The names of the methods.null
.MethodNotFoundException
- If no method was found.public static java.lang.reflect.Field field(java.lang.Class<?> declaringClass, java.lang.String fieldName)
The method will first try to look for a declared field in the same class.
If the method is not declared in this class it will look for the field in
the super class. This will continue throughout the whole class hierarchy.
If the field is not found an IllegalArgumentException
is thrown.
declaringClass
- The declaringClass of the class where the method is located.fieldName
- The method names.java.lang.reflect.Field
.FieldNotFoundException
- If a field cannot be found in the hierarchy.public static java.lang.reflect.Field[] fields(java.lang.Class<?> clazz, java.lang.String firstFieldName, java.lang.String... additionalfieldNames)
Field
's that matches the supplied list of field
names.clazz
- The class that should contain the fields.firstFieldName
- The name of the first field.additionalfieldNames
- The additional names of the fields that will be returned.null
public static java.lang.reflect.Field[] fields(java.lang.Class<?> clazz)
clazz
- The class that should contain the fields.firstFieldName
- The name of the first field.additionalfieldNames
- The additional names of the fields that will be returned.null
public static java.lang.reflect.Field[] fields(java.lang.reflect.Field field, java.lang.reflect.Field... additionalFields)
Field
's.field
- The first field.additionalFields
- Additional fieldsField
.public static java.lang.reflect.Field[] fields(java.lang.Class<?> clazz, java.lang.String[] fieldNames)
Field
's that matches the supplied list of field
names.clazz
- The class that should contain the fields.fieldNames
- The names of the fields that will be returned.null
public static <T> java.lang.reflect.Constructor<T> constructor(java.lang.Class<T> declaringClass, java.lang.Class<?>... parameterTypes)
declaringClass
- The declaringClass of the class where the constructor is
located.parameterTypes
- All parameter types of the constructor (may be
null
).java.lang.reflect.Constructor
.ConstructorNotFoundException
- if the constructor cannot be found.public static <T> java.lang.reflect.Constructor<T> constructor(java.lang.Class<T> declaringClass)
declaringClass
but you don't care which parameters it take.declaringClass
- The declaringClass of the class where the constructor is
located.java.lang.reflect.Constructor
.TooManyConstructorsFoundException
- If more than one constructor was present in
declaringClass
public static <T> java.lang.reflect.Constructor<T> defaultConstructorIn(java.lang.Class<T> declaringClass)
declaringClass
declaringClass
- The declaringClass of the class where the constructor is
located.java.lang.reflect.Constructor
.ConstructorNotFoundException
- If no default constructor was found in declaringClass
public static java.lang.reflect.Constructor<?>[] constructorsDeclaredIn(java.lang.Class<?> cls, java.lang.Class<?>... additionalClasses)
cls
- The class whose constructors to get.additionalClasses
- Additional classes whose constructors to get.public static java.lang.reflect.Constructor<?>[] constructors(java.lang.reflect.Constructor<?> constructor, java.lang.reflect.Constructor<?>... additionalConstructors)
constructor
- The first constructor.additionalConstructors
- Additional constructorsjava.lang.reflect.Constructor
.public static java.lang.reflect.AccessibleObject[] everythingDeclaredIn(java.lang.Class<?> cls, java.lang.Class<?>... additionalClasses)
cls
- The class whose constructors and methods to get.additionalClasses
- Additional classes whose constructors and methods to get.private static java.lang.String[] merge(java.lang.String first, java.lang.String... additional)
private static java.lang.reflect.Method[] merge(java.lang.reflect.Method first, java.lang.reflect.Method... additional)
private static java.lang.reflect.Field[] merge(java.lang.reflect.Field first, java.lang.reflect.Field... additional)
private static java.lang.reflect.Constructor<?>[] merge(java.lang.reflect.Constructor<?> first, java.lang.reflect.Constructor<?>... additional)