@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { if (!compilerOptions.usesProducers()) { return; } Key productionImplementationExecutorKey = keyFactory.forProductionImplementationExecutor(); Key productionExecutorKey = keyFactory.forProductionExecutor(); bindingGraph.network().nodes().stream() .flatMap(instancesOf(MaybeBinding.class)) .filter(node -> node.key().equals(productionExecutorKey)) .flatMap(productionExecutor -> bindingGraph.requestingBindings(productionExecutor).stream()) .filter(binding -> !binding.key().equals(productionImplementationExecutorKey)) .forEach(binding -> reportError(diagnosticReporter, binding)); }
/** Returns the subgraph containing only {@link DependencyEdge}s that would not break a cycle. */ // TODO(dpb): Return a network containing only Binding nodes. private ImmutableNetwork<Node, DependencyEdge> nonCycleBreakingDependencyGraph( BindingGraph bindingGraph) { MutableNetwork<Node, DependencyEdge> dependencyNetwork = NetworkBuilder.from(bindingGraph.network()) .expectedNodeCount(bindingGraph.network().nodes().size()) .expectedEdgeCount(bindingGraph.dependencyEdges().size()) .build(); bindingGraph.dependencyEdges().stream() .filter(edge -> !breaksCycle(edge, bindingGraph)) .forEach( edge -> { EndpointPair<Node> endpoints = bindingGraph.network().incidentNodes(edge); dependencyNetwork.addEdge(endpoints.source(), endpoints.target(), edge); }); return ImmutableNetwork.copyOf(dependencyNetwork); }