public static <T extends Annotation> DeclaredAnnotation<T> getConstructorAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { T annotation = constructor.getAnnotation(annotationClass); if (annotation != null) { declaredAnnotation = new DeclaredAnnotation<T>(annotation, constructor, clazz); break; } } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getConstructorAnnotation(clazz.getSuperclass(), annotationClass); return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getConstructorAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { T annotation = constructor.getAnnotation(annotationClass); if (annotation != null) { declaredAnnotation = new DeclaredAnnotation<T>(annotation, constructor, clazz); break; } } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getConstructorAnnotation(clazz.getSuperclass(), annotationClass); return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getConstructorAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { T annotation = constructor.getAnnotation(annotationClass); if (annotation != null) { declaredAnnotation = new DeclaredAnnotation<T>(annotation, constructor, clazz); break; } } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getConstructorAnnotation(clazz.getSuperclass(), annotationClass); return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getConstructorAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { T annotation = constructor.getAnnotation(annotationClass); if (annotation != null) { declaredAnnotation = new DeclaredAnnotation<T>(annotation, constructor, clazz); break; } } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getConstructorAnnotation(clazz.getSuperclass(), annotationClass); return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getAnnotation(AnnotatedElement elmt, Class<T> annotationClass) { T annotation = elmt.getAnnotation(annotationClass); if (annotation != null) { Class<?> declaringClass = (elmt instanceof Member ? ((Member)elmt).getDeclaringClass() : (Class<?>)elmt); return new DeclaredAnnotation<T>(annotation, elmt, declaringClass); } if (elmt instanceof Field) return null; if (elmt instanceof Method) { Method m = (Method)elmt; return getMethodAnnotation(m.getDeclaringClass(), m.getName(), m.getParameterTypes(), annotationClass); } if (elmt instanceof Constructor) { Constructor<?> c = (Constructor<?>)elmt; return getConstructorAnnotation(c.getDeclaringClass(), annotationClass); } if (elmt instanceof Class) { Class<?> c = (Class<?>)elmt; return getClassAnnotation(c.getDeclaringClass(), annotationClass); } throw new RuntimeException("Unsupported annotated element: " + elmt); }
public static <T extends Annotation> DeclaredAnnotation<T> getAnnotation(AnnotatedElement elmt, Class<T> annotationClass) { T annotation = elmt.getAnnotation(annotationClass); if (annotation != null) { Class<?> declaringClass = (elmt instanceof Member ? ((Member)elmt).getDeclaringClass() : (Class<?>)elmt); return new DeclaredAnnotation<T>(annotation, elmt, declaringClass); } if (elmt instanceof Field) return null; if (elmt instanceof Method) { Method m = (Method)elmt; return getMethodAnnotation(m.getDeclaringClass(), m.getName(), m.getParameterTypes(), annotationClass); } if (elmt instanceof Constructor) { Constructor<?> c = (Constructor<?>)elmt; return getConstructorAnnotation(c.getDeclaringClass(), annotationClass); } if (elmt instanceof Class) { Class<?> c = (Class<?>)elmt; return getClassAnnotation(c.getDeclaringClass(), annotationClass); } throw new RuntimeException("Unsupported annotated element: " + elmt); }
public static <T extends Annotation> DeclaredAnnotation<T> getAnnotation(AnnotatedElement elmt, Class<T> annotationClass) { T annotation = elmt.getAnnotation(annotationClass); if (annotation != null) { Class<?> declaringClass = (elmt instanceof Member ? ((Member)elmt).getDeclaringClass() : (Class<?>)elmt); return new DeclaredAnnotation<T>(annotation, elmt, declaringClass); } if (elmt instanceof Field) return null; if (elmt instanceof Method) { Method m = (Method)elmt; return getMethodAnnotation(m.getDeclaringClass(), m.getName(), m.getParameterTypes(), annotationClass); } if (elmt instanceof Constructor) { Constructor<?> c = (Constructor<?>)elmt; return getConstructorAnnotation(c.getDeclaringClass(), annotationClass); } if (elmt instanceof Class) { Class<?> c = (Class<?>)elmt; return getClassAnnotation(c.getDeclaringClass(), annotationClass); } throw new RuntimeException("Unsupported annotated element: " + elmt); }
public static <T extends Annotation> DeclaredAnnotation<T> getAnnotation(AnnotatedElement elmt, Class<T> annotationClass) { T annotation = elmt.getAnnotation(annotationClass); if (annotation != null) { Class<?> declaringClass = (elmt instanceof Member ? ((Member)elmt).getDeclaringClass() : (Class<?>)elmt); return new DeclaredAnnotation<T>(annotation, elmt, declaringClass); } if (elmt instanceof Field) return null; if (elmt instanceof Method) { Method m = (Method)elmt; return getMethodAnnotation(m.getDeclaringClass(), m.getName(), m.getParameterTypes(), annotationClass); } if (elmt instanceof Constructor) { Constructor<?> c = (Constructor<?>)elmt; return getConstructorAnnotation(c.getDeclaringClass(), annotationClass); } if (elmt instanceof Class) { Class<?> c = (Class<?>)elmt; return getClassAnnotation(c.getDeclaringClass(), annotationClass); } throw new RuntimeException("Unsupported annotated element: " + elmt); }