org.powermock.api.support.membermodification
Class MemberMatcher

java.lang.Object
  extended by org.powermock.api.support.membermodification.MemberMatcher
Direct Known Subclasses:
MemberModifier

public class MemberMatcher
extends Object

Finds members in classes.


Constructor Summary
MemberMatcher()
           
 
Method Summary
static
<T> Constructor<T>
constructor(Class<T> declaringClass)
          Returns any one constructor specified in declaringClass.
static
<T> Constructor<T>
constructor(Class<T> declaringClass, Class<?>... parameterTypes)
          Returns a constructor specified in declaringClass.
static Constructor<?>[] constructors(Constructor<?> constructor, Constructor<?>... additionalConstructors)
          Convenience method to get a constructor from a class.
static Constructor<?>[] constructorsDeclaredIn(Class<?> cls, Class<?>... additionalClasses)
          Get all constructors in the supplied class(es).
static
<T> Constructor<T>
defaultConstructorIn(Class<T> declaringClass)
          Returns the default constructor in declaringClass
static AccessibleObject[] everythingDeclaredIn(Class<?> cls, Class<?>... additionalClasses)
          Get all constructors and methods in the supplied class(es).
static Field field(Class<?> declaringClass, String fieldName)
          Get a field from a class.
static Field[] fields(Class<?> clazz)
          Get all fields in a class hierarchy.
static Field[] fields(Class<?> clazz, String[] fieldNames)
          Get an array of Field's that matches the supplied list of field names.
static Field[] fields(Class<?> clazz, String firstFieldName, String... additionalfieldNames)
          Get an array of Field's that matches the supplied list of field names.
static Field[] fields(Field field, Field... additionalFields)
          Get an array of Field's.
static Method method(Class<?> declaringClass, Class<?>... parameterTypes)
          Get a method without having to specify the method name.
static Method method(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)
          Get a method when it cannot be determined by methodName or parameter types only.
static Method[] methods(Class<?> clazz, String[] methodNames)
          Get an array of Method's that matches the supplied list of method names.
static Method[] methods(Class<?> clazz, String methodName, String... additionalMethodNames)
          Get an array of Method's that matches the supplied list of method names.
static Method[] methods(Method method, Method... additionalMethods)
          Get an array of Field's.
static Method[] methodsDeclaredIn(Class<?> cls, Class<?>... additionalClasses)
          Get all methods in a class hierarchy of the supplied classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemberMatcher

public MemberMatcher()
Method Detail

methodsDeclaredIn

public static Method[] methodsDeclaredIn(Class<?> cls,
                                         Class<?>... additionalClasses)
Get all methods in a class hierarchy of the supplied classes. Both declared an non-declared (no duplicates).

Parameters:
cls - The class whose methods to get.
additionalClasses - Additional classes whose methods to get.
Returns:
All methods declared in this class hierarchy.

method

public static Method method(Class<?> declaringClass,
                            String methodName,
                            Class<?>... parameterTypes)
Get a method when it cannot be determined by methodName or parameter types only.

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.

Parameters:
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).
Returns:
A java.lang.reflect.Method.
Throws:
MethodNotFoundException - If a method cannot be found in the hierarchy.

method

public static Method method(Class<?> declaringClass,
                            Class<?>... parameterTypes)
Get a method without having to specify the method name.

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.

Parameters:
declaringClass - The declaringClass of the class where the method is located.
parameterTypes - All parameter types of the method (may be null).
Returns:
A java.lang.reflect.Method.
Throws:
MethodNotFoundException - If a method cannot be found in the hierarchy.
TooManyMethodsFoundException - If several methods were found.

methods

public static Method[] methods(Class<?> clazz,
                               String methodName,
                               String... additionalMethodNames)
Get an array of Method's that matches the supplied list of method names. Both instance and static methods are taken into account.

Parameters:
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.
Returns:
An array of Method's. May be of length 0 but not null.
Throws:
MethodNotFoundException - If no method was found.

methods

public static Method[] methods(Method method,
                               Method... additionalMethods)
Get an array of Field's.

Parameters:
method - The first field.
additionalMethods - Additional fields
Returns:
An array of Field.

methods

public static Method[] methods(Class<?> clazz,
                               String[] methodNames)
Get an array of Method's that matches the supplied list of method names. Both instance and static methods are taken into account.

Parameters:
clazz - The class that should contain the methods.
methodNames - The names of the methods.
Returns:
An array of Method's. May be of length 0 but not null.
Throws:
MethodNotFoundException - If no method was found.

field

public static Field field(Class<?> declaringClass,
                          String fieldName)
Get a field from a class.

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.

Parameters:
declaringClass - The declaringClass of the class where the method is located.
fieldName - The method names.
Returns:
A java.lang.reflect.Field.
Throws:
FieldNotFoundException - If a field cannot be found in the hierarchy.

fields

public static Field[] fields(Class<?> clazz,
                             String firstFieldName,
                             String... additionalfieldNames)
Get an array of Field's that matches the supplied list of field names.

Parameters:
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.
Returns:
An array of Field's. May be of length 0 but not null

fields

public static Field[] fields(Class<?> clazz)
Get all fields in a class hierarchy.

Parameters:
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.
Returns:
An array of Field's. May be of length 0 but not null

fields

public static Field[] fields(Field field,
                             Field... additionalFields)
Get an array of Field's.

Parameters:
field - The first field.
additionalFields - Additional fields
Returns:
An array of Field.

fields

public static Field[] fields(Class<?> clazz,
                             String[] fieldNames)
Get an array of Field's that matches the supplied list of field names.

Parameters:
clazz - The class that should contain the fields.
fieldNames - The names of the fields that will be returned.
Returns:
An array of Field's. May be of length 0 but not null

constructor

public static <T> Constructor<T> constructor(Class<T> declaringClass,
                                             Class<?>... parameterTypes)
Returns a constructor specified in declaringClass.

Parameters:
declaringClass - The declaringClass of the class where the constructor is located.
parameterTypes - All parameter types of the constructor (may be null).
Returns:
A java.lang.reflect.Constructor.
Throws:
ConstructorNotFoundException - if the constructor cannot be found.

constructor

public static <T> Constructor<T> constructor(Class<T> declaringClass)
Returns any one constructor specified in declaringClass. Is is useful when you only have ONE constructor declared in declaringClass but you don't care which parameters it take.

Parameters:
declaringClass - The declaringClass of the class where the constructor is located.
Returns:
A java.lang.reflect.Constructor.
Throws:
TooManyConstructorsFoundException - If more than one constructor was present in declaringClass

defaultConstructorIn

public static <T> Constructor<T> defaultConstructorIn(Class<T> declaringClass)
Returns the default constructor in declaringClass

Parameters:
declaringClass - The declaringClass of the class where the constructor is located.
Returns:
A java.lang.reflect.Constructor.
Throws:
ConstructorNotFoundException - If no default constructor was found in declaringClass

constructorsDeclaredIn

public static Constructor<?>[] constructorsDeclaredIn(Class<?> cls,
                                                      Class<?>... additionalClasses)
Get all constructors in the supplied class(es).

Parameters:
cls - The class whose constructors to get.
additionalClasses - Additional classes whose constructors to get.
Returns:
All constructors declared in this class.

constructors

public static Constructor<?>[] constructors(Constructor<?> constructor,
                                            Constructor<?>... additionalConstructors)
Convenience method to get a constructor from a class.

Parameters:
constructor - The first constructor.
additionalConstructors - Additional constructors
Returns:
An array of java.lang.reflect.Constructor.

everythingDeclaredIn

public static AccessibleObject[] everythingDeclaredIn(Class<?> cls,
                                                      Class<?>... additionalClasses)
Get all constructors and methods in the supplied class(es).

Parameters:
cls - The class whose constructors and methods to get.
additionalClasses - Additional classes whose constructors and methods to get.
Returns:
All constructors and methods declared in this class.


Copyright © 2007-2012. All Rights Reserved.