Package org.codehaus.plexus.util
Class ReflectionUtils
- java.lang.Object
-
- org.codehaus.plexus.util.ReflectionUtils
-
public final class ReflectionUtils extends Object
Operations on a class' fields and their setters.- Author:
- Michal Maczka, Jesse McConnell, Trygve Laugstøl
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldgetFieldByNameIncludingSuperclasses(String fieldName, Class<?> clazz)static List<Field>getFieldsIncludingSuperclasses(Class<?> clazz)static MethodgetSetter(String fieldName, Class<?> clazz)Finds a setter in the given class for the given field.static List<Method>getSetters(Class<?> clazz)static Class<?>getSetterType(Method method)static ObjectgetValueIncludingSuperclasses(String variable, Object object)Generates a map of the fields and values on a given object, also pulls from superclassesstatic Map<String,Object>getVariablesAndValuesIncludingSuperclasses(Object object)Generates a map of the fields and values on a given object, also pulls from superclassesstatic booleanisSetter(Method method)static voidsetVariableValueInObject(Object object, String variable, Object value)attempts to set the value to the variable in the object passed in
-
-
-
Method Detail
-
getFieldByNameIncludingSuperclasses
public static Field getFieldByNameIncludingSuperclasses(String fieldName, Class<?> clazz)
-
getFieldsIncludingSuperclasses
public static List<Field> getFieldsIncludingSuperclasses(Class<?> clazz)
-
getSetter
public static Method getSetter(String fieldName, Class<?> clazz)
Finds a setter in the given class for the given field. It searches interfaces and superclasses too.- Parameters:
fieldName- the name of the field (i.e. 'fooBar'); it will search for a method named 'setFooBar'.clazz- The class to find the method in.- Returns:
- null or the method found.
-
getSetters
public static List<Method> getSetters(Class<?> clazz)
- Parameters:
clazz- the Class- Returns:
- all setters in the given class and super classes.
-
getSetterType
public static Class<?> getSetterType(Method method)
- Parameters:
method- the method- Returns:
- the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter.
-
setVariableValueInObject
public static void setVariableValueInObject(Object object, String variable, Object value) throws IllegalAccessException
attempts to set the value to the variable in the object passed in- Parameters:
object- see namevariable- see namevalue- see name- Throws:
IllegalAccessException- if error
-
getValueIncludingSuperclasses
public static Object getValueIncludingSuperclasses(String variable, Object object) throws IllegalAccessException
Generates a map of the fields and values on a given object, also pulls from superclasses- Parameters:
variable- field nameobject- the object to generate the list of fields from- Returns:
- map containing the fields and their values
- Throws:
IllegalAccessException- cannot access
-
getVariablesAndValuesIncludingSuperclasses
public static Map<String,Object> getVariablesAndValuesIncludingSuperclasses(Object object) throws IllegalAccessException
Generates a map of the fields and values on a given object, also pulls from superclasses- Parameters:
object- the object to generate the list of fields from- Returns:
- map containing the fields and their values
- Throws:
IllegalAccessException- cannot access
-
isSetter
public static boolean isSetter(Method method)
-
-