Skip to content

Commit

Permalink
Internal changes
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 666104552
  • Loading branch information
wanyingd1996 authored and Dagger Team committed Aug 22, 2024
1 parent 4a0a5e9 commit a15cf23
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
10 changes: 1 addition & 9 deletions java/dagger/internal/codegen/binding/BindingGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.google.common.graph.ImmutableNetwork;
import com.google.common.graph.Traverser;
import dagger.internal.codegen.base.TarjanSCCs;
import dagger.internal.codegen.binding.ComponentDescriptor.ComponentMethodDescriptor;
import dagger.internal.codegen.model.BindingGraph.ChildFactoryMethodEdge;
import dagger.internal.codegen.model.BindingGraph.ComponentNode;
import dagger.internal.codegen.model.BindingGraph.DependencyEdge;
Expand Down Expand Up @@ -75,8 +74,7 @@ public abstract class BindingGraph {
public abstract static class TopLevelBindingGraph
extends dagger.internal.codegen.model.BindingGraph {
static TopLevelBindingGraph create(
ImmutableNetwork<Node, Edge> network,
boolean isFullBindingGraph) {
ImmutableNetwork<Node, Edge> network, boolean isFullBindingGraph) {
TopLevelBindingGraph topLevelBindingGraph =
new AutoValue_BindingGraph_TopLevelBindingGraph(network, isFullBindingGraph);

Expand Down Expand Up @@ -280,12 +278,6 @@ public final ComponentDescriptor componentDescriptor() {
return ((ComponentNodeImpl) componentNode()).componentDescriptor();
}

/** Returns all entry point methods for this component. */
public final ImmutableSet<ComponentMethodDescriptor> entryPointMethods() {
return componentDescriptor().entryPointMethods().stream()
.collect(toImmutableSet());
}

/**
* Returns the {@link ContributionBinding} for the given {@link Key} in this component or {@link
* Optional#empty()} if one doesn't exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ BindingGraph convert(LegacyBindingGraph legacyBindingGraph, boolean isFullBindin
}

TopLevelBindingGraph topLevelBindingGraph =
TopLevelBindingGraph.create(
ImmutableNetwork.copyOf(network),
isFullBindingGraph);
TopLevelBindingGraph.create(ImmutableNetwork.copyOf(network), isFullBindingGraph);
return BindingGraph.create(rootNode, topLevelBindingGraph);
}

Expand Down
14 changes: 14 additions & 0 deletions java/dagger/internal/codegen/binding/ComponentDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ final ComponentDescriptor getChildComponentWithBuilderType(XTypeElement builderT
builderType.getQualifiedName());
}

/** Returns the first component method associated with this binding request, if one exists. */
public Optional<ComponentMethodDescriptor> firstMatchingComponentMethod(BindingRequest request) {
return Optional.ofNullable(firstMatchingComponentMethods().get(request));
}

@Memoized
ImmutableMap<BindingRequest, ComponentMethodDescriptor> firstMatchingComponentMethods() {
Map<BindingRequest, ComponentMethodDescriptor> methods = new HashMap<>();
for (ComponentMethodDescriptor method : entryPointMethods()) {
methods.putIfAbsent(BindingRequest.bindingRequest(method.dependencyRequest().get()), method);
}
return ImmutableMap.copyOf(methods);
}

/** The entry point methods on the component type. Each has a {@link DependencyRequest}. */
public final ImmutableSet<ComponentMethodDescriptor> entryPointMethods() {
return componentMethods().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Sets;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
Expand Down Expand Up @@ -92,7 +93,6 @@
import dagger.internal.codegen.xprocessing.XTypeElements;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -443,7 +443,7 @@ public TypeSpec generate() {
/**
* The implementation of a shard.
*
* <p>The purpose of a shard is to allow a component implementation to be split into multiple
* <p>The purpose of a shard is to allow a component implemenation to be split into multiple
* classes, where each class owns the creation logic for a set of keys. Sharding is useful for
* large component implementations, where a single component implementation class can reach size
* limitations, such as the constant pool size.
Expand Down Expand Up @@ -886,11 +886,10 @@ private void addInterfaceMethods() {
// Each component method may have been declared by several supertypes. We want to implement
// only one method for each distinct signature.
XType componentType = graph.componentTypeElement().getType();
Set<MethodSignature> methodDescriptors = new HashSet<>();
for (ComponentMethodDescriptor method : graph.entryPointMethods()) {
MethodSignature signature =
MethodSignature.forComponentMethod(method, componentType, processingEnv);
if (methodDescriptors.add(signature)) {
Set<MethodSignature> signatures = Sets.newHashSet();
for (ComponentMethodDescriptor method : graph.componentDescriptor().entryPointMethods()) {
if (signatures.add(
MethodSignature.forComponentMethod(method, componentType, processingEnv))) {
addMethod(
COMPONENT_METHOD,
componentRequestRepresentationsProvider.get().getComponentMethod(method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ RequestRepresentation wrapInMethod(RequestRepresentation bindingExpression) {

BindingRequest request = bindingRequest(binding.key(), RequestKind.INSTANCE);
Optional<ComponentMethodDescriptor> matchingComponentMethod =
firstMatchingComponentMethod(request, graph);
graph.componentDescriptor().firstMatchingComponentMethod(request);

ShardImplementation shardImplementation = componentImplementation.shardImplementation(binding);

Expand Down Expand Up @@ -133,16 +133,6 @@ RequestRepresentation wrapInMethod(RequestRepresentation bindingExpression) {
}
}

private static Optional<ComponentMethodDescriptor> firstMatchingComponentMethod(
BindingRequest request, BindingGraph graph) {
for (ComponentMethodDescriptor method : graph.entryPointMethods()) {
if (bindingRequest(method.dependencyRequest().get()).equals(request)) {
return Optional.of(method);
}
}
return Optional.empty();
}

private static boolean requiresMethodEncapsulation(ContributionBinding binding) {
switch (binding.kind()) {
case COMPONENT:
Expand Down

0 comments on commit a15cf23

Please sign in to comment.