2121import static dagger .internal .codegen .base .RequestKinds .getRequestKind ;
2222import static dagger .internal .codegen .base .Util .reentrantComputeIfAbsent ;
2323import static dagger .internal .codegen .binding .AssistedInjectionAnnotations .isAssistedFactoryType ;
24+ import static dagger .internal .codegen .extension .DaggerStreams .toImmutableSet ;
2425import static dagger .internal .codegen .model .BindingKind .ASSISTED_INJECTION ;
2526import static dagger .internal .codegen .model .BindingKind .DELEGATE ;
2627import static dagger .internal .codegen .model .BindingKind .INJECTION ;
3536import com .google .common .collect .ImmutableList ;
3637import com .google .common .collect .ImmutableSet ;
3738import com .google .common .collect .Iterables ;
38- import com .google .common .collect .Multimaps ;
3939import dagger .Reusable ;
4040import dagger .internal .codegen .base .ClearableCache ;
4141import dagger .internal .codegen .base .ContributionType ;
@@ -73,6 +73,7 @@ public final class BindingGraphFactory implements ClearableCache {
7373 private final InjectBindingRegistry injectBindingRegistry ;
7474 private final KeyFactory keyFactory ;
7575 private final BindingFactory bindingFactory ;
76+ private final BindingNode .Factory bindingNodeFactory ;
7677 private final ComponentDeclarations .Factory componentDeclarationsFactory ;
7778 private final BindingGraphConverter bindingGraphConverter ;
7879 private final Map <Key , ImmutableSet <Key >> keysMatchingRequestCache = new HashMap <>();
@@ -83,12 +84,14 @@ public final class BindingGraphFactory implements ClearableCache {
8384 InjectBindingRegistry injectBindingRegistry ,
8485 KeyFactory keyFactory ,
8586 BindingFactory bindingFactory ,
87+ BindingNode .Factory bindingNodeFactory ,
8688 ComponentDeclarations .Factory componentDeclarationsFactory ,
8789 BindingGraphConverter bindingGraphConverter ,
8890 CompilerOptions compilerOptions ) {
8991 this .injectBindingRegistry = injectBindingRegistry ;
9092 this .keyFactory = keyFactory ;
9193 this .bindingFactory = bindingFactory ;
94+ this .bindingNodeFactory = bindingNodeFactory ;
9295 this .componentDeclarationsFactory = componentDeclarationsFactory ;
9396 this .bindingGraphConverter = bindingGraphConverter ;
9497 this .compilerOptions = compilerOptions ;
@@ -341,13 +344,18 @@ && isAssistedFactoryType(requestKey.type().xprocessing().getTypeElement())) {
341344 .ifPresent (bindings ::add );
342345 }
343346
344- return ResolvedBindings .forContributionBindings (
345- componentPath ,
347+ return ResolvedBindings .create (
346348 requestKey ,
347- Multimaps .index (bindings , binding -> getOwningComponent (requestKey , binding )),
348- multibindingDeclarations ,
349- subcomponentDeclarations ,
350- optionalBindingDeclarations );
349+ bindings .stream ()
350+ .map (
351+ binding ->
352+ bindingNodeFactory .forContributionBindings (
353+ getOwningComponentPath (requestKey , binding ),
354+ binding ,
355+ multibindingDeclarations ,
356+ optionalBindingDeclarations ,
357+ subcomponentDeclarations ))
358+ .collect (toImmutableSet ()));
351359 }
352360
353361 /**
@@ -380,9 +388,10 @@ ResolvedBindings lookUpMembersInjectionBinding(Key requestKey) {
380388 Optional <MembersInjectionBinding > binding =
381389 injectBindingRegistry .getOrFindMembersInjectionBinding (requestKey );
382390 return binding .isPresent ()
383- ? ResolvedBindings .forMembersInjectionBinding (
384- componentPath , requestKey , componentDescriptor , binding .get ())
385- : ResolvedBindings .noBindings (componentPath , requestKey );
391+ ? ResolvedBindings .create (
392+ requestKey ,
393+ bindingNodeFactory .forMembersInjectionBinding (componentPath , binding .get ()))
394+ : ResolvedBindings .create (requestKey );
386395 }
387396
388397 /**
@@ -462,7 +471,7 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe
462471 } finally {
463472 cycleStack .pop ();
464473 }
465- if (resolvedDelegate .contributionBindings ().isEmpty ()) {
474+ if (resolvedDelegate .bindings ().isEmpty ()) {
466475 // This is guaranteed to result in a missing binding error, so it doesn't matter if the
467476 // binding is a Provision or Production, except if it is a @IntoMap method, in which
468477 // case the key will be of type Map<K, Provider<V>>, which will be "upgraded" into a
@@ -477,7 +486,7 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe
477486 // It doesn't matter which of these is selected, since they will later on produce a
478487 // duplicate binding error.
479488 ContributionBinding explicitDelegate =
480- resolvedDelegate .contributionBindings ().iterator ().next ();
489+ ( ContributionBinding ) resolvedDelegate .bindings ().iterator ().next ();
481490 return bindingFactory .delegateBinding (delegateDeclaration , explicitDelegate );
482491 }
483492
@@ -491,13 +500,13 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe
491500 * multibinding contributions in the parent, and returns the parent-resolved {@link
492501 * ResolvedBindings#owningComponent(ContributionBinding)}.
493502 */
494- private XTypeElement getOwningComponent (Key requestKey , ContributionBinding binding ) {
503+ private ComponentPath getOwningComponentPath (Key requestKey , ContributionBinding binding ) {
495504 if (isResolvedInParent (requestKey , binding ) && !requiresResolution (binding )) {
496505 ResolvedBindings parentResolvedBindings =
497506 parentResolver .get ().resolvedContributionBindings .get (requestKey );
498- return parentResolvedBindings .owningComponent (binding );
507+ return parentResolvedBindings .forBinding (binding ). componentPath ( );
499508 } else {
500- return componentDescriptor . typeElement () ;
509+ return componentPath ;
501510 }
502511 }
503512
@@ -540,8 +549,7 @@ private Optional<Resolver> getOwningResolver(ContributionBinding binding) {
540549 // If a @Reusable binding was resolved in an ancestor, use that component.
541550 ResolvedBindings resolvedBindings =
542551 requestResolver .resolvedContributionBindings .get (binding .key ());
543- if (resolvedBindings != null
544- && resolvedBindings .contributionBindings ().contains (binding )) {
552+ if (resolvedBindings != null && resolvedBindings .bindings ().contains (binding )) {
545553 return Optional .of (requestResolver );
546554 }
547555 }
@@ -740,7 +748,7 @@ && getLocalExplicitBindings(key).isEmpty()) {
740748 * component.
741749 */
742750 private void resolveDependencies (ResolvedBindings resolvedBindings ) {
743- for (Binding binding : resolvedBindings .bindingsOwnedBy ( componentDescriptor )) {
751+ for (BindingNode binding : resolvedBindings .bindingNodesOwnedBy ( componentPath )) {
744752 for (DependencyRequest dependency : binding .dependencies ()) {
745753 resolve (dependency .key ());
746754 }
@@ -870,13 +878,13 @@ private boolean hasLocalMultibindingContributions(Key requestKey) {
870878 */
871879 private boolean hasLocalOptionalBindingContribution (ResolvedBindings resolvedBindings ) {
872880 return hasLocalOptionalBindingContribution (
873- resolvedBindings .key (), resolvedBindings .contributionBindings ());
881+ resolvedBindings .key (), resolvedBindings .bindings ());
874882 }
875883
876884 private boolean hasLocalOptionalBindingContribution (
877- Key key , ImmutableSet <ContributionBinding > previousContributionBindings ) {
878- if (previousContributionBindings .stream ()
879- .map (ContributionBinding ::kind )
885+ Key key , ImmutableSet <? extends Binding > previouslyResolvedBindings ) {
886+ if (previouslyResolvedBindings .stream ()
887+ .map (Binding ::kind )
880888 .anyMatch (isEqual (OPTIONAL ))) {
881889 return !getLocalExplicitBindings (keyFactory .unwrapOptional (key ).get ())
882890 .isEmpty ();
0 commit comments