private JsonCodecBinder(Binder binder) { this.binder = requireNonNull(binder, "binder is null").skipSources(getClass()); }
ModuleWriter(Binder binder) { this.binder = binder.skipSources(this.getClass()); }
@Override public void configure(Binder binder) { binder = binder.skipSources(getClass()); for (Module module : modulesSet) { binder.install(module); } } }
/** Creates a constant binding to {@code @Named(key)} for each entry in {@code properties}. */ public static void bindProperties(Binder binder, Map<String, String> properties) { binder = binder.skipSources(Names.class); for (Map.Entry<String, String> entry : properties.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); binder.bind(Key.get(String.class, new NamedImpl(key))).toInstance(value); } }
@Override public final synchronized void configure(Binder binder) { checkState(this.binder == null, "Re-entry is not allowed."); // Guice treats PrivateModules specially and passes in a PrivateBinder automatically. this.binder = (PrivateBinder) binder.skipSources(PrivateModule.class); try { configure(); } finally { this.binder = null; } }
/** * Creates a constant binding to {@code @Named(key)} for each property. This method binds all * properties including those inherited from {@link Properties#defaults defaults}. */ public static void bindProperties(Binder binder, Properties properties) { binder = binder.skipSources(Names.class); // use enumeration to include the default properties for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); String value = properties.getProperty(propertyName); binder.bind(Key.get(String.class, new NamedImpl(propertyName))).toInstance(value); } } }
private JsonBinder(Binder binder) { binder = requireNonNull(binder, "binder is null").skipSources(getClass()); keySerializerMapBinder = MapBinder.newMapBinder(binder, new TypeLiteral<Class<?>>() {}, new TypeLiteral<JsonSerializer<?>>() {}, JsonKeySerde.class); keyDeserializerMapBinder = MapBinder.newMapBinder(binder, new TypeLiteral<Class<?>>() {}, new TypeLiteral<KeyDeserializer>() {}, JsonKeySerde.class); serializerMapBinder = MapBinder.newMapBinder(binder, new TypeLiteral<Class<?>>() {}, new TypeLiteral<JsonSerializer<?>>() {}); deserializerMapBinder = MapBinder.newMapBinder(binder, new TypeLiteral<Class<?>>() {}, new TypeLiteral<JsonDeserializer<?>>() {}); moduleBinder = newSetBinder(binder, Module.class); }
public static <T> OptionalBinder<T> newOptionalBinder(Binder binder, Class<T> type) { return new OptionalBinder<T>( newRealOptionalBinder(binder.skipSources(OptionalBinder.class), Key.get(type))); }
public static <T> OptionalBinder<T> newOptionalBinder(Binder binder, TypeLiteral<T> type) { return new OptionalBinder<T>( newRealOptionalBinder(binder.skipSources(OptionalBinder.class), Key.get(type))); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with no binding annotation. */ public static <K, V> MapBinder<K, V> newMapBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType) { return new MapBinder<K, V>( newMapRealBinder(binder.skipSources(MapBinder.class), keyType, valueType)); }
/** * Returns a new multibinder that collects instances of the key's type in a {@link Set} that is * itself bound with the annotation (if any) of the key. * * @since 4.0 */ public static <T> Multibinder<T> newSetBinder(Binder binder, Key<T> key) { return new Multibinder<T>(newRealSetBinder(binder.skipSources(Multibinder.class), key)); }
public static <T> RealOptionalBinder<T> newRealOptionalBinder(Binder binder, Key<T> type) { binder = binder.skipSources(RealOptionalBinder.class); RealOptionalBinder<T> optionalBinder = new RealOptionalBinder<>(binder, type); binder.install(optionalBinder); return optionalBinder; }
/** Implementation of newSetBinder. */ public static <T> RealMultibinder<T> newRealSetBinder(Binder binder, Key<T> key) { binder = binder.skipSources(RealMultibinder.class); RealMultibinder<T> result = new RealMultibinder<>(binder, key); binder.install(result); return result; }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotationType}. */ public static <K, V> MapBinder<K, V> newMapBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Class<? extends Annotation> annotationType) { return new MapBinder<K, V>( newRealMapBinder(binder.skipSources(MapBinder.class), keyType, valueType, annotationType)); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotation}. */ public static <K, V> MapBinder<K, V> newMapBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) { return new MapBinder<K, V>( newRealMapBinder(binder.skipSources(MapBinder.class), keyType, valueType, annotation)); }
public static <T> OptionalBinder<T> newOptionalBinder(Binder binder, Key<T> type) { return new OptionalBinder<T>( newRealOptionalBinder(binder.skipSources(OptionalBinder.class), type)); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotation}. */ public static <K, V> RealMapBinder<K, V> newRealMapBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) { binder = binder.skipSources(RealMapBinder.class); return newRealMapBinder( binder, keyType, valueType, Key.get(mapOf(keyType, valueType), annotation), RealMultibinder.newRealSetBinder( binder, Key.get(entryOfProviderOf(keyType, valueType), annotation))); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with no binding annotation. */ public static <K, V> RealMapBinder<K, V> newMapRealBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType) { binder = binder.skipSources(RealMapBinder.class); return newRealMapBinder( binder, keyType, valueType, Key.get(mapOf(keyType, valueType)), RealMultibinder.newRealSetBinder(binder, Key.get(entryOfProviderOf(keyType, valueType)))); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotationType}. */ public static <K, V> RealMapBinder<K, V> newRealMapBinder( Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Class<? extends Annotation> annotationType) { binder = binder.skipSources(RealMapBinder.class); return newRealMapBinder( binder, keyType, valueType, Key.get(mapOf(keyType, valueType), annotationType), RealMultibinder.newRealSetBinder( binder, Key.get(entryOfProviderOf(keyType, valueType), annotationType))); }
static <K, V> RealMapBinder<K, V> newRealMapBinder( Binder binder, TypeLiteral<K> keyType, Key<V> valueTypeAndAnnotation) { binder = binder.skipSources(RealMapBinder.class); TypeLiteral<V> valueType = valueTypeAndAnnotation.getTypeLiteral(); return newRealMapBinder( binder, keyType, valueType, valueTypeAndAnnotation.ofType(mapOf(keyType, valueType)), RealMultibinder.newRealSetBinder( binder, valueTypeAndAnnotation.ofType(entryOfProviderOf(keyType, valueType)))); }