com.google.inject.grapher
Class GraphingVisitor<K,N extends InterfaceNode<K>,M extends ImplementationNode<K>,B extends BindingEdge<K>,D extends DependencyEdge<K>>

java.lang.Object
  extended by com.google.inject.grapher.GraphingVisitor<K,N,M,B,D>
Type Parameters:
K - The type for node IDs.
N - Type for InterfaceNodes.
M - Type for ImplementationNode.s
B - Type for BindingEdges.
D - Type for DependencyEdges.
All Implemented Interfaces:
BindingTargetVisitor<Object,Void>

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.

Author:
phopkins@gmail.com (Pete Hopkins)

Constructor Summary
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)
           
 
Method Summary
protected  K getClassNodeId(Binding<?> binding)
          Helper method to return the standard node ID for the Binding's Key.
protected  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.
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)
          Same as visit(InstanceBinding), but the BindingEdge is BindingEdge.Type.PROVIDER.
 Void visit(ProviderKeyBinding<?> binding)
          Same as visit(LinkedKeyBinding), but the BindingEdge is BindingEdge.Type.PROVIDER.
 Void visit(UntargettedBinding<?> binding)
          Currently not displayed on the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphingVisitor

@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)
Method Detail

getClassNodeId

protected final K getClassNodeId(Binding<?> binding)
Helper method to return the standard node ID for the Binding's Key.

See Also:
NodeIdFactory.getClassNodeId(Key)

getInstanceNodeId

protected final K getInstanceNodeId(Binding<?> binding)
Helper method to return the instance node ID for the Binding's Key.

See Also:
NodeIdFactory.getInstanceNodeId(Key)

newInterfaceNode

protected N newInterfaceNode(Binding<?> binding)
Creates and returns a new InterfaceNode object for the given Binding.


newClassImplementationNode

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.


newInstanceImplementationNode

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.


newBindingEdge

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:
The newly-created and added BindingEdge.

newDependencyEdges

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:
A Collection of the DependencyEdges that were added to the graph.
See Also:
newDependencyEdge(Object, InjectionPoint, Dependency)

newDependencyEdge

protected D newDependencyEdge(K nodeId,
                              @Nullable
                              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:
The newly-created and added DependencyEdge.

visit

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.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newClassImplementationNode(Binding, InjectionPoint, Collection), newDependencyEdges(Object, ImplementationNode, Collection)

visit

public Void visit(ConvertedConstantBinding<?> binding)
Visitor for 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.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newInterfaceNode(Binding), newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)

visit

public Void visit(ExposedBinding<?> binding)
Currently not displayed on the graph.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>

visit

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.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newInterfaceNode(Binding), newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type), newInstanceImplementationNode(Binding, Object), newDependencyEdges(Object, ImplementationNode, java.util.Collection)

visit

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.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newInterfaceNode(Binding), newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)

visit

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

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
NodeAliasFactory.newAlias(Object, Object)

visit

public Void visit(ProviderInstanceBinding<?> binding)
Same as visit(InstanceBinding), but the BindingEdge is BindingEdge.Type.PROVIDER.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newInterfaceNode(Binding), newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type), newInstanceImplementationNode(Binding, Object), newDependencyEdges(Object, ImplementationNode, java.util.Collection)

visit

public Void visit(ProviderKeyBinding<?> binding)
Same as visit(LinkedKeyBinding), but the BindingEdge is BindingEdge.Type.PROVIDER.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>
See Also:
newInterfaceNode(Binding), newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)

visit

public Void visit(UntargettedBinding<?> binding)
Currently not displayed on the graph.

Specified by:
visit in interface BindingTargetVisitor<Object,Void>


Copyright © 2006-2011 Google, Inc.. All Rights Reserved.