All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.net.bluesoft.rnd.pt.utils.jdbc.helper.Classes Maven / Gradle / Ivy

There is a newer version: 3.2-RC1
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy