Skip to content

Commit

Permalink
Rollback of "[Refactor] Remove duplicated logic in `BindingGraphFacto…
Browse files Browse the repository at this point in the history
…ry`"

PiperOrigin-RevId: 564426568
  • Loading branch information
bcorso authored and Dagger Team committed Sep 11, 2023
1 parent 47953aa commit fec575c
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions java/dagger/internal/codegen/binding/BindingGraphFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static dagger.internal.codegen.base.Util.reentrantComputeIfAbsent;
import static dagger.internal.codegen.binding.AssistedInjectionAnnotations.isAssistedFactoryType;
import static dagger.internal.codegen.binding.SourceFiles.generatedMonitoringModuleName;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static dagger.internal.codegen.model.BindingKind.ASSISTED_INJECTION;
import static dagger.internal.codegen.model.BindingKind.DELEGATE;
import static dagger.internal.codegen.model.BindingKind.INJECTION;
Expand All @@ -48,6 +47,7 @@
import dagger.internal.codegen.base.ContributionType;
import dagger.internal.codegen.base.DaggerSuperficialValidation;
import dagger.internal.codegen.base.Keys;
import dagger.internal.codegen.base.MapType;
import dagger.internal.codegen.base.OptionalType;
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.internal.codegen.javapoet.TypeNames;
Expand Down Expand Up @@ -521,17 +521,12 @@ private ImmutableSet<Key> keysMatchingRequestUncached(Key requestKey) {
}

private ImmutableSet<ContributionBinding> createDelegateBindings(
ImmutableSetMultimap<Key, DelegateDeclaration> delegateDeclarations, Key requestKey) {
return delegateDeclarations.get(
// @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or
// @Produces @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the
// key's type's value type if it's a Map<K, Provider/Producer<V>> before looking
// in delegateDeclarations. createDelegateBindings() will create bindings with the
// properly wrapped key type.
keyFactory.unwrapMapValueType(requestKey))
.stream()
.map(this::createDelegateBinding)
.collect(toImmutableSet());
ImmutableSet<DelegateDeclaration> delegateDeclarations) {
ImmutableSet.Builder<ContributionBinding> builder = ImmutableSet.builder();
for (DelegateDeclaration delegateDeclaration : delegateDeclarations) {
builder.add(createDelegateBinding(delegateDeclaration));
}
return builder.build();
}

/**
Expand Down Expand Up @@ -704,9 +699,15 @@ private ImmutableList<Resolver> getResolverLineage() {
* resolver.
*/
private ImmutableSet<ContributionBinding> getLocalExplicitBindings(Key key) {
return ImmutableSet.<ContributionBinding>builder()
return new ImmutableSet.Builder<ContributionBinding>()
.addAll(explicitBindings.get(key))
.addAll(createDelegateBindings(delegateDeclarations, key))
// @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or @Produces
// @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the key's type's
// value type if it's a Map<K, Provider/Producer<V>> before looking in
// delegateDeclarations. createDelegateBindings() will create bindings with the properly
// wrapped key type.
.addAll(
createDelegateBindings(delegateDeclarations.get(keyFactory.unwrapMapValueType(key))))
.build();
}

Expand All @@ -715,10 +716,21 @@ private ImmutableSet<ContributionBinding> getLocalExplicitBindings(Key key) {
* by {@code key} from this resolver.
*/
private ImmutableSet<ContributionBinding> getLocalExplicitMultibindings(Key key) {
return ImmutableSet.<ContributionBinding>builder()
.addAll(explicitMultibindings.get(key))
.addAll(createDelegateBindings(delegateMultibindingDeclarations, key))
.build();
ImmutableSet.Builder<ContributionBinding> multibindings = ImmutableSet.builder();
multibindings.addAll(explicitMultibindings.get(key));
if (!MapType.isMap(key)
|| MapType.from(key).isRawType()
|| MapType.from(key).valuesAreFrameworkType()) {
// @Binds @IntoMap declarations have key Map<K, V>, unlike @Provides @IntoMap or @Produces
// @IntoMap, which have Map<K, Provider/Producer<V>> keys. So unwrap the key's type's
// value type if it's a Map<K, Provider/Producer<V>> before looking in
// delegateMultibindingDeclarations. createDelegateBindings() will create bindings with the
// properly wrapped key type.
multibindings.addAll(
createDelegateBindings(
delegateMultibindingDeclarations.get(keyFactory.unwrapMapValueType(key))));
}
return multibindings.build();
}

/**
Expand Down

0 comments on commit fec575c

Please sign in to comment.