K - The type for node IDs.N - Type for InterfaceNodes.M - Type for ImplementationNode.sB - Type for BindingEdges.D - Type for DependencyEdges.public class GraphingVisitor<K,N extends InterfaceNode<K>,M extends ImplementationNode<K>,B extends BindingEdge<K>,D extends DependencyEdge<K>> extends Object implements BindingTargetVisitor<Object,Void>
BindingTargetVisitor that adds nodes and edges to the graph based on
the visited Binding.
This class is parameterized over the four graph element types
(InterfaceNode, ImplementationNode, BindingEdge, and
DependencyEdge) so that you can extend those interfaces and also
extend this class, and the helper methods will all return your new types.
| Constructor and Description |
|---|
GraphingVisitor(NodeIdFactory<K> idFactory,
InterfaceNode.Factory<K,N> interfaceNodeFactory,
ImplementationNode.Factory<K,M> implementationNodeFactory,
BindingEdge.Factory<K,B> bindingEdgeFactory,
DependencyEdge.Factory<K,D> dependencyEdgeFactory,
NodeAliasFactory<K> nodeAliasFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected K |
getClassNodeId(Binding<?> binding)
|
protected K |
getInstanceNodeId(Binding<?> binding)
|
protected B |
newBindingEdge(K nodeId,
K toId,
BindingEdge.Type type)
Creates a new
BindingEdge from the given node to the specified
node. |
protected M |
newClassImplementationNode(Binding<?> binding,
InjectionPoint constructorInjectionPoint,
Collection<InjectionPoint> memberInjectionPoints)
Creates and returns a new
ImplementationNode for the given
Binding, where the Binding is for a class that Guice
will instantiate, rather than a specific instance. |
protected D |
newDependencyEdge(K nodeId,
InjectionPoint injectionPoint,
Dependency<?> dependency)
Creates a new
DependencyEdge from the given node to a
Dependency. |
protected Collection<D> |
newDependencyEdges(K nodeId,
M node,
Collection<Dependency<?>> dependencies)
Adds
DependencyEdges to the graph for each of the provided
Dependencys. |
protected M |
newInstanceImplementationNode(Binding<?> binding,
Object instance)
Creates and returns a new
ImplementationNode for the given
Binding, where the Binding is for an instance, rather than
a class. |
protected N |
newInterfaceNode(Binding<?> binding)
Creates and returns a new
InterfaceNode object for the given
Binding. |
Void |
visit(ConstructorBinding<?> binding)
Visitor for
ConstructorBindings. |
Void |
visit(ConvertedConstantBinding<?> binding)
Visitor for
ConvertedConstantBinding. |
Void |
visit(ExposedBinding<?> binding)
Currently not displayed on the graph.
|
Void |
visit(InstanceBinding<?> binding)
Visitor for
InstanceBinding. |
Void |
visit(LinkedKeyBinding<?> binding)
Visitor for
LinkedKeyBinding. |
Void |
visit(ProviderBinding<?> binding)
Visitor for
ProviderBinding. |
Void |
visit(ProviderInstanceBinding<?> binding)
|
Void |
visit(ProviderKeyBinding<?> binding)
|
Void |
visit(UntargettedBinding<?> binding)
Currently not displayed on the graph.
|
@Inject public GraphingVisitor(NodeIdFactory<K> idFactory, InterfaceNode.Factory<K,N> interfaceNodeFactory, ImplementationNode.Factory<K,M> implementationNodeFactory, BindingEdge.Factory<K,B> bindingEdgeFactory, DependencyEdge.Factory<K,D> dependencyEdgeFactory, NodeAliasFactory<K> nodeAliasFactory)
protected final K getClassNodeId(Binding<?> binding)
NodeIdFactory.getClassNodeId(Key)protected final K getInstanceNodeId(Binding<?> binding)
NodeIdFactory.getInstanceNodeId(Key)protected N newInterfaceNode(Binding<?> binding)
InterfaceNode object for the given
Binding.protected M newClassImplementationNode(Binding<?> binding, InjectionPoint constructorInjectionPoint, Collection<InjectionPoint> memberInjectionPoints)
ImplementationNode for the given
Binding, where the Binding is for a class that Guice
will instantiate, rather than a specific instance.protected M newInstanceImplementationNode(Binding<?> binding, Object instance)
ImplementationNode for the given
Binding, where the Binding is for an instance, rather than
a class.protected B newBindingEdge(K nodeId, K toId, BindingEdge.Type type)
BindingEdge from the given node to the specified
node.nodeId - ID of the InterfaceNode that binds to the other.toId - The node ID of a class or instance that is bound.type - The BindingEdge.Type of this binding.BindingEdge.protected Collection<D> newDependencyEdges(K nodeId, M node, Collection<Dependency<?>> dependencies)
DependencyEdges to the graph for each of the provided
Dependencys. These will be from the given node ID to the
Dependency's Key.
If a Dependency has an associated InjectionPoint, its
member will be added to the given ImplementationNode and the edge
will start at the Member.
nodeId - ID of the node that should be the tail of the
DependencyEdges.node - An ImplementationNode to add Members to.dependencies - Collection of Dependencys from the
Binding.Collection of the DependencyEdges that were
added to the graph.newDependencyEdge(Object, InjectionPoint, Dependency)protected D newDependencyEdge(K nodeId, @Nullable InjectionPoint injectionPoint, Dependency<?> dependency)
DependencyEdge from the given node to a
Dependency.
This method takes more comprehensive parameters than strictly necessary in case they would be useful to overriding implementations.
nodeId - ID of the ImplementationNode where the edges will start.injectionPoint - The InjectionPoint that gave rise to this
Dependency, if one exists. Used to figure out which
Member the edge should point from.dependency - The Dependency to represent with this edge.DependencyEdge.public Void visit(ConstructorBinding<?> binding)
ConstructorBindings. These are for classes that Guice
will instantiate to satisfy injection requests. We create a new
ImplementationNode for the class, then add edges to everything
that it depends on to be instantiated.visit in interface BindingTargetVisitor<Object,Void>newClassImplementationNode(Binding, InjectionPoint, Collection),
newDependencyEdges(Object, ImplementationNode, Collection)public Void visit(ConvertedConstantBinding<?> binding)
ConvertedConstantBinding. The Binding's
Key will be of an annotated primitive type, and the value of
ConvertedConstantBinding.getSourceKey() will be of a
String with the same annotation.
We render this as an InterfaceNode that has a
BindingEdge to the source Key. That will then be rendered
by visit(InstanceBinding) as an InterfaceNode
with a BindingEdge to the String instance.
visit in interface BindingTargetVisitor<Object,Void>newInterfaceNode(Binding),
newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)public Void visit(ExposedBinding<?> binding)
visit in interface BindingTargetVisitor<Object,Void>public Void visit(InstanceBinding<?> binding)
InstanceBinding. We render two nodes in this case: a
InterfaceNode for the binding's Key, and then an
ImplementationNode for the instance Object itself. We run
a binding node between them.
We then render any DependencyEdges that the instance may have,
which come either from InjectionPoints (method and field) on the
instance, or on Dependencys the instance declares through the
HasDependencies interface.
public Void visit(LinkedKeyBinding<?> binding)
LinkedKeyBinding. This is the standard Binding
you get from binding an interface class to an implementation class. We
create an InterfaceNode, then draw a BindingEdge to the
node of the implementing class.visit in interface BindingTargetVisitor<Object,Void>newInterfaceNode(Binding),
newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)public Void visit(ProviderBinding<?> binding)
ProviderBinding. These Bindings arise from an
InjectionPoint for the Provider interface. Since this
isn't tremendously interesting information, we don't render this binding
on the graph, and instead let the DependencyEdge go straight from
the InjectionPoint to the node specified by
ProviderBinding.getProvidedKey().visit in interface BindingTargetVisitor<Object,Void>NodeAliasFactory.newAlias(Object, Object)public Void visit(ProviderInstanceBinding<?> binding)
public Void visit(ProviderKeyBinding<?> binding)
visit in interface BindingTargetVisitor<Object,Void>newInterfaceNode(Binding),
newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)public Void visit(UntargettedBinding<?> binding)
visit in interface BindingTargetVisitor<Object,Void>Copyright © 2006-2012 Google, Inc.. All Rights Reserved.