use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class ReachabilityAnalyzer method traceKey.
/**
* Marks the binding of the given key in the given {@link GinjectorBindings}
* as reachable, and traces out its dependencies.
*/
private void traceKey(Key<?> key, GinjectorBindings bindings) {
Binding binding = bindings.getBinding(key);
// Make sure the binding is present: optional bindings might be missing.
if (binding != null) {
if (!reachable.add(binding)) {
// The binding was already marked as reachable.
return;
}
getReachableMemberInjects(bindings).addAll(binding.getMemberInjectRequests());
for (Dependency dependency : binding.getDependencies()) {
if (dependency.getSource().equals(key)) {
Key<?> target = dependency.getTarget();
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [%s]", bindings, key, bindings, dependency.getTarget(), binding);
traceKey(target, bindings);
}
}
// dependency graph.
if (binding instanceof ParentBinding) {
ParentBinding parentBinding = (ParentBinding) binding;
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [inherited]", bindings, key, parentBinding.getParentBindings(), key);
traceKey(key, parentBinding.getParentBindings());
} else if (binding instanceof ExposedChildBinding) {
ExposedChildBinding exposedChildBinding = (ExposedChildBinding) binding;
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [exposed]", bindings, key, exposedChildBinding.getChildBindings(), key);
traceKey(key, exposedChildBinding.getChildBindings());
}
}
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class BindingInstallerTest method testInheritDependencies.
public void testInheritDependencies() throws Exception {
// Tests that when we install an implicit binding (for foo), we install bindings to "inherit"
// the dependencies (bar and baz) from the appropriate injectors. In this case, bar must be
// inherited from the root, but we don't need to do anything with baz, since it is already
// available.
expect(positions.getInstallPosition(foo())).andStubReturn(child);
expect(positions.getInstallPosition(bar())).andStubReturn(root);
expect(positions.getInstallPosition(baz())).andStubReturn(child);
Map<Key<?>, Binding> implicitBindingMap = new HashMap<Key<?>, Binding>();
// Parent Binding to make bar available to child
ParentBinding barBinding = control.createMock("barBinding", ParentBinding.class);
expect(child.isBound(bar())).andReturn(false);
expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class))).andReturn(barBinding);
// Implicit binding for Bar
Binding bazBinding = control.createMock("bazBinding", Binding.class);
expect(graph.getDependenciesOf(baz())).andReturn(TestUtils.dependencyList());
implicitBindingMap.put(baz(), bazBinding);
// Implicit binding for Foo
Binding fooBinding = control.createMock("fooBinding", Binding.class);
expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList(new Dependency(foo(), bar(), SOURCE), new Dependency(foo(), baz(), SOURCE)));
implicitBindingMap.put(foo(), fooBinding);
expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
expect(child.getDependencies()).andReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
child.addBinding(baz(), bazBinding);
child.addBinding(bar(), barBinding);
child.addBinding(foo(), fooBinding);
control.replay();
installer.installBindings(output);
control.verify();
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class BindingResolverTest method testResolveOneDependencyInChildL.
public void testResolveOneDependencyInChildL() throws Exception {
StandardTree tree = createExampleTree();
bind(bar(), tree.root);
bind(baz(), tree.childL);
Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
// childL gets Bar from root
expectParentBinding(bar(), tree.root, tree.childL);
tree.childL.addBinding(foo(), fooBinding);
// childLL gets foo from childL
expectParentBinding(foo(), tree.childL, tree.childLL);
replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class BindingResolverTest method testResolveDependenciesInRoot.
public void testResolveDependenciesInRoot() throws Exception {
StandardTree tree = createExampleTree();
Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
bind(bar(), tree.root);
bind(baz(), tree.root);
tree.root.addBinding(foo(), fooBinding);
expectParentBinding(foo(), tree.root, tree.childLL);
replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class BindingResolverTest method testResolveBindingWithOptionalDependencyThatFails.
// Tries to create Foo, which has an optional dependency on Bar, which requires Baz.
// Baz can't be created, so it should create Foo, without the Bar.
public void testResolveBindingWithOptionalDependencyThatFails() throws Exception {
StandardTree tree = createExampleTree();
Binding fooBinding = expectCreateBinding(foo(), optional(foo(), bar()));
expectCreateBinding(bar(), required(bar(), baz()));
expect(bindingCreator.create(baz())).andThrow(new BindingCreationException("Unable to create"));
tree.root.addBinding(foo(), fooBinding);
expectParentBinding(foo(), tree.root, tree.childLL);
replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
Aggregations