com.google.inject.BindingAnnotation Java Examples
The following examples show how to use
com.google.inject.BindingAnnotation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceApiGenerator.java From yql-plus with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: ComponentGraph.java From vespa with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: InjectedApplication.java From android-arscblamer with Apache License 2.0 | 5 votes |
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; }
Example #4
Source File: GuiceAnnotationIntrospector.java From jackson-modules-base with Apache License 2.0 | 5 votes |
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; }
Example #5
Source File: Opt4JModule.java From opt4j with MIT License | 4 votes |
@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(); }
Example #6
Source File: GuiceExtension.java From junit5-extensions with MIT License | 4 votes |
private static boolean isBindingAnnotation(Annotation annotation) { Class<? extends Annotation> annotationType = annotation.annotationType(); return annotationType.isAnnotationPresent(Qualifier.class) || annotationType.isAnnotationPresent(BindingAnnotation.class); }
Example #7
Source File: TestParametersSupport.java From dropwizard-guicey with MIT License | 4 votes |
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)); }
Example #8
Source File: Bindings.java From attic-aurora with Apache License 2.0 | 3 votes |
/** * 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; }