Skip to content

Commit 537acb9

Browse files
bcorsoDagger Team
authored andcommitted
Add ComponentDescriptor#bindings(), similar to ModuleDescriptor#bindings() to easily access the bindings of a component.
This CL also moves the various `Map<Key, BindingDeclaration>` state from `BindingGraphFactory` into a new class, `ComponentDeclarations`, that encapsulates all of the various declarations of a component into a single location RELNOTES=N/A PiperOrigin-RevId: 646464552
1 parent b2a1fe6 commit 537acb9

File tree

4 files changed

+400
-254
lines changed

4 files changed

+400
-254
lines changed

java/dagger/internal/codegen/binding/BindingFactory.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static com.google.common.base.Preconditions.checkNotNull;
2424
import static com.google.common.base.Preconditions.checkState;
2525
import static com.google.common.collect.Iterables.getOnlyElement;
26-
import static dagger.internal.codegen.binding.ComponentDescriptor.isComponentProductionMethod;
2726
import static dagger.internal.codegen.binding.MapKeys.getMapKey;
2827
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
2928
import static dagger.internal.codegen.model.BindingKind.ASSISTED_FACTORY;
@@ -315,33 +314,28 @@ public ProvisionBinding componentDependencyBinding(ComponentRequirement dependen
315314
.build();
316315
}
317316

318-
/**
319-
* Returns a {@link dagger.internal.codegen.model.BindingKind#COMPONENT_PROVISION} or {@link
320-
* dagger.internal.codegen.model.BindingKind#COMPONENT_PRODUCTION} binding for a method on a
321-
* component's dependency.
322-
*
323-
* @param componentDescriptor the component with the dependency, not the dependency that has the
324-
* method
325-
*/
326-
public ContributionBinding componentDependencyMethodBinding(
327-
ComponentDescriptor componentDescriptor, XMethodElement dependencyMethod) {
317+
/** Returns a {@link BindingKind#COMPONENT_PROVISION} binding. */
318+
public ContributionBinding componentDependencyProvisionMethodBinding(
319+
XMethodElement dependencyMethod) {
328320
checkArgument(dependencyMethod.getParameters().isEmpty());
329-
ContributionBinding.Builder<?, ?> builder;
330-
if (componentDescriptor.isProduction() && isComponentProductionMethod(dependencyMethod)) {
331-
builder =
332-
ProductionBinding.builder()
333-
.key(keyFactory.forProductionComponentMethod(dependencyMethod))
334-
.kind(COMPONENT_PRODUCTION)
335-
.thrownTypes(dependencyMethod.getThrownTypes());
336-
} else {
337-
builder =
338-
ProvisionBinding.builder()
339-
.key(keyFactory.forComponentMethod(dependencyMethod))
340-
.nullability(Nullability.of(dependencyMethod))
341-
.kind(COMPONENT_PROVISION)
342-
.scope(injectionAnnotations.getScope(dependencyMethod));
343-
}
344-
return builder
321+
return ProvisionBinding.builder()
322+
.key(keyFactory.forComponentMethod(dependencyMethod))
323+
.nullability(Nullability.of(dependencyMethod))
324+
.kind(COMPONENT_PROVISION)
325+
.scope(injectionAnnotations.getScope(dependencyMethod))
326+
.contributionType(ContributionType.UNIQUE)
327+
.bindingElement(dependencyMethod)
328+
.build();
329+
}
330+
331+
/** Returns a {@link BindingKind#COMPONENT_PRODUCTION} binding. */
332+
public ContributionBinding componentDependencyProductionMethodBinding(
333+
XMethodElement dependencyMethod) {
334+
checkArgument(dependencyMethod.getParameters().isEmpty());
335+
return ProductionBinding.builder()
336+
.key(keyFactory.forProductionComponentMethod(dependencyMethod))
337+
.kind(COMPONENT_PRODUCTION)
338+
.thrownTypes(dependencyMethod.getThrownTypes())
345339
.contributionType(ContributionType.UNIQUE)
346340
.bindingElement(dependencyMethod)
347341
.build();

0 commit comments

Comments
 (0)