Skip to content

Commit 76bde06

Browse files
bcorsoDagger Team
authored andcommitted
Rollback of "[Refactor] Remove duplicated logic in BindingGraphFactory"
PiperOrigin-RevId: 564526719
1 parent e651294 commit 76bde06

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

java/dagger/internal/codegen/binding/BindingGraphFactory.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static dagger.internal.codegen.base.Util.reentrantComputeIfAbsent;
2323
import static dagger.internal.codegen.binding.AssistedInjectionAnnotations.isAssistedFactoryType;
2424
import static dagger.internal.codegen.binding.SourceFiles.generatedMonitoringModuleName;
25-
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
2625
import static dagger.internal.codegen.model.BindingKind.ASSISTED_INJECTION;
2726
import static dagger.internal.codegen.model.BindingKind.DELEGATE;
2827
import static dagger.internal.codegen.model.BindingKind.INJECTION;
@@ -48,6 +47,7 @@
4847
import dagger.internal.codegen.base.ContributionType;
4948
import dagger.internal.codegen.base.DaggerSuperficialValidation;
5049
import dagger.internal.codegen.base.Keys;
50+
import dagger.internal.codegen.base.MapType;
5151
import dagger.internal.codegen.base.OptionalType;
5252
import dagger.internal.codegen.compileroption.CompilerOptions;
5353
import 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

Comments
 (0)