Java 类com.google.inject.BindingAnnotation 实例源码

项目:yql-plus    文件:SourceApiGenerator.java   
private ObjectBuilder.FieldBuilder createInjectedField(ObjectBuilder target, GambitTypes gambitScope, java.lang.reflect.Type genericType, Annotation[] annotation) {
    TypeLiteral<?> genericParam = TypeLiteral.get(genericType);
    ObjectBuilder.FieldBuilder injectedField = target.field(gensym("inject$"), gambitScope.adapt(genericParam.getRawType(), false));
    injectedField.annotate(Inject.class);
    Annotation bindingAnnotation = null;
    for (Annotation ann : annotation) {
        if (ann.getClass().isAnnotationPresent(BindingAnnotation.class)) {
            Preconditions.checkArgument(bindingAnnotation == null, "Already found a binding annotation %s and now found another %s: that's too many", bindingAnnotation, ann);
            bindingAnnotation = ann;
        }
    }
    if (bindingAnnotation != null) {
        injectedField.annotate(bindingAnnotation);
    }
    return injectedField;
}
项目:salta    文件:GuiceModule.java   
private void addQualifierExtractors() {
    // qualifiers
    config.requiredQualifierExtractors.add(annotatedElement -> {
        return Arrays.stream(annotatedElement.getAnnotations())
                .filter(a -> a.annotationType()
                        .isAnnotationPresent(BindingAnnotation.class)
                        || a.annotationType().isAnnotationPresent(
                                javax.inject.Qualifier.class));
    });

    config.availableQualifierExtractors
            .add(new Function<AnnotatedElement, Stream<Annotation>>() {
                @Override
                public Stream<Annotation> apply(
                        AnnotatedElement annotated) {
                    return Arrays.stream(annotated.getAnnotations())
                            .filter(a -> a.annotationType()
                                    .isAnnotationPresent(
                                            BindingAnnotation.class)
                                    || a.annotationType()
                                            .isAnnotationPresent(
                                                    javax.inject.Qualifier.class));
                }
            });
}
项目:google-gin    文件:MemberLiteral.java   
protected Annotation getBindingAnnotation(Annotation[] annotations) {
  Annotation bindingAnnotation = null;
  for (Annotation annotation : annotations) {
    if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null
        || annotation.annotationType() == Named.class) {
      if (bindingAnnotation != null) {
        throw new ProvisionException(
            String.format("More than one binding annotation found on %s: %s, %s.",
                 this, annotation, bindingAnnotation));
      }

      bindingAnnotation = annotation;

      // Keep going so we can find any rogue additional binding annotations
    }
  }

  return bindingAnnotation;
}
项目:Equella    文件:GuicePlugin.java   
@Override
protected void doStart() throws Exception
{
    // Please do not remove
    // This kludge is about ensuring these annotations are parsed to prevent
    // a deadlock
    Annotations.isRetainedAtRuntime(Assisted.class);
    Annotations.isRetainedAtRuntime(AssistedInject.class);
    Annotations.isRetainedAtRuntime(BindingAnnotation.class);
    // End kludge
    privatePluginService = (PrivatePluginService) AbstractPluginService.get();
    getManager().getRegistry().registerListener(this);
    setupBeanLocators();
}
项目:android-arscblamer    文件:InjectedApplication.java   
private Collection<Annotation> getBindingAnnotations(Field field) {
  List<Annotation> result = new ArrayList<>();
  for (Annotation annotation : field.getAnnotations()) {
    if (annotation.annotationType().isAnnotationPresent(BindingAnnotation.class)) {
      result.add(annotation);
    }
  }
  return result;
}
项目:jersey2-guice    文件:BindingUtils.java   
/**
 * Returns the first {@link Annotation} from the given array that
 * is a {@link BindingAnnotation}.
 * 
 * @see BindingAnnotation
 */
private static Annotation getBindingAnnotation(Annotation[] annotations) {
  for (Annotation annotation : annotations) {
    Class<? extends Annotation> type = annotation.annotationType();
    if (type.isAnnotationPresent(BindingAnnotation.class)) {
      return annotation;
    }
  }

  return null;
}
项目:extensibility-api    文件:ExtensionLoaderModule.java   
private <T> Annotation findQualifierAnnotation(Class<? extends T> impl) {
    for (Annotation a : impl.getAnnotations()) {
        Class<? extends Annotation> at = a.annotationType();
        if (at.isAnnotationPresent(Qualifier.class)
         || at.isAnnotationPresent(BindingAnnotation.class))
            return a;
    }
    return null;
}
项目:test-injector    文件:Keys.java   
private static Key<?> getFieldKey(Field field, TypeLiteral<?> typeLiteral) {
  List<Annotation> annotations = getElementAnnotations(field, BindingAnnotation.class);

  if (annotations.size() == 0) {
    return Key.get(typeLiteral);
  }
  if (annotations.size() == 1) {
    return Key.get(typeLiteral, annotations.get(0));
  }

  throw new MoreThanOneBindingAnnotationException(field, annotations);
}
项目:test-injector    文件:ReflectionsTest.java   
@Test
public void get_element_annotations_returns_annotations_of_given_type() throws SecurityException,
    NoSuchFieldException {
  Class<ClassWithFieldWithManyAnnotations> klass = ClassWithFieldWithManyAnnotations.class;
  Field field = klass.getField("field");

  List<Annotation> annotations = getElementAnnotations(field, BindingAnnotation.class);

  assertThat(annotations).hasSize(2);
  assertThat(annotations.get(0).annotationType()).isSameAs(Named.class);
  assertThat(annotations.get(1).annotationType()).isSameAs(MyAnnotation.class);

}
项目:test-injector    文件:ReflectionsTest.java   
@Test
public void get_element_annotation_returns_empty_set_for_not_annotated_field()
    throws SecurityException, NoSuchFieldException {
  Class<ClassWithFieldWithoutAnnotations> klass = ClassWithFieldWithoutAnnotations.class;
  Field field = klass.getField("field");

  List<Annotation> annotations = getElementAnnotations(field, BindingAnnotation.class);

  assertThat(annotations).isEmpty();
}
项目:test-injector    文件:MoreThanOneBindingAnnotationExceptionTest.java   
@Test
public void test() throws Exception {
  Field field = this.getClass().getDeclaredField("field");
  List<Annotation> annotations = getElementAnnotations(field, BindingAnnotation.class);

  Exception exception = new MoreThanOneBindingAnnotationException(field, annotations);

  assertThat(exception.getMessage()).isEqualTo(
      "Field field has more than one binding annotation: @Named, @MyBindingAnnotation");
}
项目:beadledom    文件:BindingAnnotations.java   
/**
 * Returns true if {@code annotation} is a Guice binding annotation; false otherwise.
 */
public static boolean isBindingAnnotation(Class<? extends Annotation> annotation) {
  return annotation.isAnnotationPresent(BindingAnnotation.class)
      || annotation.isAnnotationPresent(Qualifier.class);
}
项目:junit5-extensions    文件:GuiceExtension.java   
private static boolean isBindingAnnotation(Annotation annotation) {
  Class<? extends Annotation> annotationType = annotation.annotationType();
  return annotationType.isAnnotationPresent(Qualifier.class)
      || annotationType.isAnnotationPresent(BindingAnnotation.class);
}
项目:gstrap    文件:GuiceExtension.java   
private static boolean isBindingAnnotation(final Annotation annotation) {
    Class<? extends Annotation> annotationType = annotation.annotationType();
    return annotationType.isAnnotationPresent(Qualifier.class)
            || annotationType.isAnnotationPresent(BindingAnnotation.class);
}
项目:Mastering-Mesos    文件:Bindings.java   
/**
 * Checks that the given annotation type is a {@link BindingAnnotation @BindingAnnotation}.
 *
 * @param annotationType The annotation type to check.
 * @param <T> The type of the binding annotation.
 * @return The checked binding annotation type.
 * @throws NullPointerException If the given {@code annotationType} is null.
 * @throws IllegalArgumentException If the given {@code annotationType} is not a
 *     {@literal @BindingAnnotation}.
 */
public static <T extends Annotation> Class<T> checkBindingAnnotation(Class<T> annotationType) {
  Preconditions.checkNotNull(annotationType);
  boolean bindingAnnotation = annotationType.isAnnotationPresent(BindingAnnotation.class);
  boolean qualifier = annotationType.isAnnotationPresent(Qualifier.class);
  Preconditions.checkArgument(bindingAnnotation || qualifier,
      "%s is not a @BindingAnnotation or @Qualifier", annotationType);
  return annotationType;
}