Search in sources :

Example 1 with ParentBinding

use of com.google.gwt.inject.rebind.binding.ParentBinding in project google-gin by gwtplus.

the class BindingInstallerTest method testInstallImplicitBindings.

public void testInstallImplicitBindings() throws Exception {
    // Tests that implicit bindings that are not already available in the origin are made accessible
    // foo and bar both had implicit bindings created (with no dependencies).  Foo is installed in
    // the child, and bar is installed in root.  We should add a binding to make bar accessible in
    // the child.
    expect(positions.getInstallPosition(foo())).andStubReturn(child);
    expect(positions.getInstallPosition(bar())).andStubReturn(root);
    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 Foo
    Binding fooBinding = control.createMock("fooBinding", Binding.class);
    expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList());
    implicitBindingMap.put(foo(), fooBinding);
    expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
    expect(child.getDependencies()).andReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE), new Dependency(Dependency.GINJECTOR, bar(), SOURCE)));
    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 2 with ParentBinding

use of com.google.gwt.inject.rebind.binding.ParentBinding in project google-gin by gwtplus.

the class BindingResolverTest method bindParent.

private void bindParent(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
    ParentBinding binding = control.createMock(ParentBinding.class);
    expect(binding.getContext()).andReturn(Context.forText("")).anyTimes();
    expect(binding.getParentBindings()).andReturn(parent).anyTimes();
    expect(child.isBound(key)).andReturn(true).anyTimes();
    expect(child.getBinding(key)).andReturn(binding).anyTimes();
    bindings.add(binding);
}
Also used : ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding)

Example 3 with ParentBinding

use of com.google.gwt.inject.rebind.binding.ParentBinding 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 4 with ParentBinding

use of com.google.gwt.inject.rebind.binding.ParentBinding 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 5 with ParentBinding

use of com.google.gwt.inject.rebind.binding.ParentBinding in project google-gin by gwtplus.

the class DoubleBindingChecker method linkedGinjector.

private GinjectorBindings linkedGinjector(Binding binding) {
    GinjectorBindings nextGinjector = null;
    if (binding instanceof ExposedChildBinding) {
        ExposedChildBinding childBinding = (ExposedChildBinding) binding;
        nextGinjector = childBinding.getChildBindings();
    } else if (binding instanceof ParentBinding) {
        ParentBinding parentBinding = (ParentBinding) binding;
        nextGinjector = parentBinding.getParentBindings();
    }
    return nextGinjector;
}
Also used : ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding)

Aggregations

ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)6 Binding (com.google.gwt.inject.rebind.binding.Binding)4 Dependency (com.google.gwt.inject.rebind.binding.Dependency)3 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)3 Context (com.google.gwt.inject.rebind.binding.Context)2 Key (com.google.inject.Key)2 HashMap (java.util.HashMap)2 RemoteServiceProxyBinding (com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding)1 Singleton (com.google.inject.Singleton)1