Package com.tngtech.jgiven.impl.util
Class ReflectionUtil
java.lang.Object
com.tngtech.jgiven.impl.util.ReflectionUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindMethodTransitively(Class<?> clazz, String methodName) static voidforEachField(Object object, Class<?> clazz, ReflectionUtil.FieldPredicate predicate, ReflectionUtil.FieldAction action) Iterates over all fields of the given class and all its super classes and calls action.act() for the fields that are annotated with the given annotation.static voidforEachMethod(Object object, Class<?> clazz, Class<? extends Annotation> annotation, ReflectionUtil.MethodAction action) Iterates over all methods of the given class and all its super classes and calls action.act() for the methods that are annotated with the given annotation.static voidforEachSuperClass(Class<?> clazz, ReflectionUtil.ClassAction action) Iterates over all super classes of the given class (including the class itself) and calls action.act() for these classes.getAllFieldNames(Iterable<Field> fields) getAllFieldValues(Object target, Iterable<Field> fields, String errorDescription) getAllNonStaticFields(Class<?> clazz) getAllNonStaticFieldValuesFrom(Class<?> clazz, Object target, String errorDescription) static ObjectgetFieldValueOrNull(Field field, Object target, String errorDescription) static ObjectgetFieldValueOrNull(String fieldName, Object target, String errorDescription) getNonStaticMethod(Method[] declaredMethods) hasAtLeastOneAnnotation(Class<? extends Annotation>... annotation) static booleanhasConstructor(Class<?> type, Class<?>... parameterTypes) static voidinvokeMethod(Object object, Method method, String errorDescription) static voidmakeAccessible(AccessibleObject object, String errorDescription) static <T> TnewInstance(Class<T> type) static <T> TnewInstance(Class<T> type, Class<?>[] parameterTypes, Object... parameterValues) static voidstatic StringtoReadableString(AccessibleObject object)
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
forEachField
public static void forEachField(Object object, Class<?> clazz, ReflectionUtil.FieldPredicate predicate, ReflectionUtil.FieldAction action) Iterates over all fields of the given class and all its super classes and calls action.act() for the fields that are annotated with the given annotation. -
forEachMethod
public static void forEachMethod(Object object, Class<?> clazz, Class<? extends Annotation> annotation, ReflectionUtil.MethodAction action) Iterates over all methods of the given class and all its super classes and calls action.act() for the methods that are annotated with the given annotation. -
forEachSuperClass
Iterates over all super classes of the given class (including the class itself) and calls action.act() for these classes. -
hasAtLeastOneAnnotation
@SafeVarargs public static ReflectionUtil.FieldPredicate hasAtLeastOneAnnotation(Class<? extends Annotation>... annotation) -
allFields
-
nonStaticField
-
hasConstructor
-
findMethodTransitively
-
newInstance
-
newInstance
-
invokeMethod
-
getAllNonStaticFieldValuesFrom
public static List<Object> getAllNonStaticFieldValuesFrom(Class<?> clazz, Object target, String errorDescription) Returns aListof objects reflecting all the non-static field values declared by the class or interface represented by the givenClassobject and defined by the givenObject. This includespublic,protected, default (package) access, andprivatefields, but excludes inherited fields. The elements in theListreturned are not sorted and are not in any particular order. This method returns an emptyListif the class or interface declares no fields, or if the givenClassobject represents a primitive type, an array class, or void.- Parameters:
clazz- class or interface declaring fieldstarget- instance of givenclazzfrom which field values should be retrievederrorDescription- customizable part of logged error message- Returns:
- a
Listcontaining all the found field values (nevernull)
-
getFieldValueOrNull
-
getFieldValueOrNull
-
getAllNonStaticFields
-
getAllFieldValues
-
getAllFieldNames
-
setField
-
makeAccessible
-
toReadableString
-
getNonStaticMethod
-