Class ReflectionHelper
java.lang.Object
clazzfish.monitor.util.ReflectionHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic FieldTries to get the wanted field.static ObjectgetFieldValue(Object target, String name) If it can it returns the value of the given field.static ObjectGets the id of the given object.static MethodGets the method.static MethodGets the method.static Collection<Field> To get all uninitialized field you can call this method.static booleanReturns true if the given class have a field with the given name.static booleanReturns true if the given object have a field with the given name.static booleanChecks if the given class has something which looks like an id attribute.static booleanChecks if the given object has something which looks like an id.static ObjectinvokeMethod(Object target, String name, Object... args) Invoke method.static booleanChecks if the given field is static.static voidsetFieldValue(Object target, String name, String value) Sets the field value of the given target.static StringtoShortString(Field field) To short string.static StringtoShortString(Collection<Field> fields) To short string.
-
Method Details
-
getField
Tries to get the wanted field.- Parameters:
cl- the classname- the field name- Returns:
- the wanted field
- Throws:
NoSuchFieldException- if the field was not found
-
hasField
-
hasField
-
getFieldValue
If it can it returns the value of the given field. If not it throws an exception.- Parameters:
target- the target objectname- the name- Returns:
- the field value
- Throws:
ReflectiveOperationException- the reflective operation exception
-
setFieldValue
public static void setFieldValue(Object target, String name, String value) throws ReflectiveOperationException Sets the field value of the given target. With this method you can set private attributes, e.g. for testing.- Parameters:
target- the targetname- the namevalue- the value- Throws:
ReflectiveOperationException- the reflective operation exception- Since:
- 1.6
-
getUninitializedNonStaticFields
To get all uninitialized field you can call this method.- Parameters:
obj- the object where to get the fields from- Returns:
- a collecion of unitialized fields (can be empty)
-
isStatic
Checks if the given field is static.- Parameters:
field- the field- Returns:
- true, if is static
-
toShortString
-
toShortString
To short string.- Parameters:
fields- the fields- Returns:
- the string
-
getMethod
public static Method getMethod(Class<?> cl, String name, Object... args) throws NoSuchMethodException Gets the method.- Parameters:
cl- the clname- the nameargs- the args- Returns:
- the method
- Throws:
NoSuchMethodException- the no such method exception
-
getMethod
public static Method getMethod(Class<?> cl, String name, Class<?>... parameterTypes) throws NoSuchMethodException Gets the method.- Parameters:
cl- e.g. class java.lang.ClassLoadername- e.g. "getPackages"parameterTypes- the parameter types- Returns:
- a Method object
- Throws:
NoSuchMethodException- the no such method exception
-
invokeMethod
-
hasId
Checks if the given object has something which looks like an id.- Parameters:
obj- the obj- Returns:
- true, if successful
- Since:
- 1.6 (01.06.2015)
-
hasId
Checks if the given class has something which looks like an id attribute.- Parameters:
clazz- the clazz- Returns:
- true, if successful
-
getId
-