當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。