@Nonnull
  protected List<Annotation> harvestQualifiers(@Nonnull Field field) {
    List<Annotation> list = new ArrayList<>();
    Annotation[] annotations = field.getAnnotations();
    for (Annotation annotation : annotations) {
      if (AnnotationUtils.isAnnotatedWith(annotation, Qualifier.class)) {
        if (BindTo.class.isAssignableFrom(annotation.getClass())) {
          continue;
        }

        // special case for @Named
        if (Named.class.isAssignableFrom(annotation.getClass())) {
          Named named = (Named) annotation;
          if (isBlank(named.value())) {
            list.add(named(getPropertyName(field.getName())));
            continue;
          }
        }
        list.add(annotation);
      }
    }
    return list;
  }
Ejemplo n.º 2
0
 @Nonnull
 public static List<Annotation> harvestQualifiers(@Nonnull Class<?> klass) {
   requireNonNull(klass, "Argument 'class' must not be null");
   List<Annotation> list = new ArrayList<>();
   Annotation[] annotations = klass.getAnnotations();
   for (Annotation annotation : annotations) {
     if (AnnotationUtils.isAnnotatedWith(annotation, Qualifier.class)) {
       // special case @BindTo is only used during tests
       if (BindTo.class.isAssignableFrom(annotation.getClass())) {
         continue;
       }
       // special case for @Named
       if (Named.class.isAssignableFrom(annotation.getClass())) {
         Named named = (Named) annotation;
         if (isBlank(named.value())) {
           list.add(named(getPropertyName(klass)));
           continue;
         }
       }
       list.add(annotation);
     }
   }
   return list;
 }