use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class DependencyExplorerTest method testAlreadyPositioned.
public void testAlreadyPositioned() throws Exception {
expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
expect(origin.isBound(foo())).andReturn(true).anyTimes();
expect(origin.getParent()).andReturn(null);
control.replay();
DependencyExplorerOutput output = dependencyExplorer.explore(origin);
assertSame(origin, output.getPreExistingLocations().get(foo()));
assertEquals(1, output.getPreExistingLocations().size());
assertEmpty(output.getBindingErrors());
assertEmpty(output.getImplicitlyBoundKeys());
assertSame(origin, output.getGraph().getOrigin());
assertEmpty(output.getGraph().getDependenciesOf(foo()));
assertContentsAnyOrder(output.getGraph().getDependenciesTargeting(foo()), new Dependency(Dependency.GINJECTOR, foo(), SOURCE));
control.verify();
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class DependencyExplorerTest method testSourcePositioned_Exposed.
/**
* Tests that when we have a dependency that installs multiple steps (eg, GINJECTOR -> foo -> bar)
* we will use the highest foo available.
*/
public void testSourcePositioned_Exposed() throws Exception {
GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE), new Dependency(foo(), bar(), SOURCE)));
expect(origin.isBound(foo())).andReturn(true).anyTimes();
expect(origin.isBound(bar())).andReturn(false).anyTimes();
expect(origin.isPinned(foo())).andReturn(true).anyTimes();
expect(origin.isPinned(bar())).andReturn(false).anyTimes();
expect(origin.getParent()).andReturn(parent).anyTimes();
expect(parent.getParent()).andReturn(null).times(2);
expect(parent.isBound(foo())).andReturn(true);
expect(parent.isBound(bar())).andReturn(true);
control.replay();
DependencyExplorerOutput output = dependencyExplorer.explore(origin);
assertSame(parent, output.getPreExistingLocations().get(foo()));
assertSame(parent, output.getPreExistingLocations().get(bar()));
control.verify();
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class BindingPositioner method calculateExactPositions.
/**
* Iterates on the position equation, updating each binding in the queue and re-queueing nodes
* that depend on any node we move. This will always terminate, since we only re-queue when we
* make a change, and there are a finite number of entries in the injector hierarchy.
*/
private void calculateExactPositions() {
while (!workqueue.isEmpty()) {
Key<?> key = workqueue.iterator().next();
workqueue.remove(key);
Set<GinjectorBindings> injectors = getSourceGinjectors(key);
injectors.add(positions.get(key));
GinjectorBindings newPosition = lowest(injectors);
GinjectorBindings oldPosition = positions.put(key, newPosition);
if (oldPosition != newPosition) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Moved the highest visible position of %s from %s to %s, the lowest injector of %s.", key, oldPosition, newPosition, injectors);
// actually constrain anything.
for (Dependency dependency : output.getGraph().getDependenciesTargeting(key)) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Re-enqueuing %s due to %s", dependency.getSource(), dependency);
workqueue.add(dependency.getSource());
}
}
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class DependencyExplorer method visit.
private void visit(Key<?> key, DependencyGraph.Builder builder, DependencyExplorerOutput output, GinjectorBindings origin) {
if (visited.add(key)) {
GinjectorBindings accessibleSource = locateHighestAccessibleSource(key, origin);
if (accessibleSource != null) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Using binding of %s in %s.", key, accessibleSource);
output.preExistingBindings.put(key, accessibleSource);
} else {
try {
Binding binding = bindingCreator.create(key);
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Implicitly bound %s in %s using %s.", key, origin, binding);
for (Dependency edge : binding.getDependencies()) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Following %s", edge);
builder.addEdge(edge);
visit(edge.getTarget(), builder, output, origin);
}
// Do this *after* visiting all dependencies so that that the ordering is post-order
output.implicitBindings.put(key, binding);
} catch (BindingCreationException e) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Implicit binding failed for %s: %s", key, e.getMessage());
output.bindingErrors.put(key, e.getMessage());
} catch (RuntimeException e) {
logger.log(Type.ERROR, "Exception while visiting " + key);
throw e;
}
}
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class EagerCycleFinder method describeCycle.
private List<Dependency> describeCycle(Dependency cycleEdge) {
List<Dependency> cycle = new ArrayList<Dependency>();
cycle.add(cycleEdge);
Key<?> curr = cycleEdge.getSource();
while (!curr.equals(cycleEdge.getTarget())) {
Dependency edge = visitedEdge.get(curr);
cycle.add(edge);
curr = edge.getSource();
}
Collections.reverse(cycle);
return cycle;
}
Aggregations