Search in sources :

Example 16 with Dependency

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

the class DependencyExplorerTest method testAlreadyPositioned.

public void testAlreadyPositioned() throws Exception {
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(true).anyTimes();
    expect(origin.getParent()).andReturn(null);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(origin, output.getPreExistingLocations().get(foo()));
    assertEquals(1, output.getPreExistingLocations().size());
    assertEmpty(output.getBindingErrors());
    assertEmpty(output.getImplicitlyBoundKeys());
    assertSame(origin, output.getGraph().getOrigin());
    assertEmpty(output.getGraph().getDependenciesOf(foo()));
    assertContentsAnyOrder(output.getGraph().getDependenciesTargeting(foo()), new Dependency(Dependency.GINJECTOR, foo(), SOURCE));
    control.verify();
}
Also used : DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 17 with Dependency

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

the class DependencyExplorerTest method testSourcePositioned_Exposed.

/**
 * Tests that when we have a dependency that installs multiple steps (eg, GINJECTOR -> foo -> bar)
 * we will use the highest foo available.
 */
public void testSourcePositioned_Exposed() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE), new Dependency(foo(), bar(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(true).anyTimes();
    expect(origin.isBound(bar())).andReturn(false).anyTimes();
    expect(origin.isPinned(foo())).andReturn(true).anyTimes();
    expect(origin.isPinned(bar())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null).times(2);
    expect(parent.isBound(foo())).andReturn(true);
    expect(parent.isBound(bar())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    assertSame(parent, output.getPreExistingLocations().get(bar()));
    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 Dependency

use of com.google.gwt.inject.rebind.binding.Dependency 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());
            }
        }
    }
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 19 with Dependency

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

Example 20 with Dependency

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

the class EagerCycleFinder method describeCycle.

private List<Dependency> describeCycle(Dependency cycleEdge) {
    List<Dependency> cycle = new ArrayList<Dependency>();
    cycle.add(cycleEdge);
    Key<?> curr = cycleEdge.getSource();
    while (!curr.equals(cycleEdge.getTarget())) {
        Dependency edge = visitedEdge.get(curr);
        cycle.add(edge);
        curr = edge.getSource();
    }
    Collections.reverse(cycle);
    return cycle;
}
Also used : ArrayList(java.util.ArrayList) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Aggregations

Dependency (com.google.gwt.inject.rebind.binding.Dependency)50 DependencyExplorerOutput (com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput)10 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)8 Key (com.google.inject.Key)6 Binding (com.google.gwt.inject.rebind.binding.Binding)5 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)4 Method (java.lang.reflect.Method)4 LinkedHashSet (java.util.LinkedHashSet)4 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)3 HashMap (java.util.HashMap)3 Context (com.google.gwt.inject.rebind.binding.Context)2 BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)2 ArrayList (java.util.ArrayList)2 FieldLiteral (com.google.gwt.inject.rebind.reflect.FieldLiteral)1 InjectionPoint (com.google.inject.spi.InjectionPoint)1 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1