@@ -252,7 +252,7 @@ && isComponentProductionMethod(elements, method)
252
252
for (ComponentMethodDescriptor componentMethod : componentDescriptor .componentMethods ()) {
253
253
Optional <DependencyRequest > componentMethodRequest = componentMethod .dependencyRequest ();
254
254
if (componentMethodRequest .isPresent ()) {
255
- requestResolver .resolve (componentMethodRequest .get ());
255
+ requestResolver .resolve (componentMethodRequest .get (). bindingKey () );
256
256
}
257
257
}
258
258
@@ -316,35 +316,33 @@ private final class Resolver {
316
316
}
317
317
318
318
/**
319
- * Returns the bindings that satisfy a given dependency request .
319
+ * Returns the bindings for the given {@link BindingKey} .
320
320
*
321
321
* <p>For {@link BindingKey.Kind#CONTRIBUTION} requests, returns all of:
322
+ *
322
323
* <ul>
323
324
* <li>All explicit bindings for:
324
325
* <ul>
325
326
* <li>the requested key
326
327
* <li>{@code Set<T>} if the requested key's type is {@code Set<Produced<T>>}
327
- * <li>{@code Map<K, Provider<V>>} if the requested key's type is
328
- * {@code Map<K, Producer<V>>}.
328
+ * <li>{@code Map<K, Provider<V>>} if the requested key's type is {@code Map<K,
329
+ * Producer<V>>}.
329
330
* </ul>
330
331
*
331
332
* <li>A synthetic binding that depends on {@code Map<K, Producer<V>>} if the requested key's
332
- * type is {@code Map<K, V>} and there are some explicit bindings for
333
- * {@code Map<K, Producer<V>>}.
334
- *
333
+ * type is {@code Map<K, V>} and there are some explicit bindings for {@code Map<K,
334
+ * Producer<V>>}.
335
335
* <li>A synthetic binding that depends on {@code Map<K, Provider<V>>} if the requested key's
336
- * type is {@code Map<K, V>} and there are some explicit bindings for
337
- * {@code Map<K, Provider<V>>} but no explicit bindings for {@code Map<K, Producer<V>>}.
338
- *
336
+ * type is {@code Map<K, V>} and there are some explicit bindings for {@code Map<K,
337
+ * Provider<V>>} but no explicit bindings for {@code Map<K, Producer<V>>}.
339
338
* <li>An implicit {@link Inject @Inject}-annotated constructor binding if there is one and
340
339
* there are no explicit bindings or synthetic bindings.
341
340
* </ul>
342
341
*
343
- * <p>For {@link BindingKey.Kind#MEMBERS_INJECTION} requests, returns the
344
- * {@link MembersInjectionBinding} for the type.
342
+ * <p>For {@link BindingKey.Kind#MEMBERS_INJECTION} requests, returns the {@link
343
+ * MembersInjectionBinding} for the type.
345
344
*/
346
- ResolvedBindings lookUpBindings (DependencyRequest request ) {
347
- BindingKey bindingKey = request .bindingKey ();
345
+ ResolvedBindings lookUpBindings (BindingKey bindingKey ) {
348
346
Key requestKey = bindingKey .key ();
349
347
switch (bindingKey .kind ()) {
350
348
case CONTRIBUTION :
@@ -365,9 +363,10 @@ ResolvedBindings lookUpBindings(DependencyRequest request) {
365
363
ImmutableSet <MultibindingDeclaration > multibindingDeclarations =
366
364
multibindingDeclarationsBuilder .build ();
367
365
368
- contributionBindings .addAll (syntheticMapOfValuesBinding (request ).asSet ());
366
+ contributionBindings .addAll (syntheticMapOfValuesBinding (bindingKey . key () ).asSet ());
369
367
contributionBindings .addAll (
370
- syntheticMultibinding (request , multibindingContributions , multibindingDeclarations )
368
+ syntheticMultibinding (
369
+ bindingKey .key (), multibindingContributions , multibindingDeclarations )
371
370
.asSet ());
372
371
373
372
/* If there are no bindings, add the implicit @Inject-constructed binding if there is
@@ -380,7 +379,8 @@ ResolvedBindings lookUpBindings(DependencyRequest request) {
380
379
return ResolvedBindings .forContributionBindings (
381
380
bindingKey ,
382
381
componentDescriptor ,
383
- indexBindingsByOwningComponent (request , ImmutableSet .copyOf (contributionBindings )),
382
+ indexBindingsByOwningComponent (
383
+ bindingKey , ImmutableSet .copyOf (contributionBindings )),
384
384
multibindingDeclarations );
385
385
386
386
case MEMBERS_INJECTION :
@@ -407,32 +407,29 @@ private Iterable<Key> keysMatchingRequest(Key requestKey) {
407
407
}
408
408
409
409
/**
410
- * If {@code request} is for a {@code Map<K, V>} or {@code Map<K, Produced<V>>}, and there are
411
- * any multibinding contributions or declarations that apply to that map, returns a synthetic
412
- * binding for the {@code request} that depends on an {@linkplain
413
- * #syntheticMultibinding(DependencyRequest, Iterable, Iterable) underlying synthetic
414
- * multibinding}.
410
+ * If {@code key} is a {@code Map<K, V>} or {@code Map<K, Produced<V>>}, and there are any
411
+ * multibinding contributions or declarations that apply to that map, returns a synthetic
412
+ * binding for the {@code key} that depends on an {@linkplain #syntheticMultibinding(Key,
413
+ * Iterable, Iterable) underlying synthetic multibinding}.
415
414
*
416
415
* <p>The returned binding has the same {@link BindingType} as the underlying synthetic
417
416
* multibinding.
418
417
*/
419
- private Optional <ContributionBinding > syntheticMapOfValuesBinding (
420
- final DependencyRequest request ) {
418
+ private Optional <ContributionBinding > syntheticMapOfValuesBinding (final Key key ) {
421
419
return syntheticMultibinding (
422
- request ,
423
- multibindingContributionsForValueMap (request . key () ),
424
- multibindingDeclarationsForValueMap (request . key () ))
420
+ key ,
421
+ multibindingContributionsForValueMap (key ),
422
+ multibindingDeclarationsForValueMap (key ))
425
423
.transform (
426
424
new Function <ContributionBinding , ContributionBinding >() {
427
425
@ Override
428
426
public ContributionBinding apply (ContributionBinding syntheticMultibinding ) {
429
427
switch (syntheticMultibinding .bindingType ()) {
430
428
case PROVISION :
431
- return provisionBindingFactory .syntheticMapOfValuesBinding (request );
429
+ return provisionBindingFactory .syntheticMapOfValuesBinding (key );
432
430
433
431
case PRODUCTION :
434
- return productionBindingFactory .syntheticMapOfValuesOrProducedBinding (
435
- request );
432
+ return productionBindingFactory .syntheticMapOfValuesOrProducedBinding (key );
436
433
437
434
default :
438
435
throw new VerifyException (syntheticMultibinding .toString ());
@@ -495,17 +492,17 @@ public Iterable<MultibindingDeclaration> apply(Key key) {
495
492
* Otherwise, returns a {@link ProvisionBinding}.
496
493
*/
497
494
private Optional <? extends ContributionBinding > syntheticMultibinding (
498
- DependencyRequest request ,
495
+ Key key ,
499
496
Iterable <ContributionBinding > multibindingContributions ,
500
497
Iterable <MultibindingDeclaration > multibindingDeclarations ) {
501
498
if (isEmpty (multibindingContributions ) && isEmpty (multibindingDeclarations )) {
502
499
return Optional .absent ();
503
- } else if (multibindingsRequireProduction (multibindingContributions , request . key () )) {
500
+ } else if (multibindingsRequireProduction (multibindingContributions , key )) {
504
501
return Optional .of (
505
- productionBindingFactory .syntheticMultibinding (request , multibindingContributions ));
502
+ productionBindingFactory .syntheticMultibinding (key , multibindingContributions ));
506
503
} else {
507
504
return Optional .of (
508
- provisionBindingFactory .syntheticMultibinding (request , multibindingContributions ));
505
+ provisionBindingFactory .syntheticMultibinding (key , multibindingContributions ));
509
506
}
510
507
}
511
508
@@ -539,7 +536,8 @@ private ImmutableSet<ContributionBinding> createDelegateBindings(
539
536
* delegate key.
540
537
*/
541
538
private ContributionBinding createDelegateBinding (DelegateDeclaration delegateDeclaration ) {
542
- ResolvedBindings resolvedDelegate = lookUpBindings (delegateDeclaration .delegateRequest ());
539
+ ResolvedBindings resolvedDelegate =
540
+ lookUpBindings (delegateDeclaration .delegateRequest ().bindingKey ());
543
541
if (resolvedDelegate .contributionBindings ().isEmpty ()) {
544
542
// This is guaranteed to result in a missing binding error, so it doesn't matter if the
545
543
// binding is a Provision or Production, except if it is a @IntoMap method, in which
@@ -572,11 +570,11 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe
572
570
573
571
private ImmutableSetMultimap <ComponentDescriptor , ContributionBinding >
574
572
indexBindingsByOwningComponent (
575
- DependencyRequest request , Iterable <? extends ContributionBinding > bindings ) {
573
+ BindingKey bindingKey , Iterable <? extends ContributionBinding > bindings ) {
576
574
ImmutableSetMultimap .Builder <ComponentDescriptor , ContributionBinding > index =
577
575
ImmutableSetMultimap .builder ();
578
576
for (ContributionBinding binding : bindings ) {
579
- index .put (getOwningComponent (request , binding ), binding );
577
+ index .put (getOwningComponent (bindingKey , binding ), binding );
580
578
}
581
579
return index .build ();
582
580
}
@@ -588,31 +586,31 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe
588
586
* multibinding contributions in this component, returns this component.
589
587
*
590
588
* <p>Otherwise, resolves {@code request} in this component's parent in order to resolve any
591
- * multibinding contributions in the parent, and returns the parent-resolved
592
- * {@link ResolvedBindings#owningComponent(ContributionBinding)}.
589
+ * multibinding contributions in the parent, and returns the parent-resolved {@link
590
+ * ResolvedBindings#owningComponent(ContributionBinding)}.
593
591
*/
594
592
private ComponentDescriptor getOwningComponent (
595
- DependencyRequest request , ContributionBinding binding ) {
596
- if (isResolvedInParent (request , binding )
593
+ BindingKey bindingKey , ContributionBinding binding ) {
594
+ if (isResolvedInParent (bindingKey , binding )
597
595
&& !new MultibindingDependencies ().dependsOnLocalMultibindings (binding )) {
598
596
ResolvedBindings parentResolvedBindings =
599
- parentResolver .get ().resolvedBindings .get (request . bindingKey () );
597
+ parentResolver .get ().resolvedBindings .get (bindingKey );
600
598
return parentResolvedBindings .owningComponent (binding );
601
599
} else {
602
600
return componentDescriptor ;
603
601
}
604
602
}
605
603
606
604
/**
607
- * Returns {@code true} if {@code binding} is owned by an ancestor. If so,
608
- * {@linkplain #resolve(DependencyRequest) resolves} the request in this component's parent.
609
- * Don't resolve directly in the owning component in case it depends on multibindings in any
610
- * of its descendants.
605
+ * Returns {@code true} if {@code binding} is owned by an ancestor. If so, {@linkplain
606
+ * #resolve resolves} the {@link BindingKey} in this component's parent. Don't resolve
607
+ * directly in the owning component in case it depends on multibindings in any of its
608
+ * descendants.
611
609
*/
612
- private boolean isResolvedInParent (DependencyRequest request , ContributionBinding binding ) {
610
+ private boolean isResolvedInParent (BindingKey bindingKey , ContributionBinding binding ) {
613
611
Optional <Resolver > owningResolver = getOwningResolver (binding );
614
612
if (owningResolver .isPresent () && !owningResolver .get ().equals (this )) {
615
- parentResolver .get ().resolve (request );
613
+ parentResolver .get ().resolve (bindingKey );
616
614
return true ;
617
615
} else {
618
616
return false ;
@@ -724,9 +722,7 @@ private Optional<ResolvedBindings> getPreviouslyResolvedBindings(
724
722
}
725
723
}
726
724
727
- void resolve (DependencyRequest request ) {
728
- BindingKey bindingKey = request .bindingKey ();
729
-
725
+ void resolve (BindingKey bindingKey ) {
730
726
// If we find a cycle, stop resolving. The original request will add it with all of the
731
727
// other resolved deps.
732
728
if (cycleStack .contains (bindingKey )) {
@@ -750,7 +746,7 @@ void resolve(DependencyRequest request) {
750
746
if (getPreviouslyResolvedBindings (bindingKey ).isPresent ()) {
751
747
/* Resolve in the parent in case there are multibinding contributions or conflicts in some
752
748
* component between this one and the previously-resolved one. */
753
- parentResolver .get ().resolve (request );
749
+ parentResolver .get ().resolve (bindingKey );
754
750
if (!new MultibindingDependencies ().dependsOnLocalMultibindings (bindingKey )
755
751
&& getExplicitBindings (bindingKey .key ()).isEmpty ()) {
756
752
/* Cache the inherited parent component's bindings in case resolving at the parent found
@@ -764,10 +760,10 @@ && getExplicitBindings(bindingKey.key()).isEmpty()) {
764
760
765
761
cycleStack .push (bindingKey );
766
762
try {
767
- ResolvedBindings bindings = lookUpBindings (request );
763
+ ResolvedBindings bindings = lookUpBindings (bindingKey );
768
764
for (Binding binding : bindings .ownedBindings ()) {
769
765
for (DependencyRequest dependency : binding .implicitDependencies ()) {
770
- resolve (dependency );
766
+ resolve (dependency . bindingKey () );
771
767
}
772
768
}
773
769
resolvedBindings .put (bindingKey , bindings );
0 commit comments