List of utility methods to do Reflection Annotation
String | getAnnotationFullname(Annotation annotation) get Annotation Fullname return getAnnotationFullname(annotation.annotationType());
|
T | getAnnotationInClass(final Class Checks if class is noted by annotationClass .
Class<?> baseClass = clazz; while (baseClass != null && !baseClass.equals(Object.class)) { if (baseClass.isAnnotationPresent(annotationClass)) { return baseClass.getAnnotation(annotationClass); for (Class<?> iClass : baseClass.getInterfaces()) { final T tAnnotation = getAnnotationInClass(annotationClass, iClass); if (tAnnotation != null) { ... |
Annotation | getAnnotationInHeirarchy(Class annotationClass, Class aClass) get Annotation In Heirarchy if (aClass.equals(Object.class)) return null; if (aClass.getAnnotation(annotationClass) != null) { return aClass.getAnnotation(annotationClass); if (aClass.getSuperclass() != null) { Annotation annotation = getAnnotationInHeirarchy(annotationClass, aClass.getSuperclass()); if (annotation != null) { ... |
A | getAnnotationInherited(Class> type, Class annotationClass) get Annotation Inherited A ann = type.getAnnotation(annotationClass); if (ann != null) { return ann; Class<?> superClass = type.getSuperclass(); if (superClass != null) { ann = getAnnotationInherited(superClass, annotationClass); if (ann != null) { ... |
Set | getAnnotationInstances(Class> clazz, Class get Annotation Instances Set<T> annotationInstances = new HashSet<T>(); for (Class<?> clazzClass : clazz.getInterfaces()) { if (clazzClass.isAnnotationPresent(annotationClass)) { annotationInstances.add(clazzClass.getAnnotation(annotationClass)); if (clazz.isAnnotationPresent(annotationClass)) { annotationInstances.add(clazz.getAnnotation(annotationClass)); ... |
Map | getAnnotationMemberDefaults(Annotation annotation) get Annotation Member Defaults Field[] fields = annotation.getClass().getSuperclass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); Object instance = field.get(annotation); if (isAnnotationInvocationHandler(instance.getClass())) { Field typeField = instance.getClass().getDeclaredField("type"); typeField.setAccessible(true); Object typeInstance = typeField.get(instance); ... |
Class> | getAnnotationMemberType(Annotation annotation, String memberName) return the type of an annotation member, or null if the member is not found in the annotation Class<? extends Annotation> annotationType = annotation.annotationType(); return getAnnotationMemberType(annotationType, memberName); |
Annotation | getAnnotationMetaAnnotated( AnnotatedElement annotatedElementClass, Class Finds a annotation meta-annotated on the given annotated element. Annotation[] annotations = annotatedElementClass.getAnnotations(); for (Annotation annotation : annotations) { Annotation[] metaAnnotations = annotation.annotationType().getAnnotations(); for (Annotation metaAnnotation : metaAnnotations) { if (metaAnnotation.annotationType().equals(metaAnnotationToFind)) { return annotation; return null; |
Map | getAnnotationMethods(Class extends Annotation> annotationType) get Annotation Methods Map<String, Method> annotationMethods = reflexionCache.get(annotationType); if (annotationMethods == null) { annotationMethods = new HashMap<String, Method>(); for (Method method : annotationType.getMethods()) { if (method.getParameterTypes().length == 0 && method.getReturnType().equals(Void.class) == false) { String methName = method.getName(); if (methName.equals("equals") || methName.equals("toString") || methName.equals("hashCode") || methName.equals("annotationType")) { ... |
T | getAnnotationOfField(Field field, Class get Annotation Of Field for (Annotation annotation : field.getDeclaredAnnotations()) { if (annotation.annotationType() == clazz) { return clazz.cast(annotation); return null; |