当前位置: 首页>>代码示例>>Java>>正文


Java BindingAnnotation类代码示例

本文整理汇总了Java中com.google.inject.BindingAnnotation的典型用法代码示例。如果您正苦于以下问题:Java BindingAnnotation类的具体用法?Java BindingAnnotation怎么用?Java BindingAnnotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BindingAnnotation类属于com.google.inject包,在下文中一共展示了BindingAnnotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createInjectedField

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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;
}
 
开发者ID:yahoo,项目名称:yql-plus,代码行数:17,代码来源:SourceApiGenerator.java

示例2: addQualifierExtractors

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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));
                }
            });
}
 
开发者ID:ruediste,项目名称:salta,代码行数:26,代码来源:GuiceModule.java

示例3: getBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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;
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:20,代码来源:MemberLiteral.java

示例4: doStart

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
@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();
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:GuicePlugin.java

示例5: getBindingAnnotations

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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;
}
 
开发者ID:google,项目名称:android-arscblamer,代码行数:10,代码来源:InjectedApplication.java

示例6: getBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:17,代码来源:BindingUtils.java

示例7: findQualifierAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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;
}
 
开发者ID:cloudbees,项目名称:extensibility-api,代码行数:10,代码来源:ExtensionLoaderModule.java

示例8: getFieldKey

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
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);
}
 
开发者ID:mikosik,项目名称:test-injector,代码行数:13,代码来源:Keys.java

示例9: get_element_annotations_returns_annotations_of_given_type

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
@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);

}
 
开发者ID:mikosik,项目名称:test-injector,代码行数:14,代码来源:ReflectionsTest.java

示例10: get_element_annotation_returns_empty_set_for_not_annotated_field

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
@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();
}
 
开发者ID:mikosik,项目名称:test-injector,代码行数:11,代码来源:ReflectionsTest.java

示例11: test

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
@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");
}
 
开发者ID:mikosik,项目名称:test-injector,代码行数:11,代码来源:MoreThanOneBindingAnnotationExceptionTest.java

示例12: isBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:8,代码来源:BindingAnnotations.java

示例13: isBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
private static boolean isBindingAnnotation(Annotation annotation) {
  Class<? extends Annotation> annotationType = annotation.annotationType();
  return annotationType.isAnnotationPresent(Qualifier.class)
      || annotationType.isAnnotationPresent(BindingAnnotation.class);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:6,代码来源:GuiceExtension.java

示例14: isBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
private static boolean isBindingAnnotation(final Annotation annotation) {
	Class<? extends Annotation> annotationType = annotation.annotationType();
	return annotationType.isAnnotationPresent(Qualifier.class)
			|| annotationType.isAnnotationPresent(BindingAnnotation.class);
}
 
开发者ID:stickfigure,项目名称:gstrap,代码行数:6,代码来源:GuiceExtension.java

示例15: checkBindingAnnotation

import com.google.inject.BindingAnnotation; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:19,代码来源:Bindings.java


注:本文中的com.google.inject.BindingAnnotation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。