Search in sources :

Example 11 with GinjectorBindings

use of com.google.gwt.inject.rebind.GinjectorBindings 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 12 with GinjectorBindings

use of com.google.gwt.inject.rebind.GinjectorBindings 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 13 with GinjectorBindings

use of com.google.gwt.inject.rebind.GinjectorBindings in project gwt-test-utils by gwt-test-utils.

the class GInjectorCreateHandler method readGuiceModules.

private Set<Module> readGuiceModules(Class<? extends GinModule>[] classLiterals, Class<? extends Ginjector> ginectorClass) throws Exception {
    Set<Module> modules = new HashSet<>();
    for (Class<? extends GinModule> literal : classLiterals) {
        LOGGER.debug("wrapping GinModule literal " + literal);
        MemberCollector memberCollector = new MemberCollector(GwtTreeLogger.get());
        GuiceUtil guiceUtil = new GuiceUtil(memberCollector);
        modules.add(new GinModuleAdapter(literal.newInstance(), new GinjectorBindings(null, GwtTreeLogger.get(), guiceUtil, ginectorClass, null, memberCollector, null, null)));
    }
    return modules;
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) GuiceUtil(com.google.gwt.inject.rebind.util.GuiceUtil) GinModuleAdapter(com.google.gwt.inject.rebind.adapter.GinModuleAdapter) Module(com.google.inject.Module) GinModule(com.google.gwt.inject.client.GinModule) MemberCollector(com.google.gwt.inject.rebind.util.MemberCollector) HashSet(java.util.HashSet)

Example 14 with GinjectorBindings

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

the class BindingResolverTest method testDepHiddenInChildBlocksResolvingInRoot.

public void testDepHiddenInChildBlocksResolvingInRoot() throws Exception {
    GinjectorBindings root = createInjectorNode("root");
    GinjectorBindings child = createInjectorNode("child_module");
    setChildren(root, child);
    bind(baz(), root);
    bind(bar(), child);
    expect(root.isBoundLocallyInChild(bar())).andReturn(true).anyTimes();
    expect(root.getChildWhichBindsLocally(bar())).andReturn(child);
    expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
    expectCreateBinding(bar());
    Capture<String> errorMessage = new Capture<String>();
    errorManager.logError(isA(String.class), isA(Object.class), capture(errorMessage), // failure to create bar b/c already bound
    isA(Object.class));
    replayAndResolve(root, required(Dependency.GINJECTOR, foo()));
    assertTrue(errorMessage.getValue().contains("child_module"));
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) Capture(org.easymock.Capture)

Example 15 with GinjectorBindings

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

the class BindingResolverTest method testManyChildren.

public void testManyChildren() throws Exception {
    GinjectorBindings root = createInjectorNode("root");
    GinjectorBindings child1 = createInjectorNode("child1");
    GinjectorBindings child2 = createInjectorNode("child2");
    GinjectorBindings child3 = createInjectorNode("child3");
    setChildren(root, child1, child2, child3);
    bind(bar(), child1);
    bindChild(bar(), root, child1);
    bind(baz(), child2);
    bindChild(baz(), root, child2);
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
    root.addBinding(foo(), fooBinding);
    expectParentBinding(foo(), root, child3);
    replayAndResolve(child3, 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) 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