de.bechte.junit.runners.util
Class ReflectionUtil

java.lang.Object
  extended by de.bechte.junit.runners.util.ReflectionUtil

public final class ReflectionUtil
extends Object

Set of helper methods to retrieve information using Java's reflection API.


Method Summary
static Object createDeepInstance(Stack<Class<?>> classHierarchy)
          Returns an instance of the Class, represented by the given class hierarchy.
static Stack<Class<?>> getClassHierarchy(Class<?> clazz)
          Returns a Stack of classes, representing the hierarchy of the given Class.
static Object getEnclosingInstance(Object target)
          Returns the Object that encloses the given target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEnclosingInstance

public static Object getEnclosingInstance(Object target)
                                   throws IllegalAccessException
Returns the Object that encloses the given target. This method returns null if the given target is null or its Class is not a member class.

Parameters:
target - theĀ Object to retrieve the enclosing instance for
Returns:
the enclosing Object of target
Throws:
IllegalArgumentException - If target is null.
IllegalAccessException - An instance of the enclosing class is kept in a private field within the enclosed instance. Accessing the field might throw an IllegalAccessException.
IllegalStateException - If no field containing the enclosing instance can be found.

getClassHierarchy

public static Stack<Class<?>> getClassHierarchy(Class<?> clazz)
Returns a Stack of classes, representing the hierarchy of the given Class.

Parameters:
clazz - the Class to retrieve the hierarchy for
Returns:
the Class hierarchy

createDeepInstance

public static Object createDeepInstance(Stack<Class<?>> classHierarchy)
                                 throws Throwable
Returns an instance of the Class, represented by the given class hierarchy.

Parameters:
classHierarchy - the hierarchy representing a deep class
Returns:
the newly created instance
Throws:
Throwable - if errors occurred during construction of the instance


Copyright © 2015. All rights reserved.