Skip to content

Commit

Permalink
Explicitly tell BindingGraphConverter whether it's creating a full bi…
Browse files Browse the repository at this point in the history
…nding graph, or else it will prune unreachable bindings.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229407182
  • Loading branch information
netdpb authored and ronshapiro committed Jan 16, 2019
1 parent e6215df commit 13f0cbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions java/dagger/internal/codegen/BindingGraphConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ final class BindingGraphConverter {
/**
* Creates the external {@link dagger.model.BindingGraph} representing the given internal {@link
* dagger.internal.codegen.BindingGraph}.
*
* @param fullBindingGraph if {@code true}, include bindings that are not reachable from any entry
* points
*/
dagger.model.BindingGraph convert(BindingGraph bindingGraph) {
dagger.model.BindingGraph convert(BindingGraph bindingGraph, boolean fullBindingGraph) {
Traverser traverser = new Traverser(bindingGraph);
traverser.traverseComponents();

// When bindings are copied down into child graphs because they transitively depend on local
// multibindings or optional bindings, the parent-owned binding is still there. If that
// parent-owned binding is not reachable from its component, it doesn't need to be in the graph
// because it will never be used. So remove all nodes that are not reachable from the root
// component—unless the component is a module-binding validation component.
if (!bindingGraph.componentDescriptor().kind().isForModuleValidation()) {
// component—unless we're building a full binding graph.
if (!fullBindingGraph) {
unreachableNodes(traverser.network.asGraph(), rootComponentNode(traverser.network))
.forEach(traverser.network::removeNode);
}

ComponentKind componentKind = bindingGraph.componentDescriptor().kind();
return BindingGraphProxies.bindingGraph(
traverser.network, componentKind.isForModuleValidation());
return BindingGraphProxies.bindingGraph(traverser.network, fullBindingGraph);
}

// TODO(dpb): Example of BindingGraph logic applied to derived networks.
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/internal/codegen/ComponentProcessingStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected void process(
}

private boolean isValid(BindingGraph bindingGraph) {
dagger.model.BindingGraph modelGraph = bindingGraphConverter.convert(bindingGraph);
dagger.model.BindingGraph modelGraph = bindingGraphConverter.convert(bindingGraph, false);
return bindingGraphValidator.isValid(modelGraph);
}

Expand Down
2 changes: 1 addition & 1 deletion java/dagger/internal/codegen/ModuleValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private void validateModuleBindings(
TypeElement module, ValidationReport.Builder<TypeElement> report) {
BindingGraph bindingGraph =
bindingGraphConverter.convert(
bindingGraphFactory.create(componentDescriptorFactory.forTypeElement(module)));
bindingGraphFactory.create(componentDescriptorFactory.forTypeElement(module)), true);
if (!bindingGraphValidator.isValid(bindingGraph)) {
// Since the validator uses a DiagnosticReporter to report errors, the ValdiationReport won't
// have any Items for them. We have to tell the ValidationReport that some errors were
Expand Down

0 comments on commit 13f0cbe

Please sign in to comment.