Skip to content

Commit b1b536b

Browse files
gk5885ronshapiro
authored andcommitted
Change the way we make synthetic multibindings to not depend on the type of the request; it only depends on the types of the contributions. This will now just rely on the implict conversion of Provider -> Producer that we use for all other provision bindings in production components.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130528960
1 parent 147ef93 commit b1b536b

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

compiler/src/main/java/dagger/internal/codegen/BindingGraph.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import com.google.common.collect.Maps;
5555
import com.google.common.collect.Sets;
5656
import com.google.common.collect.TreeTraverser;
57-
import com.google.common.util.concurrent.ListenableFuture;
5857
import dagger.Component;
5958
import dagger.Reusable;
6059
import dagger.internal.codegen.ComponentDescriptor.ComponentMethodDescriptor;
@@ -488,9 +487,6 @@ public Iterable<MultibindingDeclaration> apply(Key key) {
488487
* the following types, returns a {@link ProductionBinding}.
489488
*
490489
* <ul>
491-
* <li>{@link Producer Producer<SetOrMap>}
492-
* <li>{@link Produced Produced<SetOrMap>}
493-
* <li>{@link ListenableFuture ListenableFuture<SetOrMap>}
494490
* <li>{@code Set<Produced<T>>}
495491
* <li>{@code Map<K, Producer<V>>}
496492
* <li>{@code Map<K, Produced<V>>}
@@ -504,7 +500,7 @@ private Optional<? extends ContributionBinding> syntheticMultibinding(
504500
Iterable<MultibindingDeclaration> multibindingDeclarations) {
505501
if (isEmpty(multibindingContributions) && isEmpty(multibindingDeclarations)) {
506502
return Optional.absent();
507-
} else if (multibindingsRequireProduction(multibindingContributions, request)) {
503+
} else if (multibindingsRequireProduction(multibindingContributions, request.key())) {
508504
return Optional.of(
509505
productionBindingFactory.syntheticMultibinding(request, multibindingContributions));
510506
} else {
@@ -514,33 +510,17 @@ private Optional<? extends ContributionBinding> syntheticMultibinding(
514510
}
515511

516512
private boolean multibindingsRequireProduction(
517-
Iterable<ContributionBinding> multibindingContributions, DependencyRequest request) {
518-
switch (request.kind()) {
519-
case PRODUCER:
520-
case PRODUCED:
521-
case FUTURE:
513+
Iterable<ContributionBinding> multibindingContributions, Key requestKey) {
514+
if (MapType.isMap(requestKey)) {
515+
MapType mapType = MapType.from(requestKey);
516+
if (mapType.valuesAreTypeOf(Producer.class) || mapType.valuesAreTypeOf(Produced.class)) {
522517
return true;
523-
524-
case INSTANCE:
525-
case LAZY:
526-
case PROVIDER:
527-
case PROVIDER_OF_LAZY:
528-
if (MapType.isMap(request.key())) {
529-
MapType mapType = MapType.from(request.key());
530-
if (mapType.valuesAreTypeOf(Producer.class)
531-
|| mapType.valuesAreTypeOf(Produced.class)) {
532-
return true;
533-
}
534-
} else if (SetType.isSet(request.key())
535-
&& SetType.from(request.key()).elementsAreTypeOf(Produced.class)) {
536-
return true;
537-
}
538-
return Iterables.any(multibindingContributions, isOfType(BindingType.PRODUCTION));
539-
540-
case MEMBERS_INJECTOR:
541-
default:
542-
throw new AssertionError(request.kind());
518+
}
519+
} else if (SetType.isSet(requestKey)
520+
&& SetType.from(requestKey).elementsAreTypeOf(Produced.class)) {
521+
return true;
543522
}
523+
return Iterables.any(multibindingContributions, isOfType(BindingType.PRODUCTION));
544524
}
545525

546526
private ImmutableSet<ContributionBinding> createDelegateBindings(

0 commit comments

Comments
 (0)