edu.mit.csail.sdg.squander.utils.ReflectionUtils Class Reference
[Utils]

Collaboration diagram for edu.mit.csail.sdg.squander.utils.ReflectionUtils:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static Field getFieldWithAccess (Object obj, String fieldName)
static Field getFieldWithAccess (Class<?> cls, String fieldName)
static Field getField (Class<?> cls, String fieldName)
static< R > R getFieldValue (Object obj, Field field)
static< R > R getFieldValue (Object obj, String fieldName)
static void setFieldValue (Object obj, String field, Object value)
static void setFieldValue (Object obj, Field field, Object value)
static Field[] getAllFields (Class<?> clz)
static Field[] getAllNonStaticFields (Class<?> clz)
static Field[] getDeclaredNonStaticFields (Class<?> clz)
static Method getMethod (Class<?extends Object > clz, String methodName, Class<?>[] methodArgs) throws NoSuchMethodException
static Method findMethod (Class<?> clz, String methodName, Class<?>[] methodParams) throws NoSuchMethodException
static Class<?> box (Class<?> c)
static Object invoke (Object obj, String method, Class<?>[] params, Object[] args)
static Object invoke_ex (Object obj, String method, Class<?>[] params, Object[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
static Object createObjectDefaultConstructor (Class<?> clz)
static Object createNewArray (Class<?> componentType, int len)
static< T, K > T newInstance (Class< T > clz, Class< K > argType, K arg)
static< T > T newInstance (Class< T > clz, Object[] args)
static< T > T newInstance (Class< T > clz, Class<?>[] argTypes, Object[] args)
static< T, K, V > T newInstance (Class< T > clz, Class< K > arg1Type, Class< V > arg2Type, K arg1, V arg2)
static Method getAnnotatedMethod (Class<?> owner, Class<?extends Annotation > annotation)
static Method[] getAnnotatedMethods (Class<?> owner, Class<?extends Annotation > annotation)
static boolean isPrimitive (Class<?> type)
static Class lca (Class clz1, Class clz2)
static String sig (Method method)
static Collection< Class<?> > getImmParents (Class<?> clz)
static Collection< Type > getImmGenericParents (Class<?> cls)
static String toString (Object obj)

Static Package Attributes

static Map< Class<?>, Map
< String, Field > > 
cache = new HashMap<Class<?>, Map<String, Field>>()

Static Private Member Functions

static void getAllFieldsRecursive (Class<?> clz, List< Field > fldLst)
static boolean paramsMatch (Class<?> declared, Class<?> actual)
static void printObj (Object obj, StringBuilder sb, String indent, IdentityHashSet< Object > visited)

Static Private Attributes

static final String tab = " "

Detailed Description

Author:
Aleksandar Milicevic <aca.milicevic@gmail.com>

Definition at line 29 of file ReflectionUtils.java.


Member Function Documentation

static Class<?> edu.mit.csail.sdg.squander.utils.ReflectionUtils.box ( Class<?>  c  )  [static]
static Object edu.mit.csail.sdg.squander.utils.ReflectionUtils.createNewArray ( Class<?>  componentType,
int  len 
) [static]

Definition at line 301 of file ReflectionUtils.java.

static Object edu.mit.csail.sdg.squander.utils.ReflectionUtils.createObjectDefaultConstructor ( Class<?>  clz  )  [static]

Creates object of the class clz using default constructor

If there is any problem during object construction, a RuntimeException is thrown

Parameters:
clz -the class of object
Returns:
- created object

Definition at line 288 of file ReflectionUtils.java.

static Method edu.mit.csail.sdg.squander.utils.ReflectionUtils.findMethod ( Class<?>  clz,
String  methodName,
Class<?>[]  methodParams 
) throws NoSuchMethodException [static]
static Field [] edu.mit.csail.sdg.squander.utils.ReflectionUtils.getAllFields ( Class<?>  clz  )  [static]
static void edu.mit.csail.sdg.squander.utils.ReflectionUtils.getAllFieldsRecursive ( Class<?>  clz,
List< Field >  fldLst 
) [static, private]
static Field [] edu.mit.csail.sdg.squander.utils.ReflectionUtils.getAllNonStaticFields ( Class<?>  clz  )  [static]
static Method edu.mit.csail.sdg.squander.utils.ReflectionUtils.getAnnotatedMethod ( Class<?>  owner,
Class<?extends Annotation >  annotation 
) [static]

Finds method in class owner that contains given annotation. There must be at most one annotation of the given type in the class. If there are more methods that contain same annotation, RuntimeException is thrown. In this case, it would good to use getAnnotatedMethods(Class, Class) method

Parameters:
owner 
annotation 
Returns:
See also:
getAnnotatedMethods(Class, Class)

Definition at line 354 of file ReflectionUtils.java.

static Method [] edu.mit.csail.sdg.squander.utils.ReflectionUtils.getAnnotatedMethods ( Class<?>  owner,
Class<?extends Annotation >  annotation 
) [static]

Definition at line 368 of file ReflectionUtils.java.

static Field [] edu.mit.csail.sdg.squander.utils.ReflectionUtils.getDeclaredNonStaticFields ( Class<?>  clz  )  [static]

Definition at line 162 of file ReflectionUtils.java.

static Field edu.mit.csail.sdg.squander.utils.ReflectionUtils.getField ( Class<?>  cls,
String  fieldName 
) [static]

Gets field from class cls, either declared in cls or in one of its superclasses

Parameters:
cls - declaring class of the field
fieldName - name of the field
Returns:
requested field

Definition at line 51 of file ReflectionUtils.java.

References edu.mit.csail.sdg.squander.utils.ReflectionUtils.cache.

Referenced by edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldValue(), edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldWithAccess(), and edu.mit.csail.sdg.squander.utils.ReflectionUtils.setFieldValue().

static <R> R edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldValue ( Object  obj,
String  fieldName 
) [static]
static <R> R edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldValue ( Object  obj,
Field  field 
) [static]
static Field edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldWithAccess ( Class<?>  cls,
String  fieldName 
) [static]
static Field edu.mit.csail.sdg.squander.utils.ReflectionUtils.getFieldWithAccess ( Object  obj,
String  fieldName 
) [static]

Definition at line 33 of file ReflectionUtils.java.

static Collection<Type> edu.mit.csail.sdg.squander.utils.ReflectionUtils.getImmGenericParents ( Class<?>  cls  )  [static]

Definition at line 434 of file ReflectionUtils.java.

static Collection<Class<?> > edu.mit.csail.sdg.squander.utils.ReflectionUtils.getImmParents ( Class<?>  clz  )  [static]

Definition at line 425 of file ReflectionUtils.java.

static Method edu.mit.csail.sdg.squander.utils.ReflectionUtils.getMethod ( Class<?extends Object >  clz,
String  methodName,
Class<?>[]  methodArgs 
) throws NoSuchMethodException [static]

Gets method from class clz or any of its superclasses. If no method can be found NoSuchMethodException is raised.

Parameters:
clz - declaring class of the method
methodName - name of the method
methodArgs - method arguments
Returns:
requested method
Exceptions:
NoSuchMethodException 

Definition at line 186 of file ReflectionUtils.java.

static Object edu.mit.csail.sdg.squander.utils.ReflectionUtils.invoke ( Object  obj,
String  method,
Class<?>[]  params,
Object[]  args 
) [static]

Invokes method of a given obj and set of parameters

Parameters:
obj - Object for which the method is going to be executed. Special if obj is of type java.lang.Class, method is executed as static method of class given as obj parameter
method - name of the object
params - actual parameters for the method
Returns:
- result of the method execution

If there is any problem with method invocation, a RuntimeException is thrown

Definition at line 255 of file ReflectionUtils.java.

References edu.mit.csail.sdg.squander.utils.ReflectionUtils.invoke_ex().

static Object edu.mit.csail.sdg.squander.utils.ReflectionUtils.invoke_ex ( Object  obj,
String  method,
Class<?>[]  params,
Object[]  args 
) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException [static]
static boolean edu.mit.csail.sdg.squander.utils.ReflectionUtils.isPrimitive ( Class<?>  type  )  [static]

Definition at line 379 of file ReflectionUtils.java.

static Class edu.mit.csail.sdg.squander.utils.ReflectionUtils.lca ( Class  clz1,
Class  clz2 
) [static]

Lowest common ancestor of two classes in the type lattice.

Definition at line 392 of file ReflectionUtils.java.

static <T,K,V> T edu.mit.csail.sdg.squander.utils.ReflectionUtils.newInstance ( Class< T >  clz,
Class< K >  arg1Type,
Class< V >  arg2Type,
arg1,
arg2 
) [static]

Definition at line 332 of file ReflectionUtils.java.

static <T> T edu.mit.csail.sdg.squander.utils.ReflectionUtils.newInstance ( Class< T >  clz,
Class<?>[]  argTypes,
Object[]  args 
) [static]

Definition at line 322 of file ReflectionUtils.java.

static <T> T edu.mit.csail.sdg.squander.utils.ReflectionUtils.newInstance ( Class< T >  clz,
Object[]  args 
) [static]
static <T,K> T edu.mit.csail.sdg.squander.utils.ReflectionUtils.newInstance ( Class< T >  clz,
Class< K >  argType,
arg 
) [static]
static boolean edu.mit.csail.sdg.squander.utils.ReflectionUtils.paramsMatch ( Class<?>  declared,
Class<?>  actual 
) [static, private]
static void edu.mit.csail.sdg.squander.utils.ReflectionUtils.printObj ( Object  obj,
StringBuilder  sb,
String  indent,
IdentityHashSet< Object >  visited 
) [static, private]
static void edu.mit.csail.sdg.squander.utils.ReflectionUtils.setFieldValue ( Object  obj,
Field  field,
Object  value 
) [static]

Definition at line 110 of file ReflectionUtils.java.

static void edu.mit.csail.sdg.squander.utils.ReflectionUtils.setFieldValue ( Object  obj,
String  field,
Object  value 
) [static]
static String edu.mit.csail.sdg.squander.utils.ReflectionUtils.sig ( Method  method  )  [static]

Returns method signature as string

Definition at line 415 of file ReflectionUtils.java.

static String edu.mit.csail.sdg.squander.utils.ReflectionUtils.toString ( Object  obj  )  [static]

Member Data Documentation

Map<Class<?>, Map<String, Field> > edu.mit.csail.sdg.squander.utils.ReflectionUtils.cache = new HashMap<Class<?>, Map<String, Field>>() [static, package]
final String edu.mit.csail.sdg.squander.utils.ReflectionUtils.tab = " " [static, private]

The documentation for this class was generated from the following file:
Generated by  doxygen 1.6.2-20100208