本文整理匯總了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;
}
示例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));
}
});
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}