private RealMultibinder(Binder binder, TypeLiteral<T> elementType, Key<Set<T>> setKey) { this.binder = checkNotNull(binder, "binder"); this.elementType = checkNotNull(elementType, "elementType"); this.setKey = checkNotNull(setKey, "setKey"); this.collectionOfProvidersKey = setKey.ofType(collectionOfProvidersOf(elementType)); this.collectionOfJavaxProvidersKey = setKey.ofType(collectionOfJavaxProvidersOf(elementType)); this.setName = RealElement.nameOf(setKey); this.permitDuplicatesKey = Key.get(Boolean.class, named(toString() + " permits duplicates")); }
private RealOptionalBinder(Binder binder, Key<T> typeKey) { this.binder = binder; this.typeKey = checkNotNull(typeKey); TypeLiteral<T> literal = typeKey.getTypeLiteral(); this.optionalKey = typeKey.ofType(optionalOf(literal)); this.optionalJavaxProviderKey = typeKey.ofType(optionalOfJavaxProvider(literal)); this.optionalProviderKey = typeKey.ofType(optionalOfProvider(literal)); this.optionalProviderT = binder.getProvider(optionalProviderKey); String name = RealElement.nameOf(typeKey); this.defaultKey = Key.get(typeKey.getTypeLiteral(), new DefaultImpl(name)); this.actualKey = Key.get(typeKey.getTypeLiteral(), new ActualImpl(name)); // Until the injector initializes us, we don't know what our dependencies are, // so initialize to the whole Injector (like Multibinder, and MapBinder indirectly). this.dependencies = ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class))); this.providerDependencies = ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class))); if (JAVA_OPTIONAL_CLASS != null) { this.javaOptionalKey = typeKey.ofType(javaOptionalOf(literal)); this.javaOptionalJavaxProviderKey = typeKey.ofType(javaOptionalOfJavaxProvider(literal)); this.javaOptionalProviderKey = typeKey.ofType(javaOptionalOfProvider(literal)); } else { this.javaOptionalKey = null; this.javaOptionalJavaxProviderKey = null; this.javaOptionalProviderKey = null; } }