46
46
import dagger .MembersInjector ;
47
47
import dagger .Reusable ;
48
48
import dagger .internal .codegen .base .ClearableCache ;
49
+ import dagger .internal .codegen .base .ContributionType ;
49
50
import dagger .internal .codegen .base .MapType ;
50
51
import dagger .internal .codegen .base .OptionalType ;
52
+ import dagger .internal .codegen .compileroption .CompilerOptions ;
51
53
import dagger .internal .codegen .langmodel .DaggerElements ;
52
54
import dagger .model .DependencyRequest ;
53
55
import dagger .model .Key ;
@@ -84,6 +86,7 @@ public final class BindingGraphFactory implements ClearableCache {
84
86
private final ModuleDescriptor .Factory moduleDescriptorFactory ;
85
87
private final BindingGraphConverter bindingGraphConverter ;
86
88
private final Map <Key , ImmutableSet <Key >> keysMatchingRequestCache = new HashMap <>();
89
+ private final CompilerOptions compilerOptions ;
87
90
88
91
@ Inject
89
92
BindingGraphFactory (
@@ -92,13 +95,15 @@ public final class BindingGraphFactory implements ClearableCache {
92
95
KeyFactory keyFactory ,
93
96
BindingFactory bindingFactory ,
94
97
ModuleDescriptor .Factory moduleDescriptorFactory ,
95
- BindingGraphConverter bindingGraphConverter ) {
98
+ BindingGraphConverter bindingGraphConverter ,
99
+ CompilerOptions compilerOptions ) {
96
100
this .elements = elements ;
97
101
this .injectBindingRegistry = injectBindingRegistry ;
98
102
this .keyFactory = keyFactory ;
99
103
this .bindingFactory = bindingFactory ;
100
104
this .moduleDescriptorFactory = moduleDescriptorFactory ;
101
105
this .bindingGraphConverter = bindingGraphConverter ;
106
+ this .compilerOptions = compilerOptions ;
102
107
}
103
108
104
109
/**
@@ -702,12 +707,25 @@ private boolean containsExplicitBinding(ContributionBinding binding) {
702
707
703
708
/** Returns true if {@code binding} was installed in a module in this resolver's component. */
704
709
private boolean resolverContainsDelegateDeclarationForBinding (ContributionBinding binding ) {
705
- return binding .kind ().equals (DELEGATE )
706
- && delegateDeclarations .get (binding .key ()).stream ()
707
- .anyMatch (
708
- declaration ->
709
- declaration .contributingModule ().equals (binding .contributingModule ())
710
- && declaration .bindingElement ().equals (binding .bindingElement ()));
710
+ if (!binding .kind ().equals (DELEGATE )) {
711
+ return false ;
712
+ }
713
+
714
+ // Map multibinding key values are wrapped with a framework type. This needs to be undone
715
+ // to look it up in the delegate declarations map.
716
+ // TODO(erichang): See if we can standardize the way map keys are used in these data
717
+ // structures, either always wrapped or unwrapped to be consistent and less errorprone.
718
+ Key bindingKey = binding .key ();
719
+ if (compilerOptions .strictMultibindingValidation ()
720
+ && binding .contributionType ().equals (ContributionType .MAP )) {
721
+ bindingKey = keyFactory .unwrapMapValueType (bindingKey );
722
+ }
723
+
724
+ return delegateDeclarations .get (bindingKey ).stream ()
725
+ .anyMatch (
726
+ declaration ->
727
+ declaration .contributingModule ().equals (binding .contributingModule ())
728
+ && declaration .bindingElement ().equals (binding .bindingElement ()));
711
729
}
712
730
713
731
/** Returns the resolver lineage from parent to child. */
0 commit comments