Search in sources :

Example 41 with Dependency

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

the class RequiredKeySetTest method testWithMultipleDeps.

public void testWithMultipleDeps() throws Exception {
    EasyMock.expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    control.replay();
    DependencyGraph graph = new DependencyGraph.Builder(origin).addEdge(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)).addEdge(new Dependency(foo(), bar(), SOURCE)).addEdge(new Dependency(foo(), baz(), SOURCE)).build();
    RequiredKeySet requiredKeys = new RequiredKeySet(graph);
    assertTrue(requiredKeys.isRequired(foo()));
    assertTrue(requiredKeys.isRequired(bar()));
    assertTrue(requiredKeys.isRequired(baz()));
    control.verify();
}
Also used : Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 42 with Dependency

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

the class RequiredKeySetTest method testRequiredSkipsOptional.

public void testRequiredSkipsOptional() throws Exception {
    EasyMock.expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    control.replay();
    DependencyGraph graph = new DependencyGraph.Builder(origin).addEdge(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)).addEdge(new Dependency(foo(), bar(), true, false, SOURCE)).addEdge(new Dependency(foo(), baz(), SOURCE)).build();
    RequiredKeySet requiredKeys = new RequiredKeySet(graph);
    assertTrue(requiredKeys.isRequired(foo()));
    assertFalse(requiredKeys.isRequired(bar()));
    assertTrue(requiredKeys.isRequired(baz()));
    control.verify();
}
Also used : Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 43 with Dependency

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

the class TestUtils method originDependencies.

static Map<Key<?>, Set<Dependency>> originDependencies(Dependency... dependencies) {
    Map<Key<?>, Set<Dependency>> rootDependencies = new HashMap<Key<?>, Set<Dependency>>();
    for (Dependency dependency : dependencies) {
        Set<Dependency> dependencySet = rootDependencies.get(dependency.getTarget());
        if (dependencySet == null) {
            dependencySet = new LinkedHashSet<Dependency>();
            rootDependencies.put(dependency.getTarget(), dependencySet);
        }
        dependencySet.add(dependency);
    }
    return rootDependencies;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Dependency(com.google.gwt.inject.rebind.binding.Dependency) Key(com.google.inject.Key)

Example 44 with Dependency

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

the class DependencyExplorer method explore.

/**
 * Explore the unresolved dependencies in the origin Ginjector, and create the corresponding
 * dependency graph.  Also gathers information about key in the dependency graph, such as which
 * Ginjector it is already available on, or what implicit binding was created for it.
 *
 * @param origin the ginjector to build a dependency graph for
 */
public DependencyExplorerOutput explore(GinjectorBindings origin) {
    DependencyExplorerOutput output = new DependencyExplorerOutput();
    DependencyGraph.Builder builder = new DependencyGraph.Builder(origin);
    for (Dependency edge : origin.getDependencies()) {
        Preconditions.checkState(Dependency.GINJECTOR.equals(edge.getSource()) || origin.isBound(edge.getSource()), "Expected non-null source %s to be bound in origin!", edge.getSource());
        builder.addEdge(edge);
        if (!edge.getSource().equals(Dependency.GINJECTOR) && visited.add(edge.getSource())) {
            // Need to register where we can find the "source".  Note that this will be always be
            // available somewhere, because it's already available at the origin (that's how we found
            // this dependency).
            PrettyPrinter.log(logger, TreeLogger.DEBUG, "Registering %s as available at %s because of the dependency %s", edge.getSource(), origin, edge);
            output.preExistingBindings.put(edge.getSource(), locateHighestAccessibleSource(edge.getSource(), origin));
        }
        PrettyPrinter.log(logger, TreeLogger.DEBUG, "Exploring from %s in %s because of the dependency %s", edge.getTarget(), origin, edge);
        // Visit the target of the dependency to find additional bindings
        visit(edge.getTarget(), builder, output, origin);
    }
    output.setGraph(builder.build());
    return output;
}
Also used : Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 45 with Dependency

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

the class PathFinder method getPathFor.

private List<Dependency> getPathFor(Key<?> rootKey) {
    List<Dependency> result = new ArrayList<Dependency>();
    // Now, add the edges from the BFS path
    Dependency edge = visited.get(rootKey);
    while (edge != null) {
        result.add(edge);
        edge = visited.get(edge.getTarget());
    }
    return result;
}
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