/** * Indicates if class has given annotation. * * @param <T> Annotation type. * @param cls Class to get annotation from. * @param annCls Annotation to get. * @return {@code true} if class has annotation or {@code false} otherwise. */ public static <T extends Annotation> boolean hasAnnotation(Class<?> cls, Class<T> annCls) { return getAnnotation(cls, annCls) != null; }
/** * Gets task name for the given task class. * * @param taskCls Task class. * @return Either task name from class annotation (see {@link org.apache.ignite.compute.ComputeTaskName}}) * or task class name if there is no annotation. */ public static String getTaskName(Class<? extends ComputeTask<?, ?>> taskCls) { ComputeTaskName nameAnn = getAnnotation(taskCls, ComputeTaskName.class); return nameAnn == null ? taskCls.getName() : nameAnn.value(); }
/** * Gets annotation for a class. * * @param <T> Type of annotation to return. * @param cls Class to get annotation from. * @param annCls Annotation to get. * @return Instance of annotation, or {@code null} if not found. */ @Nullable public static <T extends Annotation> T getAnnotation(Class<?> cls, Class<T> annCls) { if (cls == Object.class) return null; T ann = cls.getAnnotation(annCls); if (ann != null) return ann; for (Class<?> itf : cls.getInterfaces()) { ann = getAnnotation(itf, annCls); // Recursion. if (ann != null) return ann; } if (!cls.isInterface()) { ann = getAnnotation(cls.getSuperclass(), annCls); if (ann != null) return ann; } return null; }
/** * Indicates if class has given annotation. * * @param <T> Annotation type. * @param cls Class to get annotation from. * @param annCls Annotation to get. * @return {@code true} if class has annotation or {@code false} otherwise. */ public static <T extends Annotation> boolean hasAnnotation(Class<?> cls, Class<T> annCls) { return getAnnotation(cls, annCls) != null; }
/** * Gets task name for the given task class. * * @param taskCls Task class. * @return Either task name from class annotation (see {@link org.apache.ignite.compute.ComputeTaskName}}) * or task class name if there is no annotation. */ public static String getTaskName(Class<? extends ComputeTask<?, ?>> taskCls) { ComputeTaskName nameAnn = getAnnotation(taskCls, ComputeTaskName.class); return nameAnn == null ? taskCls.getName() : nameAnn.value(); }
/** * Gets annotation for a class. * * @param <T> Type of annotation to return. * @param cls Class to get annotation from. * @param annCls Annotation to get. * @return Instance of annotation, or {@code null} if not found. */ @Nullable public static <T extends Annotation> T getAnnotation(Class<?> cls, Class<T> annCls) { if (cls == Object.class) return null; T ann = cls.getAnnotation(annCls); if (ann != null) return ann; for (Class<?> itf : cls.getInterfaces()) { ann = getAnnotation(itf, annCls); // Recursion. if (ann != null) return ann; } if (!cls.isInterface()) { ann = getAnnotation(cls.getSuperclass(), annCls); if (ann != null) return ann; } return null; }