public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Class<T> annotation) { Validate.notNull(annotation, "annotation cannot be null"); Validate.notNull(type, "type cannot be null"); for (Annotation ann : type.getDeclaredAnnotations()) { if (ann.annotationType().equals(annotation)) return Optional.of((T) ann); } Class<?> superType = type.getSuperclass(); if (superType != null && !superType.equals(Object.class)) { return getAnnotation(superType, annotation); } return Optional.absent(); }
public static <T extends Annotation> Optional<T> getAnnotation(JoinPoint joinPoint, Class<T> annotation) { return getAnnotation(joinPoint.getTarget().getClass(), annotation); }
private static MetaHolder.Builder setDefaultProperties(MetaHolder.Builder builder, Class<?> declaringClass, final ProceedingJoinPoint joinPoint) { Optional<DefaultProperties> defaultPropertiesOpt = AopUtils.getAnnotation(joinPoint, DefaultProperties.class); builder.defaultGroupKey(declaringClass.getSimpleName()); if (defaultPropertiesOpt.isPresent()) { DefaultProperties defaultProperties = defaultPropertiesOpt.get(); builder.defaultProperties(defaultProperties); if (StringUtils.isNotBlank(defaultProperties.groupKey())) { builder.defaultGroupKey(defaultProperties.groupKey()); } if (StringUtils.isNotBlank(defaultProperties.threadPoolKey())) { builder.defaultThreadPoolKey(defaultProperties.threadPoolKey()); } } return builder; }
public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Class<T> annotation) { Validate.notNull(annotation, "annotation cannot be null"); Validate.notNull(type, "type cannot be null"); for (Annotation ann : type.getDeclaredAnnotations()) { if (ann.annotationType().equals(annotation)) return Optional.of((T) ann); } Class<?> superType = type.getSuperclass(); if (superType != null && !superType.equals(Object.class)) { return getAnnotation(superType, annotation); } return Optional.absent(); }
public static <T extends Annotation> Optional<T> getAnnotation(JoinPoint joinPoint, Class<T> annotation) { return getAnnotation(joinPoint.getTarget().getClass(), annotation); }
private static MetaHolder.Builder setDefaultProperties(MetaHolder.Builder builder, Class<?> declaringClass, final ProceedingJoinPoint joinPoint) { Optional<DefaultProperties> defaultPropertiesOpt = AopUtils.getAnnotation(joinPoint, DefaultProperties.class); builder.defaultGroupKey(declaringClass.getSimpleName()); if (defaultPropertiesOpt.isPresent()) { DefaultProperties defaultProperties = defaultPropertiesOpt.get(); builder.defaultProperties(defaultProperties); if (StringUtils.isNotBlank(defaultProperties.groupKey())) { builder.defaultGroupKey(defaultProperties.groupKey()); } if (StringUtils.isNotBlank(defaultProperties.threadPoolKey())) { builder.defaultThreadPoolKey(defaultProperties.threadPoolKey()); } } return builder; }