Converts dagger.internal.codegen.BindingGraphs to dagger.model.BindingGraphs.
| 44 | |
| 45 | /** Converts {@link dagger.internal.codegen.BindingGraph}s to {@link dagger.model.BindingGraph}s. */ |
| 46 | final class BindingGraphConverter extends ComponentTreeTraverser { |
| 47 | |
| 48 | private final MutableNetwork<Node, Edge> network = |
| 49 | NetworkBuilder.directed().allowsParallelEdges(true).allowsSelfLoops(true).build(); |
| 50 | |
| 51 | private ComponentNode parentComponent; |
| 52 | private ComponentNode currentComponent; |
| 53 | |
| 54 | private BindingGraphConverter(BindingGraph graph) { |
| 55 | super(graph); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates the external {@link dagger.model.BindingGraph} representing the given internal root |
| 60 | * {@link dagger.internal.codegen.BindingGraph}. |
| 61 | */ |
| 62 | static dagger.model.BindingGraph convert(BindingGraph graph) { |
| 63 | BindingGraphConverter converter = new BindingGraphConverter(graph); |
| 64 | converter.traverseComponents(); |
| 65 | return BindingGraphProxies.bindingGraph(converter.network); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | protected void visitComponent(BindingGraph graph) { |
| 70 | ComponentNode grandparentNode = parentComponent; |
| 71 | parentComponent = currentComponent; |
| 72 | currentComponent = componentNode(componentTreePath().toComponentPath()); |
| 73 | network.addNode(currentComponent); |
| 74 | super.visitComponent(graph); |
| 75 | currentComponent = parentComponent; |
| 76 | parentComponent = grandparentNode; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | protected void visitSubcomponentFactoryMethod( |
| 81 | BindingGraph graph, BindingGraph parent, ExecutableElement factoryMethod) { |
| 82 | network.addEdge(parentComponent, currentComponent, childFactoryMethodEdge(factoryMethod)); |
| 83 | super.visitSubcomponentFactoryMethod(graph, parent, factoryMethod); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | protected BindingGraphTraverser bindingGraphTraverser( |
| 88 | ComponentTreePath componentTreePath, ComponentMethodDescriptor entryPointMethod) { |
| 89 | return new BindingGraphVisitor(componentTreePath, entryPointMethod); |
| 90 | } |
| 91 | |
| 92 | private final class BindingGraphVisitor extends BindingGraphTraverser { |
| 93 | |
| 94 | private Node current; |
| 95 | |
| 96 | BindingGraphVisitor( |
| 97 | ComponentTreePath componentTreePath, ComponentMethodDescriptor entryPointMethod) { |
| 98 | super(componentTreePath, entryPointMethod); |
| 99 | current = currentComponent; |
| 100 | network.addNode(current); |
| 101 | } |
| 102 | |
| 103 | @Override |
nothing calls this directly
no test coverage detected