Lines Matching full:binding

22 import static dagger.internal.codegen.binding.BindingRequest.bindingRequest;
40 import dagger.internal.codegen.binding.Binding;
41 import dagger.internal.codegen.binding.BindingGraph;
42 import dagger.internal.codegen.binding.BindingNode;
43 import dagger.internal.codegen.binding.BindingRequest;
44 import dagger.internal.codegen.binding.BindingType;
45 import dagger.internal.codegen.binding.ComponentDescriptor.ComponentMethodDescriptor;
46 import dagger.internal.codegen.binding.ComponentRequirement;
47 import dagger.internal.codegen.binding.ContributionBinding;
48 import dagger.internal.codegen.binding.FrameworkType;
49 import dagger.internal.codegen.binding.FrameworkTypeMapper;
50 import dagger.internal.codegen.binding.MembersInjectionBinding;
51 import dagger.internal.codegen.binding.ProvisionBinding;
71 /** A central repository of code expressions used to access any binding available to a component. */
125 * Returns an expression that evaluates to the value of a binding request for a binding owned by
129 * @throws IllegalStateException if there is no binding expression that satisfies the request
139 * @throws IllegalStateException if there is no binding expression that satisfies the request
151 * method for the given {@link ContributionBinding binding}.
153 CodeBlock getCreateMethodArgumentsCodeBlock(ContributionBinding binding) { in getCreateMethodArgumentsCodeBlock() argument
154 return makeParametersCodeBlock(getCreateMethodArgumentsCodeBlocks(binding)); in getCreateMethodArgumentsCodeBlock()
157 private ImmutableList<CodeBlock> getCreateMethodArgumentsCodeBlocks(ContributionBinding binding) { in getCreateMethodArgumentsCodeBlocks() argument
160 if (binding.requiresModuleInstance()) { in getCreateMethodArgumentsCodeBlocks()
163 ComponentRequirement.forModule(binding.contributingModule().get().asType()), in getCreateMethodArgumentsCodeBlocks()
167 binding.dependencies().stream() in getCreateMethodArgumentsCodeBlocks()
168 .map(dependency -> frameworkRequest(binding, dependency)) in getCreateMethodArgumentsCodeBlocks()
177 ContributionBinding binding, DependencyRequest dependency) { in frameworkRequest() argument
180 FrameworkTypeMapper.forBindingType(binding.bindingType()) in frameworkRequest()
187 * binding method, an {@code @Inject}-annotated constructor or member, or a proxy for one.
220 // Even though this is not used if the method is abstract, we need to invoke the binding in getComponentMethod()
236 Optional<Binding> optionalBinding = in getBindingExpression()
243 // The binding used for the binding expression depends on the request: in getBindingExpression()
251 // We expect at most one binding to match since this graph is already validated. in getBindingExpression()
264 /** Creates a binding expression. */
265 private BindingExpression createBindingExpression(Binding binding, BindingRequest request) { in createBindingExpression() argument
266 switch (binding.bindingType()) { in createBindingExpression()
270 (MembersInjectionBinding) binding, membersInjectionMethods); in createBindingExpression()
273 return provisionBindingExpression((ContributionBinding) binding, request); in createBindingExpression()
276 return productionBindingExpression((ContributionBinding) binding, request); in createBindingExpression()
278 throw new AssertionError(binding); in createBindingExpression()
282 * Returns a binding expression that uses a {@link javax.inject.Provider} for provision bindings
285 private BindingExpression frameworkInstanceBindingExpression(ContributionBinding binding) { in frameworkInstanceBindingExpression() argument
288 useStaticFactoryCreation(binding) ? staticFactoryCreation(binding) : Optional.empty(); in frameworkInstanceBindingExpression()
294 binding, in frameworkInstanceBindingExpression()
295 binding.scope().isPresent() in frameworkInstanceBindingExpression()
296 ? scope(binding, frameworkInstanceCreationExpression(binding)) in frameworkInstanceBindingExpression()
297 : frameworkInstanceCreationExpression(binding)); in frameworkInstanceBindingExpression()
299 switch (binding.bindingType()) { in frameworkInstanceBindingExpression()
302 binding, frameworkInstanceSupplier, types, elements); in frameworkInstanceBindingExpression()
305 binding, frameworkInstanceSupplier, types, elements, componentImplementation); in frameworkInstanceBindingExpression()
307 throw new AssertionError("invalid binding type: " + binding.bindingType()); in frameworkInstanceBindingExpression()
312 ContributionBinding binding, FrameworkInstanceCreationExpression unscoped) { in scope() argument
316 binding.scope().get().isReusable() ? SINGLE_CHECK : DOUBLE_CHECK, in scope()
325 ContributionBinding binding) { in frameworkInstanceCreationExpression() argument
326 switch (binding.kind()) { in frameworkInstanceCreationExpression()
330 () -> CodeBlock.of("($T) this", binding.key().type())); in frameworkInstanceCreationExpression()
334 binding, ComponentRequirement.forBoundInstance(binding)); in frameworkInstanceCreationExpression()
338 binding, ComponentRequirement.forDependency(binding.key().type())); in frameworkInstanceCreationExpression()
342 binding, in frameworkInstanceCreationExpression()
350 binding, this, componentImplementation.name()); in frameworkInstanceCreationExpression()
356 return new InjectionOrProvisionProviderCreationExpression(binding, this); in frameworkInstanceCreationExpression()
360 binding, componentImplementation, componentRequirementExpressions, graph); in frameworkInstanceCreationExpression()
363 return new ProducerCreationExpression(binding, this); in frameworkInstanceCreationExpression()
366 return new SetFactoryCreationExpression(binding, componentImplementation, this, graph); in frameworkInstanceCreationExpression()
370 binding, componentImplementation, this, graph, elements); in frameworkInstanceCreationExpression()
374 binding, componentImplementation, this); in frameworkInstanceCreationExpression()
378 optionalFactories, binding, componentImplementation, this); in frameworkInstanceCreationExpression()
381 return new MembersInjectorProviderCreationExpression((ProvisionBinding) binding, this); in frameworkInstanceCreationExpression()
384 throw new AssertionError(binding); in frameworkInstanceCreationExpression()
389 ContributionBinding binding, ComponentRequirement componentRequirement) { in instanceFactoryCreationExpression() argument
391 binding.nullableType().isPresent(), in instanceFactoryCreationExpression()
397 /** Returns a binding expression for a provision binding. */
399 ContributionBinding binding, BindingRequest request) { in provisionBindingExpression() argument
405 return producerFromProviderBindingExpression(binding); in provisionBindingExpression()
411 return instanceBindingExpression(binding); in provisionBindingExpression()
414 return providerBindingExpression(binding); in provisionBindingExpression()
423 return producerFromProviderBindingExpression(binding); in provisionBindingExpression()
435 /** Returns a binding expression for a production binding. */
437 ContributionBinding binding, BindingRequest request) { in productionBindingExpression() argument
439 return frameworkInstanceBindingExpression(binding); in productionBindingExpression()
449 * Returns a binding expression for {@link RequestKind#PROVIDER} requests.
460 private BindingExpression providerBindingExpression(ContributionBinding binding) { in providerBindingExpression() argument
461 if (binding.kind().equals(DELEGATE) && !needsCaching(binding)) { in providerBindingExpression()
462 return new DelegateBindingExpression(binding, RequestKind.PROVIDER, this, types, elements); in providerBindingExpression()
465 && frameworkInstanceCreationExpression(binding).useInnerSwitchingProvider() in providerBindingExpression()
466 && !(instanceBindingExpression(binding) in providerBindingExpression()
469 binding, in providerBindingExpression()
470 bindingRequest(binding.key(), RequestKind.PROVIDER), in providerBindingExpression()
471 innerSwitchingProviders.newBindingExpression(binding)); in providerBindingExpression()
473 return frameworkInstanceBindingExpression(binding); in providerBindingExpression()
477 * Returns a binding expression that uses a {@link dagger.producers.Producer} field for a
478 * provision binding.
481 ContributionBinding binding) { in producerFromProviderBindingExpression() argument
482 checkArgument(binding.bindingType().equals(BindingType.PROVISION)); in producerFromProviderBindingExpression()
484 binding, in producerFromProviderBindingExpression()
487 binding, in producerFromProviderBindingExpression()
488 new ProducerFromProviderCreationExpression(binding, componentImplementation, this)), in producerFromProviderBindingExpression()
495 * Returns a binding expression for {@link RequestKind#INSTANCE} requests.
498 * instance of this binding, return it, wrapped in a method if the binding {@linkplain
501 * <p>In fastInit mode, we can use direct expressions unless the binding needs to be cached.
503 private BindingExpression instanceBindingExpression(ContributionBinding binding) { in instanceBindingExpression() argument
505 unscopedDirectInstanceExpression(binding); in instanceBindingExpression()
506 if (canUseDirectInstanceExpression(binding) && maybeDirectInstanceExpression.isPresent()) { in instanceBindingExpression()
508 return directInstanceExpression.requiresMethodEncapsulation() || needsCaching(binding) in instanceBindingExpression()
510 binding, in instanceBindingExpression()
511 bindingRequest(binding.key(), RequestKind.INSTANCE), in instanceBindingExpression()
516 binding.key(), FrameworkType.PROVIDER, RequestKind.INSTANCE, this, types); in instanceBindingExpression()
520 * Returns an unscoped binding expression for an {@link RequestKind#INSTANCE} that does not call
524 ContributionBinding binding) { in unscopedDirectInstanceExpression() argument
525 switch (binding.kind()) { in unscopedDirectInstanceExpression()
528 new DelegateBindingExpression(binding, RequestKind.INSTANCE, this, types, elements)); in unscopedDirectInstanceExpression()
532 new ComponentInstanceBindingExpression(binding, componentImplementation.name())); in unscopedDirectInstanceExpression()
537 binding, in unscopedDirectInstanceExpression()
538 ComponentRequirement.forDependency(binding.key().type()), in unscopedDirectInstanceExpression()
544 (ProvisionBinding) binding, in unscopedDirectInstanceExpression()
552 binding, componentImplementation.getSubcomponentCreatorSimpleName(binding.key()))); in unscopedDirectInstanceExpression()
556 new SetBindingExpression((ProvisionBinding) binding, graph, this, types, elements)); in unscopedDirectInstanceExpression()
560 new MapBindingExpression((ProvisionBinding) binding, graph, this, types, elements)); in unscopedDirectInstanceExpression()
564 new OptionalBindingExpression((ProvisionBinding) binding, this, types, sourceVersion)); in unscopedDirectInstanceExpression()
569 binding, in unscopedDirectInstanceExpression()
570 ComponentRequirement.forBoundInstance(binding), in unscopedDirectInstanceExpression()
576 (ProvisionBinding) binding, this, types, elements)); in unscopedDirectInstanceExpression()
583 (ProvisionBinding) binding, in unscopedDirectInstanceExpression()
598 throw new IllegalArgumentException(binding.kind().toString()); in unscopedDirectInstanceExpression()
600 throw new AssertionError("Unexpected binding kind: " + binding.kind()); in unscopedDirectInstanceExpression()
605 * Returns {@code true} if the binding should use the static factory creation strategy.
612 private boolean useStaticFactoryCreation(ContributionBinding binding) { in useStaticFactoryCreation() argument
615 || binding.kind().equals(MULTIBOUND_MAP) in useStaticFactoryCreation()
616 || binding.kind().equals(MULTIBOUND_SET); in useStaticFactoryCreation()
621 * binding. If the binding doesn't {@linkplain #needsCaching(ContributionBinding) need to be
622 * cached} and the binding is not an {@link BindingKind.ASSISTED_FACTORY}, we can.
624 * <p>In fastInit mode, we can use a direct expression even if the binding {@linkplain
627 private boolean canUseDirectInstanceExpression(ContributionBinding binding) { in canUseDirectInstanceExpression() argument
628 return (!needsCaching(binding) && binding.kind() != BindingKind.ASSISTED_FACTORY) in canUseDirectInstanceExpression()
634 * Returns a binding expression that uses a given one as the body of a method that users call. If
636 * match a component provision method and the binding is modifiable, then a new public modifiable
637 * binding method will be written. If the binding doesn't match a component method and is not
641 ContributionBinding binding, BindingRequest request, BindingExpression bindingExpression) { in wrapInMethod() argument
648 methodImplementationStrategy(binding, request); in wrapInMethod()
652 ComponentImplementation shard = componentImplementation.shardImplementation(binding.key()); in wrapInMethod()
673 binding, in wrapInMethod()
682 binding, in wrapInMethod()
692 ContributionBinding binding, BindingRequest request) { in methodImplementationStrategy() argument
697 } else if (request.isRequestKind(RequestKind.INSTANCE) && needsCaching(binding)) { in methodImplementationStrategy()
698 return binding.scope().get().isReusable() in methodImplementationStrategy()
712 private boolean needsCaching(ContributionBinding binding) { in needsCaching() argument
713 if (!binding.scope().isPresent()) { in needsCaching()
716 if (binding.kind().equals(DELEGATE)) { in needsCaching()
717 return isBindsScopeStrongerThanDependencyScope(binding, graph); in needsCaching()