Search in sources :

Example 16 with Binding

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());
        }
    }
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 17 with Binding

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();
}
Also used : Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) Context(com.google.gwt.inject.rebind.binding.Context) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) HashMap(java.util.HashMap) Dependency(com.google.gwt.inject.rebind.binding.Dependency) Key(com.google.inject.Key)

Example 18 with Binding

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()));
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding)

Example 19 with Binding

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()));
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding)

Example 20 with Binding

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()));
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Aggregations

Binding (com.google.gwt.inject.rebind.binding.Binding)34 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)28 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)25 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)10 Key (com.google.inject.Key)6 Dependency (com.google.gwt.inject.rebind.binding.Dependency)5 GinjectorNameGenerator (com.google.gwt.inject.rebind.GinjectorNameGenerator)4 NameGenerator (com.google.gwt.inject.rebind.util.NameGenerator)4 BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Context (com.google.gwt.inject.rebind.binding.Context)2 HashMap (java.util.HashMap)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 GinScope (com.google.gwt.inject.rebind.GinScope)1 GinjectorBinding (com.google.gwt.inject.rebind.binding.GinjectorBinding)1 RemoteServiceProxyBinding (com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding)1 InjectorMethod (com.google.gwt.inject.rebind.util.InjectorMethod)1 SourceWriteUtil (com.google.gwt.inject.rebind.util.SourceWriteUtil)1 Singleton (com.google.inject.Singleton)1