com.senseidb.search.client.json.ReflectionUtil Maven / Gradle / Ivy
package com.senseidb.search.client.json;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class ReflectionUtil {
public static Set getAnnotations(Class cls) {
Set ret = new HashSet();
ret.addAll(Arrays.asList(cls.getAnnotations()));
if(cls.getSuperclass() != null) {
ret.addAll(getAnnotations(cls.getSuperclass()));
}
for (Class intrface : cls.getInterfaces()) {
ret.addAll(getAnnotations(intrface));
}
return ret;
}
public static Annotation getAnnotation(Class cls, Class annotationCls) {
if (cls == null) {
return null;
}
Annotation ret = cls.getAnnotation(annotationCls);
if (ret != null) {
return ret;
}
ret = getAnnotation(cls.getSuperclass(), annotationCls);
if (ret != null) {
return ret;
}
for (Class intrface : cls.getInterfaces()) {
ret = getAnnotation(intrface, annotationCls);
if (ret != null) {
return ret;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy