/** * Returns the specified annotation only if it's been declared on the specified class. * * <p> * More efficient than calling {@link Class#getAnnotation(Class)} since it doesn't recursively look for the class * up the parent chain. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getDeclaredAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) for (Annotation a2 : c.getDeclaredAnnotations()) if (a2.annotationType() == a) return (T)a2; return null; }
/** * Returns the specified annotation only if it's been declared on the specified class. * * <p> * More efficient than calling {@link Class#getAnnotation(Class)} since it doesn't recursively look for the class * up the parent chain. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getDeclaredAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) for (Annotation a2 : c.getDeclaredAnnotations()) if (a2.annotationType() == a) return (T)a2; return null; }
/** * Returns the specified annotation only if it's been declared on the specified class. * * <p> * More efficient than calling {@link Class#getAnnotation(Class)} since it doesn't recursively look for the class * up the parent chain. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getDeclaredAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) for (Annotation a2 : c.getDeclaredAnnotations()) if (a2.annotationType() == a) return (T)a2; return null; }
private static <T extends Annotation> void findAnnotationsMap(Class<T> a, Type t, Map<Class<?>,T> m) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) m.put(c, t2); findAnnotationsMap(a, c.getSuperclass(), m); for (Class<?> c2 : c.getInterfaces()) findAnnotationsMap(a, c2, m); } }
private static <T extends Annotation> void findAnnotationsMap(Class<T> a, Type t, Map<Class<?>,T> m) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) m.put(c, t2); findAnnotationsMap(a, c.getSuperclass(), m); for (Class<?> c2 : c.getInterfaces()) findAnnotationsMap(a, c2, m); } }
private static <T extends Annotation> void findAnnotationsMap(Class<T> a, Type t, Map<Class<?>,T> m) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) m.put(c, t2); findAnnotationsMap(a, c.getSuperclass(), m); for (Class<?> c2 : c.getInterfaces()) findAnnotationsMap(a, c2, m); } }
/** * Similar to {@link Class#getAnnotation(Class)} except also searches annotations on interfaces. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ public static <T extends Annotation> T getAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) return t2; t2 = getAnnotation(a, c.getSuperclass()); if (t2 != null) return t2; for (Class<?> c2 : c.getInterfaces()) { t2 = getAnnotation(a, c2); if (t2 != null) return t2; } } return null; }
/** * Similar to {@link Class#getAnnotation(Class)} except also searches annotations on interfaces. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ public static <T extends Annotation> T getAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) return t2; t2 = getAnnotation(a, c.getSuperclass()); if (t2 != null) return t2; for (Class<?> c2 : c.getInterfaces()) { t2 = getAnnotation(a, c2); if (t2 != null) return t2; } } return null; }
/** * Similar to {@link Class#getAnnotation(Class)} except also searches annotations on interfaces. * * @param <T> The annotation class type. * @param a The annotation class. * @param t The annotated class. * @return The annotation, or <jk>null</jk> if not found. */ public static <T extends Annotation> T getAnnotation(Class<T> a, Type t) { Class<?> c = toClass(t); if (c != null) { T t2 = getDeclaredAnnotation(a, c); if (t2 != null) return t2; t2 = getAnnotation(a, c.getSuperclass()); if (t2 != null) return t2; for (Class<?> c2 : c.getInterfaces()) { t2 = getAnnotation(a, c2); if (t2 != null) return t2; } } return null; }
/** * Finds and appends the specified annotation on the specified class and superclasses/interfaces to the specified * list. * * @param a The annotation. * @param t The class. * @param l The list of annotations. */ public static <T extends Annotation> void appendAnnotations(Class<T> a, Type t, List<T> l) { Class<?> c = toClass(t); if (c != null) { addIfNotNull(l, getDeclaredAnnotation(a, c)); if (c.getPackage() != null) addIfNotNull(l, c.getPackage().getAnnotation(a)); appendAnnotations(a, c.getSuperclass(), l); for (Class<?> c2 : c.getInterfaces()) appendAnnotations(a, c2, l); } }
/** * Finds and appends the specified annotation on the specified class and superclasses/interfaces to the specified * list. * * @param a The annotation. * @param t The class. * @param l The list of annotations. */ public static <T extends Annotation> void appendAnnotations(Class<T> a, Type t, List<T> l) { Class<?> c = toClass(t); if (c != null) { addIfNotNull(l, getDeclaredAnnotation(a, c)); if (c.getPackage() != null) addIfNotNull(l, c.getPackage().getAnnotation(a)); appendAnnotations(a, c.getSuperclass(), l); for (Class<?> c2 : c.getInterfaces()) appendAnnotations(a, c2, l); } }
/** * Finds and appends the specified annotation on the specified class and superclasses/interfaces to the specified * list. * * @param a The annotation. * @param t The class. * @param l The list of annotations. */ public static <T extends Annotation> void appendAnnotations(Class<T> a, Type t, List<T> l) { Class<?> c = toClass(t); if (c != null) { addIfNotNull(l, getDeclaredAnnotation(a, c)); if (c.getPackage() != null) addIfNotNull(l, c.getPackage().getAnnotation(a)); appendAnnotations(a, c.getSuperclass(), l); for (Class<?> c2 : c.getInterfaces()) appendAnnotations(a, c2, l); } }
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }