public static <T extends Annotation> DeclaredAnnotation<T> getMethodAnnotation(Class<?> clazz, String name, Class<?>[] parameterTypes, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; try { Method method = clazz.getDeclaredMethod(name, parameterTypes); T annotation = clazz.getDeclaredMethod(name, parameterTypes).getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, method, clazz); } catch (NoSuchMethodException e) { // fallback... } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getMethodAnnotation(clazz.getSuperclass(), name, parameterTypes, annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getMethodAnnotation(interfaze, name, parameterTypes, annotationClass); if (declaredAnnotation != null) break; } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getMethodAnnotation(Class<?> clazz, String name, Class<?>[] parameterTypes, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; try { Method method = clazz.getDeclaredMethod(name, parameterTypes); T annotation = clazz.getDeclaredMethod(name, parameterTypes).getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, method, clazz); } catch (NoSuchMethodException e) { // fallback... } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getMethodAnnotation(clazz.getSuperclass(), name, parameterTypes, annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getMethodAnnotation(interfaze, name, parameterTypes, annotationClass); if (declaredAnnotation != null) break; } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getMethodAnnotation(Class<?> clazz, String name, Class<?>[] parameterTypes, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; try { Method method = clazz.getDeclaredMethod(name, parameterTypes); T annotation = clazz.getDeclaredMethod(name, parameterTypes).getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, method, clazz); } catch (NoSuchMethodException e) { // fallback... } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getMethodAnnotation(clazz.getSuperclass(), name, parameterTypes, annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getMethodAnnotation(interfaze, name, parameterTypes, annotationClass); if (declaredAnnotation != null) break; } } 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); }
public static <T extends Annotation> DeclaredAnnotation<T> getMethodAnnotation(Class<?> clazz, String name, Class<?>[] parameterTypes, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; try { Method method = clazz.getDeclaredMethod(name, parameterTypes); T annotation = clazz.getDeclaredMethod(name, parameterTypes).getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, method, clazz); } catch (NoSuchMethodException e) { // fallback... } if (declaredAnnotation == null && clazz.getSuperclass() != null) declaredAnnotation = getMethodAnnotation(clazz.getSuperclass(), name, parameterTypes, annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getMethodAnnotation(interfaze, name, parameterTypes, annotationClass); if (declaredAnnotation != null) break; } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getClassAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; T annotation = clazz.getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, clazz, clazz); else { if (clazz.getSuperclass() != null) declaredAnnotation = getClassAnnotation(clazz.getSuperclass(), annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getClassAnnotation(interfaze, annotationClass); if (declaredAnnotation != null) break; } } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getClassAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; T annotation = clazz.getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, clazz, clazz); else { if (clazz.getSuperclass() != null) declaredAnnotation = getClassAnnotation(clazz.getSuperclass(), annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getClassAnnotation(interfaze, annotationClass); if (declaredAnnotation != null) break; } } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getClassAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; T annotation = clazz.getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, clazz, clazz); else { if (clazz.getSuperclass() != null) declaredAnnotation = getClassAnnotation(clazz.getSuperclass(), annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getClassAnnotation(interfaze, annotationClass); if (declaredAnnotation != null) break; } } } return declaredAnnotation; }
public static <T extends Annotation> DeclaredAnnotation<T> getClassAnnotation(Class<?> clazz, Class<T> annotationClass) { DeclaredAnnotation<T> declaredAnnotation = null; T annotation = clazz.getAnnotation(annotationClass); if (annotation != null) declaredAnnotation = new DeclaredAnnotation<T>(annotation, clazz, clazz); else { if (clazz.getSuperclass() != null) declaredAnnotation = getClassAnnotation(clazz.getSuperclass(), annotationClass); if (declaredAnnotation == null) { for (Class<?> interfaze : clazz.getInterfaces()) { declaredAnnotation = getClassAnnotation(interfaze, annotationClass); if (declaredAnnotation != null) break; } } } 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> 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; }