Class Reflections
- java.lang.Object
-
- org.zkoss.zats.common.select.impl.Reflections
-
public class Reflections extends Object
A collection of reflection utilities.- Since:
- 6.0.0
- Author:
- simonpai
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceReflections.FieldRunner<A extends Annotation>static interfaceReflections.MethodRunner<A extends Annotation>
-
Constructor Summary
Constructors Constructor Description Reflections()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddToCollectionField(Object owner, Field field, Object item)Add the item to a collection field of an object.static <A extends Annotation>
voidforFields(Class<?> clazz, Class<A> annotationClass, Reflections.FieldRunner<A> runner)Traverse through all fields with a certain annotation in a class and it super classes.static <A extends Annotation>
voidforMethods(Class<?> clazz, Class<A> annotationClass, Reflections.MethodRunner<A> runner)Traverse through all methods with a certain annotation in a class, including ones inherited from its super class.static Class<?>getClass(Type type)Return the Class representing the given Type.static ObjectgetFieldValue(Object bean, Field field)Get field value.static voidinvokeMethod(Method method, Object bean, Object... arguments)Invoke a method reflexively.static booleanisAppendableToCollection(Type type, Object object)Return true if field is of Collection type, and an object of type clazz can be added into the Collection.static booleanisPassableToMethod(Method method, Object... arguments)Return true if the given arguments can be passed as the arguments of the method.static voidsetFieldValue(Object bean, Field field, Object value)Set a value to a field of the object.
-
-
-
Method Detail
-
forFields
public static <A extends Annotation> void forFields(Class<?> clazz, Class<A> annotationClass, Reflections.FieldRunner<A> runner)
Traverse through all fields with a certain annotation in a class and it super classes. Subclass first. If a field is re-declared in subclass, it will be skipped at the superclass.
-
forMethods
public static <A extends Annotation> void forMethods(Class<?> clazz, Class<A> annotationClass, Reflections.MethodRunner<A> runner)
Traverse through all methods with a certain annotation in a class, including ones inherited from its super class.
-
isAppendableToCollection
public static boolean isAppendableToCollection(Type type, Object object)
Return true if field is of Collection type, and an object of type clazz can be added into the Collection.
-
isPassableToMethod
public static boolean isPassableToMethod(Method method, Object... arguments)
Return true if the given arguments can be passed as the arguments of the method.
-
setFieldValue
public static void setFieldValue(Object bean, Field field, Object value)
Set a value to a field of the object.
-
addToCollectionField
public static void addToCollectionField(Object owner, Field field, Object item)
Add the item to a collection field of an object.
-
invokeMethod
public static void invokeMethod(Method method, Object bean, Object... arguments)
Invoke a method reflexively.
-
-