Search in sources :

Example 16 with GinjectorBindings

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

the class DependencyExplorerTest method testUsesExposedBinding.

/**
 * Tests that we don't skip an exposed binding from a different injector.
 */
public void testUsesExposedBinding() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    GinjectorBindings otherGinjector = control.createMock("other", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.isPinned(foo())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null);
    expect(parent.isBound(foo())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 17 with GinjectorBindings

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

the class DependencyExplorerTest method testWillBeBoundBoundInParent.

public void testWillBeBoundBoundInParent() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isPinned(foo())).andReturn(false).anyTimes();
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null);
    expect(parent.isBound(foo())).andReturn(false);
    expect(parent.isPinned(foo())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 18 with GinjectorBindings

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

the class DependencyExplorerTest method testSkipsExposedBindingFromOrigin.

/**
 * Tests that we don't try to use an exposed binding from the "origin" to satisfy a dependency
 * from the origin.
 */
public void testSkipsExposedBindingFromOrigin() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.isPinned(foo())).andReturn(true).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(bindingCreator.create(foo())).andReturn(binding);
    expect(binding.getDependencies()).andReturn(TestUtils.dependencyList());
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertTrue(output.getPreExistingLocations().isEmpty());
    assertTrue(output.getImplicitlyBoundKeys().contains(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 19 with GinjectorBindings

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

the class DependencyExplorerTest method testAlreadyBoundInParent.

public void testAlreadyBoundInParent() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isPinned(foo())).andReturn(false).anyTimes();
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null);
    expect(parent.isBound(foo())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 20 with GinjectorBindings

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

the class BindingPositioner method computeInitialPosition.

/**
 * Returns the highest injector that we could possibly position the key at without causing a
 * double binding.
 */
private GinjectorBindings computeInitialPosition(Key<?> key) {
    GinjectorBindings initialPosition = output.getGraph().getOrigin();
    boolean pinned = initialPosition.isPinned(key);
    // to install the binding in the origin.
    if (pinned) {
        PrettyPrinter.log(logger, TreeLogger.DEBUG, PrettyPrinter.format("Forcing %s to be installed in %s due to a pin.", key, initialPosition));
        installOverrides.put(key, initialPosition);
    }
    while (canExposeKeyFrom(key, initialPosition, pinned)) {
        PrettyPrinter.log(logger, TreeLogger.SPAM, "Moving the highest visible position of %s from %s to %s.", key, initialPosition, initialPosition.getParent());
        initialPosition = initialPosition.getParent();
    }
    return initialPosition;
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings)

Aggregations

GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)27 Binding (com.google.gwt.inject.rebind.binding.Binding)10 Dependency (com.google.gwt.inject.rebind.binding.Dependency)8 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)7 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)6 DependencyExplorerOutput (com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput)6 Key (com.google.inject.Key)5 NameGenerator (com.google.gwt.inject.rebind.util.NameGenerator)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Capture (org.easymock.Capture)3 GinjectorNameGenerator (com.google.gwt.inject.rebind.GinjectorNameGenerator)2 InjectorMethod (com.google.gwt.inject.rebind.util.InjectorMethod)2 SourceWriteUtil (com.google.gwt.inject.rebind.util.SourceWriteUtil)2 GeneratorContext (com.google.gwt.core.ext.GeneratorContext)1 GinModule (com.google.gwt.inject.client.GinModule)1 GinScope (com.google.gwt.inject.rebind.GinScope)1 GinModuleAdapter (com.google.gwt.inject.rebind.adapter.GinModuleAdapter)1 GinjectorBinding (com.google.gwt.inject.rebind.binding.GinjectorBinding)1 SubPackageClass (com.google.gwt.inject.rebind.output.subpackage.SubPackageClass)1