2222import static dagger .internal .codegen .base .Util .reentrantComputeIfAbsent ;
2323import static dagger .internal .codegen .binding .AssistedInjectionAnnotations .isAssistedFactoryType ;
2424import static dagger .internal .codegen .binding .SourceFiles .generatedMonitoringModuleName ;
25- import static dagger .internal .codegen .extension .DaggerStreams .toImmutableSet ;
2625import static dagger .internal .codegen .model .BindingKind .ASSISTED_INJECTION ;
2726import static dagger .internal .codegen .model .BindingKind .DELEGATE ;
2827import static dagger .internal .codegen .model .BindingKind .INJECTION ;
4847import dagger .internal .codegen .base .ContributionType ;
4948import dagger .internal .codegen .base .DaggerSuperficialValidation ;
5049import dagger .internal .codegen .base .Keys ;
50+ import dagger .internal .codegen .base .MapType ;
5151import dagger .internal .codegen .base .OptionalType ;
5252import dagger .internal .codegen .compileroption .CompilerOptions ;
5353import dagger .internal .codegen .javapoet .TypeNames ;
@@ -521,17 +521,12 @@ private ImmutableSet<Key> keysMatchingRequestUncached(Key requestKey) {
521521 }
522522
523523 private ImmutableSet <ContributionBinding > createDelegateBindings (
524- ImmutableSetMultimap <Key , DelegateDeclaration > delegateDeclarations , Key requestKey ) {
525- return delegateDeclarations .get (
526- // @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or
527- // @Produces @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the
528- // key's type's value type if it's a Map<K, Provider/Producer<V>> before looking
529- // in delegateDeclarations. createDelegateBindings() will create bindings with the
530- // properly wrapped key type.
531- keyFactory .unwrapMapValueType (requestKey ))
532- .stream ()
533- .map (this ::createDelegateBinding )
534- .collect (toImmutableSet ());
524+ ImmutableSet <DelegateDeclaration > delegateDeclarations ) {
525+ ImmutableSet .Builder <ContributionBinding > builder = ImmutableSet .builder ();
526+ for (DelegateDeclaration delegateDeclaration : delegateDeclarations ) {
527+ builder .add (createDelegateBinding (delegateDeclaration ));
528+ }
529+ return builder .build ();
535530 }
536531
537532 /**
@@ -704,9 +699,15 @@ private ImmutableList<Resolver> getResolverLineage() {
704699 * resolver.
705700 */
706701 private ImmutableSet <ContributionBinding > getLocalExplicitBindings (Key key ) {
707- return ImmutableSet .<ContributionBinding >builder ()
702+ return new ImmutableSet .Builder <ContributionBinding >()
708703 .addAll (explicitBindings .get (key ))
709- .addAll (createDelegateBindings (delegateDeclarations , key ))
704+ // @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or @Produces
705+ // @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the key's type's
706+ // value type if it's a Map<K, Provider/Producer<V>> before looking in
707+ // delegateDeclarations. createDelegateBindings() will create bindings with the properly
708+ // wrapped key type.
709+ .addAll (
710+ createDelegateBindings (delegateDeclarations .get (keyFactory .unwrapMapValueType (key ))))
710711 .build ();
711712 }
712713
@@ -715,10 +716,21 @@ private ImmutableSet<ContributionBinding> getLocalExplicitBindings(Key key) {
715716 * by {@code key} from this resolver.
716717 */
717718 private ImmutableSet <ContributionBinding > getLocalExplicitMultibindings (Key key ) {
718- return ImmutableSet .<ContributionBinding >builder ()
719- .addAll (explicitMultibindings .get (key ))
720- .addAll (createDelegateBindings (delegateMultibindingDeclarations , key ))
721- .build ();
719+ ImmutableSet .Builder <ContributionBinding > multibindings = ImmutableSet .builder ();
720+ multibindings .addAll (explicitMultibindings .get (key ));
721+ if (!MapType .isMap (key )
722+ || MapType .from (key ).isRawType ()
723+ || MapType .from (key ).valuesAreFrameworkType ()) {
724+ // @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or @Produces
725+ // @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the key's type's
726+ // value type if it's a Map<K, Provider/Producer<V>> before looking in
727+ // delegateMultibindingDeclarations. createDelegateBindings() will create bindings with the
728+ // properly wrapped key type.
729+ multibindings .addAll (
730+ createDelegateBindings (
731+ delegateMultibindingDeclarations .get (keyFactory .unwrapMapValueType (key ))));
732+ }
733+ return multibindings .build ();
722734 }
723735
724736 /**
0 commit comments