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

下面列出了怎么用com.google.inject.BindingAnnotation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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;
}
 
源代码2 项目: vespa   文件: ComponentGraph.java
public static boolean isBindingAnnotation(Annotation annotation) {
    LinkedList<Class<?>> queue = new LinkedList<>();
    queue.add(annotation.getClass());
    queue.addAll(Arrays.asList(annotation.getClass().getInterfaces()));

    while (!queue.isEmpty()) {
        Class<?> clazz = queue.removeFirst();
        if (clazz.getAnnotation(BindingAnnotation.class) != null) {
            return true;
        } else {
            if (clazz.getSuperclass() != null) {
                queue.addFirst(clazz.getSuperclass());
            }
        }
    }
    return false;
}
 
源代码3 项目: 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;
}
 
private Annotation findBindingAnnotation(Iterable<Annotation> annotations)
{
    for (Annotation annotation : annotations) {
        // Check on guice (BindingAnnotation) & javax (Qualifier) based injections
        if (annotation.annotationType().isAnnotationPresent(BindingAnnotation.class) ||
            annotation.annotationType().isAnnotationPresent(Qualifier.class))
        {
            return annotation;
        }
    }
    return null;
}
 
源代码5 项目: opt4j   文件: Opt4JModule.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {

	/**
	 * Configure injected constants.
	 */
	PropertyModule module = new PropertyModule(this);
	for (Property property : module.getProperties()) {
		for (Annotation annotation : property.getAnnotations()) {
			if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null) {
				Class<?> type = property.getType();
				Object value = property.getValue();

				ConstantBindingBuilder builder = bindConstant(annotation);
				if (type.equals(Integer.TYPE)) {
					builder.to((Integer) value);
				} else if (type.equals(Long.TYPE)) {
					builder.to((Long) value);
				} else if (type.equals(Double.TYPE)) {
					builder.to((Double) value);
				} else if (type.equals(Float.TYPE)) {
					builder.to((Float) value);
				} else if (type.equals(Byte.TYPE)) {
					builder.to((Byte) value);
				} else if (type.equals(Short.TYPE)) {
					builder.to((Short) value);
				} else if (type.equals(Boolean.TYPE)) {
					builder.to((Boolean) value);
				} else if (type.equals(Character.TYPE)) {
					builder.to((Character) value);
				} else if (type.equals(String.class)) {
					builder.to((String) value);
				} else if (type.equals(Class.class)) {
					builder.to((Class<?>) value);
				} else if (value instanceof Enum<?>) {
					builder.to((Enum) value);
				} else {
					String message = "Constant type not bindable: " + type + " of field " + property.getName() + " in module "
							+ this.getClass().getName();
					throw new ConfigurationException(Arrays.asList(new Message(message)));
				}
			}
		}
	}

	multi(OptimizerStateListener.class);
	multi(OptimizerIterationListener.class);
	multi(IndividualStateListener.class);

	config();
}
 
源代码6 项目: 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);
}
 
源代码7 项目: dropwizard-guicey   文件: TestParametersSupport.java
private boolean isQualifierAnnotation(final Annotation... annotations) {
    final Annotation ann = annotations[0];
    return annotations.length == 1
            && (AnnotationSupport.isAnnotated(ann.annotationType(), Qualifier.class)
            || AnnotationSupport.isAnnotated(ann.annotationType(), BindingAnnotation.class));
}
 
源代码8 项目: attic-aurora   文件: 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;
}
 
 类所在包
 同包方法