Top Description Inners Fields Constructors Methods
org.testng.internal.reflect

public final Class ReflectionRecipes

extends Object
Class Inheritance
Imports
java.lang.reflect.Constructor, .Method, .Parameter, java.util.*, org.testng.ITestContext, .ITestResult, .TestNGException, org.testng.annotations.NoInjection, org.testng.internal.RuntimeBehavior, org.testng.xml.XmlTest

Utility class to handle reflection.
Author
Nitin Verma

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Map<Class<?>, List<Class<?>>>
private static final Map<Class<?>, Class<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
canInject(final Parameter parameter, final InjectableParameter injectableParameter)

public static Class<?>[]

Returns:

parameter types.
classesFromParameters
(final Parameter[]
an array of parameters.
parameters
)

Extracts class instances from parameters.

public static boolean

Returns:

matches or not
exactMatch
(final Parameter[] parameters, final Object[] args)

Matches an array of parameters to an array of instances.

public static boolean

Returns:

matches or not
exactMatch
(final Class<?>[]
array of class instances to check against.
classes
,
final Object[]
instances to be verified.
args
)

Matches an array of class instances to an array of instances.

public static Parameter[]

Returns:

Injects free array of class instances.
filter
(final Parameter[]
array of parameter instances under question.
parameters
,
final Set<InjectableParameter>
filters to use.
filters
)

Omits 1.

public static Parameter[]

Returns:

extracted constructor parameters.
getConstructorParameters
(final Constructor<?>
any valid constructor.
constructor
)

Extracts constructor parameters.

public static Parameter[]

Returns:

extracted method parameters.
getMethodParameters
(final Method
any valid method.
method
)

Extracts method parameters.

private static void
private static void
public static Object[]

Returns:

injected arguments.
inject
(final Parameter[]
array of parameter instances under question.
parameters
,
final Set<InjectableParameter>
filters to use.
filters
,
final Object[]
user supplied arguments.
args
,
final Method
current test method.
injectionMethod
,
final ITestContext
current test context.
context
,
final ITestResult
on going test results.
testResult
)

Injects appropriate arguments.

public static Object[]

Returns:

injected arguments.
inject
(final Parameter[]
array of parameter instances under question.
parameters
,
final Set<InjectableParameter>
filters to use.
filters
,
final Object[]
user supplied arguments.
args
,
final Constructor<?>
current test method.
constructor
,
final ITestContext
current test context.
context
,
final ITestResult
on going test results.
testResult
)

Injects appropriate arguments.

public static boolean

Returns:

is an instance-of or not
isInstanceOf
(final Class<?>
reference class.
reference
,
final Object
instance to be tested.
object
)

Checks if an instance is an instance of the given class.

public static boolean

Returns:

would an instance of 'clazz' be an instance of reference class.
isOrExtends
(final Class<?>
reference class instance.
reference
,
final Class<?>
class instance to be tested.
clazz
)

Checks a class instance for being a given class or its sub-class.

public static boolean

Returns:

would an instance of 'clazz' be an instance of reference interface.
isOrImplementsInterface
(final Class<?>
reference interface instance.
reference
,
final Class<?>
class instance to be tested.
clazz
)

Checks a class instance for being a given interface or its implementation.

public static boolean

Returns:

matches or not
lenientMatch
(final Parameter[] parameters, final Object[] args)

Matches an array of parameters to an array of instances.

public static boolean

Returns:

matches or not
lenientMatch
(final Class<?>[]
array of class instances to check against.
classes
,
final Object[]
instances to be verified.
args
)

Matches an array of class instances to an array of instances.

public static boolean

Returns:

matches or not
matchArrayEnding
(final Parameter[] parameters, final Object[] param)

public static boolean

Returns:

matches or not
matchArrayEnding
(final Class<?>[]
array of class instances to check against.
classes
,
final Object[]
instances to be verified.
args
)

Matches an array of class instances to an array of instances having last class instance an array.

private static Object[]
nativelyInject(final Parameter[] parameters, final Set<InjectableParameter> filters, final Object[] args, final Object injectionMethod, final ITestContext context, final ITestResult testResult)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASSIGNABLE_MAPPINGback to summary
private static final Map<Class<?>, List<Class<?>>> ASSIGNABLE_MAPPING
PRIMITIVE_MAPPINGback to summary
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPING

Constructor Detail

ReflectionRecipesback to summary
private ReflectionRecipes()

Method Detail

canInjectback to summary
private static boolean canInject(final Parameter parameter, final InjectableParameter injectableParameter)
classesFromParametersback to summary
public static Class<?>[] classesFromParameters(final Parameter[] parameters)

Extracts class instances from parameters.

Parameters
parameters:Parameter[]

an array of parameters.

Returns:Class<?>[]

parameter types.

exactMatchback to summary
public static boolean exactMatch(final Parameter[] parameters, final Object[] args)

Matches an array of parameters to an array of instances.

Returns:boolean

matches or not

See Also
exactMatch(Class[], Object[])
exactMatchback to summary
public static boolean exactMatch(final Class<?>[] classes, final Object[] args)

Matches an array of class instances to an array of instances.

Parameters
classes:Class<?>[]

array of class instances to check against.

args:Object[]

instances to be verified.

Returns:boolean

matches or not

filterback to summary
public static Parameter[] filter(final Parameter[] parameters, final Set<InjectableParameter> filters)

Omits 1. org.testng.ITestContext or its implementations from input array 2. org.testng.ITestResult or its implementations from input array 3. org.testng.xml.XmlTest or its implementations from input array 4. First method depending on filters.

An example would be Input: {ITestContext.class, int.class, Boolean.class, TestContext.class} Output: {int.class, Boolean.class}

Parameters
parameters:Parameter[]

array of parameter instances under question.

filters:Set<InjectableParameter>

filters to use.

Returns:Parameter[]

Injects free array of class instances.

getConstructorParametersback to summary
public static Parameter[] getConstructorParameters(final Constructor<?> constructor)

Extracts constructor parameters.

Parameters
constructor:Constructor<?>

any valid constructor.

Returns:Parameter[]

extracted constructor parameters.

getMethodParametersback to summary
public static Parameter[] getMethodParameters(final Method method)

Extracts method parameters.

Parameters
method:Method

any valid method.

Returns:Parameter[]

extracted method parameters.

initAssignableMappingback to summary
private static void initAssignableMapping()
initPrimitiveMappingback to summary
private static void initPrimitiveMapping()
injectback to summary
public static Object[] inject(final Parameter[] parameters, final Set<InjectableParameter> filters, final Object[] args, final Method injectionMethod, final ITestContext context, final ITestResult testResult)

Injects appropriate arguments.

Parameters
parameters:Parameter[]

array of parameter instances under question.

filters:Set<InjectableParameter>

filters to use.

args:Object[]

user supplied arguments.

injectionMethod:Method

current test method.

context:ITestContext

current test context.

testResult:ITestResult

on going test results.

Returns:Object[]

injected arguments.

injectback to summary
public static Object[] inject(final Parameter[] parameters, final Set<InjectableParameter> filters, final Object[] args, final Constructor<?> constructor, final ITestContext context, final ITestResult testResult)

Injects appropriate arguments.

Parameters
parameters:Parameter[]

array of parameter instances under question.

filters:Set<InjectableParameter>

filters to use.

args:Object[]

user supplied arguments.

constructor:Constructor<?>

current test method.

context:ITestContext

current test context.

testResult:ITestResult

on going test results.

Returns:Object[]

injected arguments.

isInstanceOfback to summary
public static boolean isInstanceOf(final Class<?> reference, final Object object)

Checks if an instance is an instance of the given class.

Parameters
reference:Class<?>

reference class.

object:Object

instance to be tested.

Returns:boolean

is an instance-of or not

isOrExtendsback to summary
public static boolean isOrExtends(final Class<?> reference, final Class<?> clazz)

Checks a class instance for being a given class or its sub-class.

Parameters
reference:Class<?>

reference class instance.

clazz:Class<?>

class instance to be tested.

Returns:boolean

would an instance of 'clazz' be an instance of reference class.

isOrImplementsInterfaceback to summary
public static boolean isOrImplementsInterface(final Class<?> reference, final Class<?> clazz)

Checks a class instance for being a given interface or its implementation.

Parameters
reference:Class<?>

reference interface instance.

clazz:Class<?>

class instance to be tested.

Returns:boolean

would an instance of 'clazz' be an instance of reference interface.

lenientMatchback to summary
public static boolean lenientMatch(final Parameter[] parameters, final Object[] args)

Matches an array of parameters to an array of instances.

Returns:boolean

matches or not

See Also
lenientMatch(Class[], Object[])
lenientMatchback to summary
public static boolean lenientMatch(final Class<?>[] classes, final Object[] args)

Matches an array of class instances to an array of instances. Such that {int, boolean, float} matches {int, boolean}

Parameters
classes:Class<?>[]

array of class instances to check against.

args:Object[]

instances to be verified.

Returns:boolean

matches or not

matchArrayEndingback to summary
public static boolean matchArrayEnding(final Parameter[] parameters, final Object[] param)
Returns:boolean

matches or not

See Also
matchArrayEnding(Class[], Object[])
matchArrayEndingback to summary
public static boolean matchArrayEnding(final Class<?>[] classes, final Object[] args)

Matches an array of class instances to an array of instances having last class instance an array.

Assuming upper case letters denote classes and corresponding lowercase its instances. Classes {A,B,C...}, instances {a,b,c1,c2} ==> check for {a,b,{c1,c2}} match or Classes {A,B,C[]}, instances {a,b,c1,c2} ==> check for {a,b,{c1,c2}} match both of the above cases are equivalent.

Parameters
classes:Class<?>[]

array of class instances to check against.

args:Object[]

instances to be verified.

Returns:boolean

matches or not

nativelyInjectback to summary
private static Object[] nativelyInject(final Parameter[] parameters, final Set<InjectableParameter> filters, final Object[] args, final Object injectionMethod, final ITestContext context, final ITestResult testResult)
org.testng.internal.reflect back to summary

private Class ReflectionRecipes.ListBackedImmutableQueue<T>

extends Object
Class Inheritance
  • java.lang.Object
  • org.testng.internal.reflect.ReflectionRecipes.ListBackedImmutableQueue

Field Summary

Modifier and TypeField and Description
private final List<T>

Constructor Summary

AccessConstructor and Description
pack-priv
ListBackedImmutableQueue(final T[] elements)

Method Summary

Modifier and TypeMethod and Description
pack-priv T
poll()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backingListback to summary
private final List<T> backingList

Constructor Detail

ListBackedImmutableQueueback to summary
pack-priv ListBackedImmutableQueue(final T[] elements)

Method Detail

pollback to summary
pack-priv T poll()