use of com.google.gwt.inject.rebind.GinjectorBindings 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.GinjectorBindings 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.GinjectorBindings in project gwt-test-utils by gwt-test-utils.
the class GInjectorCreateHandler method readGuiceModules.
private Set<Module> readGuiceModules(Class<? extends GinModule>[] classLiterals, Class<? extends Ginjector> ginectorClass) throws Exception {
Set<Module> modules = new HashSet<>();
for (Class<? extends GinModule> literal : classLiterals) {
LOGGER.debug("wrapping GinModule literal " + literal);
MemberCollector memberCollector = new MemberCollector(GwtTreeLogger.get());
GuiceUtil guiceUtil = new GuiceUtil(memberCollector);
modules.add(new GinModuleAdapter(literal.newInstance(), new GinjectorBindings(null, GwtTreeLogger.get(), guiceUtil, ginectorClass, null, memberCollector, null, null)));
}
return modules;
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingResolverTest method testDepHiddenInChildBlocksResolvingInRoot.
public void testDepHiddenInChildBlocksResolvingInRoot() throws Exception {
GinjectorBindings root = createInjectorNode("root");
GinjectorBindings child = createInjectorNode("child_module");
setChildren(root, child);
bind(baz(), root);
bind(bar(), child);
expect(root.isBoundLocallyInChild(bar())).andReturn(true).anyTimes();
expect(root.getChildWhichBindsLocally(bar())).andReturn(child);
expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
expectCreateBinding(bar());
Capture<String> errorMessage = new Capture<String>();
errorManager.logError(isA(String.class), isA(Object.class), capture(errorMessage), // failure to create bar b/c already bound
isA(Object.class));
replayAndResolve(root, required(Dependency.GINJECTOR, foo()));
assertTrue(errorMessage.getValue().contains("child_module"));
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingResolverTest method testManyChildren.
public void testManyChildren() throws Exception {
GinjectorBindings root = createInjectorNode("root");
GinjectorBindings child1 = createInjectorNode("child1");
GinjectorBindings child2 = createInjectorNode("child2");
GinjectorBindings child3 = createInjectorNode("child3");
setChildren(root, child1, child2, child3);
bind(bar(), child1);
bindChild(bar(), root, child1);
bind(baz(), child2);
bindChild(baz(), root, child2);
Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
root.addBinding(foo(), fooBinding);
expectParentBinding(foo(), root, child3);
replayAndResolve(child3, required(Dependency.GINJECTOR, foo()));
}
Aggregations