public class

GraphingVisitor

extends Object
implements BindingTargetVisitor<T, V>
java.lang.Object
   ↳ com.google.inject.grapher.GraphingVisitor<K, N extends com.google.inject.grapher.InterfaceNode<K>, M extends com.google.inject.grapher.ImplementationNode<K>, B extends com.google.inject.grapher.BindingEdge<K>, D extends com.google.inject.grapher.DependencyEdge<K>>

Class Overview

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.

Summary

Public Constructors
GraphingVisitor(NodeIdFactory<K> idFactory, Factory<K, N> interfaceNodeFactory, Factory<K, M> implementationNodeFactory, Factory<K, B> bindingEdgeFactory, Factory<K, D> dependencyEdgeFactory, NodeAliasFactory<K> nodeAliasFactory)
Public Methods
Void visit(ConstructorBinding<?> binding)
Visitor for ConstructorBindings.
Void visit(ConvertedConstantBinding<?> binding)
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.
Protected Methods
final K getClassNodeId(Binding<?> binding)
Helper method to return the standard node ID for the Binding's Key.
final K getInstanceNodeId(Binding<?> binding)
Helper method to return the instance node ID for the Binding's Key.
B newBindingEdge(K nodeId, K toId, BindingEdge.Type type)
Creates a new BindingEdge from the given node to the specified node.
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.
D newDependencyEdge(K nodeId, InjectionPoint injectionPoint, Dependency<?> dependency)
Creates a new DependencyEdge from the given node to a Dependency.
Collection<D> newDependencyEdges(K nodeId, M node, Collection<Dependency<?>> dependencies)
Adds DependencyEdges to the graph for each of the provided Dependencys.
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.
N newInterfaceNode(Binding<?> binding)
Creates and returns a new InterfaceNode object for the given Binding.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.inject.spi.BindingTargetVisitor

Public Constructors

public GraphingVisitor (NodeIdFactory<K> idFactory, Factory<K, N> interfaceNodeFactory, Factory<K, M> implementationNodeFactory, Factory<K, B> bindingEdgeFactory, Factory<K, D> dependencyEdgeFactory, NodeAliasFactory<K> nodeAliasFactory)

Public Methods

public Void visit (ConstructorBinding<?> binding)

Visitor for 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.

public Void visit (ConvertedConstantBinding<?> binding)

Visitor for ConvertedConstantBinding. The Binding's Key will be of an annotated primitive type, and the value of 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.

public Void visit (ExposedBinding<?> binding)

Currently not displayed on the graph.

public Void visit (InstanceBinding<?> binding)

Visitor for 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)

Visitor for 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.

public Void visit (ProviderBinding<?> binding)

Visitor for 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 getProvidedKey().

public Void visit (UntargettedBinding<?> binding)

Currently not displayed on the graph.

Protected Methods

protected final K getClassNodeId (Binding<?> binding)

Helper method to return the standard node ID for the Binding's Key.

protected final K getInstanceNodeId (Binding<?> binding)

Helper method to return the instance node ID for the Binding's Key.

protected B newBindingEdge (K nodeId, K toId, BindingEdge.Type type)

Creates a new BindingEdge from the given node to the specified node.

Parameters
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.
Returns

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.

This method takes more comprehensive parameters than strictly necessary in case they would be useful to overriding implementations.

Parameters
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.
Returns

protected Collection<D> newDependencyEdges (K nodeId, M node, Collection<Dependency<?>> dependencies)

Adds 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.

Parameters
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.
Returns

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.