|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.inject.grapher.GraphingVisitor<K,N,M,B,D>
K
- The type for node IDs.N
- Type for InterfaceNode
s.M
- Type for ImplementationNode
.sB
- Type for BindingEdge
s.D
- Type for DependencyEdge
s.public class GraphingVisitor<K,N extends InterfaceNode<K>,M extends ImplementationNode<K>,B extends BindingEdge<K>,D extends DependencyEdge<K>>
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 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 DependencyEdge s to the graph for each of the provided
Dependency s. |
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 ConstructorBinding s. |
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 |
---|
@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 |
---|
protected final K getClassNodeId(Binding<?> binding)
Binding
's
Key
.
NodeIdFactory.getClassNodeId(Key)
protected final K getInstanceNodeId(Binding<?> binding)
Binding
's
Key
.
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)
DependencyEdge
s to the graph for each of the provided
Dependency
s. 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
DependencyEdge
s.node
- An ImplementationNode
to add Member
s to.dependencies
- Collection
of Dependency
s from the
Binding
.
Collection
of the DependencyEdge
s 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)
ConstructorBinding
s. 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 DependencyEdge
s that the instance may have,
which come either from InjectionPoint
s (method and field) on the
instance, or on Dependency
s the instance declares through the
HasDependencies
interface.
visit
in interface BindingTargetVisitor<Object,Void>
newInterfaceNode(Binding)
,
newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)
,
newInstanceImplementationNode(Binding, Object)
,
newDependencyEdges(Object, ImplementationNode, java.util.Collection)
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 Binding
s 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)
visit(InstanceBinding)
, but the
BindingEdge
is BindingEdge.Type.PROVIDER
.
visit
in interface BindingTargetVisitor<Object,Void>
newInterfaceNode(Binding)
,
newBindingEdge(Object, Object, com.google.inject.grapher.BindingEdge.Type)
,
newInstanceImplementationNode(Binding, Object)
,
newDependencyEdges(Object, ImplementationNode, java.util.Collection)
public Void visit(ProviderKeyBinding<?> binding)
visit(LinkedKeyBinding)
, but the
BindingEdge
is BindingEdge.Type.PROVIDER
.
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>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |