pl.net.bluesoft.rnd.pt.utils.jdbc.helper.Classes Maven / Gradle / Ivy
package pl.net.bluesoft.rnd.pt.utils.jdbc.helper;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class Classes {
public static A getClassAnnotation(Class clazz, Class annotation) {
while (clazz != null && Object.class != clazz) {
if (clazz.isAnnotationPresent(annotation)) {
return (A) clazz.getAnnotation(annotation);
}
clazz = clazz.getSuperclass();
}
return null;
}
public static java.lang.reflect.Field getFieldWithAnnotation(Class clazz, Class annotation) {
List fields = new LinkedList(Arrays.asList(clazz.getDeclaredFields()));
for (Iterator it = fields.iterator(); it.hasNext(); ) {
java.lang.reflect.Field field = it.next();
if (field.isAnnotationPresent(annotation)) {
return field;
}
}
if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object.class)) {
return getFieldWithAnnotation(clazz.getSuperclass(), annotation);
}
return null;
}
}