use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class RequiredKeySetTest method testWithMultipleDeps.
public void testWithMultipleDeps() throws Exception {
EasyMock.expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
control.replay();
DependencyGraph graph = new DependencyGraph.Builder(origin).addEdge(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)).addEdge(new Dependency(foo(), bar(), SOURCE)).addEdge(new Dependency(foo(), baz(), SOURCE)).build();
RequiredKeySet requiredKeys = new RequiredKeySet(graph);
assertTrue(requiredKeys.isRequired(foo()));
assertTrue(requiredKeys.isRequired(bar()));
assertTrue(requiredKeys.isRequired(baz()));
control.verify();
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class RequiredKeySetTest method testRequiredSkipsOptional.
public void testRequiredSkipsOptional() throws Exception {
EasyMock.expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
control.replay();
DependencyGraph graph = new DependencyGraph.Builder(origin).addEdge(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)).addEdge(new Dependency(foo(), bar(), true, false, SOURCE)).addEdge(new Dependency(foo(), baz(), SOURCE)).build();
RequiredKeySet requiredKeys = new RequiredKeySet(graph);
assertTrue(requiredKeys.isRequired(foo()));
assertFalse(requiredKeys.isRequired(bar()));
assertTrue(requiredKeys.isRequired(baz()));
control.verify();
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class TestUtils method originDependencies.
static Map<Key<?>, Set<Dependency>> originDependencies(Dependency... dependencies) {
Map<Key<?>, Set<Dependency>> rootDependencies = new HashMap<Key<?>, Set<Dependency>>();
for (Dependency dependency : dependencies) {
Set<Dependency> dependencySet = rootDependencies.get(dependency.getTarget());
if (dependencySet == null) {
dependencySet = new LinkedHashSet<Dependency>();
rootDependencies.put(dependency.getTarget(), dependencySet);
}
dependencySet.add(dependency);
}
return rootDependencies;
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class DependencyExplorer method explore.
/**
* Explore the unresolved dependencies in the origin Ginjector, and create the corresponding
* dependency graph. Also gathers information about key in the dependency graph, such as which
* Ginjector it is already available on, or what implicit binding was created for it.
*
* @param origin the ginjector to build a dependency graph for
*/
public DependencyExplorerOutput explore(GinjectorBindings origin) {
DependencyExplorerOutput output = new DependencyExplorerOutput();
DependencyGraph.Builder builder = new DependencyGraph.Builder(origin);
for (Dependency edge : origin.getDependencies()) {
Preconditions.checkState(Dependency.GINJECTOR.equals(edge.getSource()) || origin.isBound(edge.getSource()), "Expected non-null source %s to be bound in origin!", edge.getSource());
builder.addEdge(edge);
if (!edge.getSource().equals(Dependency.GINJECTOR) && visited.add(edge.getSource())) {
// Need to register where we can find the "source". Note that this will be always be
// available somewhere, because it's already available at the origin (that's how we found
// this dependency).
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Registering %s as available at %s because of the dependency %s", edge.getSource(), origin, edge);
output.preExistingBindings.put(edge.getSource(), locateHighestAccessibleSource(edge.getSource(), origin));
}
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Exploring from %s in %s because of the dependency %s", edge.getTarget(), origin, edge);
// Visit the target of the dependency to find additional bindings
visit(edge.getTarget(), builder, output, origin);
}
output.setGraph(builder.build());
return output;
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class PathFinder method getPathFor.
private List<Dependency> getPathFor(Key<?> rootKey) {
List<Dependency> result = new ArrayList<Dependency>();
// Now, add the edges from the BFS path
Dependency edge = visited.get(rootKey);
while (edge != null) {
result.add(edge);
edge = visited.get(edge.getTarget());
}
return result;
}
Aggregations