use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class PathFinder method findShortestPath.
/**
* Find the shortest path from an unresolved edge in the roots to a key in the destinations.
*
* <p>Implemented as a Breadth-first search from the destination set back to the origin.
*
* @return the shortest path from the roots to any of the destinations specified that passes
* through edges meeting the criteria; can be empty if destination is already in the root
* set, or null if no path exists
*/
public List<Dependency> findShortestPath() {
Preconditions.checkNotNull(graph, "Must call onGraph(DependencyGraph) before findShortestPath");
Preconditions.checkState(!roots.isEmpty(), "Must call addRoots(Key<?>...) before findShortestPath");
Preconditions.checkState(!destinations.isEmpty(), "Must call addDestinations(Key<?>...) before findShortestPath");
visited = new LinkedHashMap<Key<?>, Dependency>();
workQueue = new LinkedList<Key<?>>();
// set, we can return early.
for (Key<?> key : destinations) {
visited.put(key, null);
if (roots.contains(key)) {
return getPathFor(key);
}
workQueue.add(key);
}
// Perform a BFS looking for a path back to a root edge
while (!workQueue.isEmpty()) {
Key<?> key = workQueue.remove();
for (Dependency edge : graph.getDependenciesTargeting(key)) {
if (isEdgeUsable(edge)) {
Key<?> sourceKey = edge.getSource();
if (!visited.containsKey(sourceKey)) {
workQueue.add(sourceKey);
visited.put(sourceKey, edge);
// Check for early termination
if (roots.contains(sourceKey)) {
return getPathFor(sourceKey);
}
}
}
}
}
// and requiredOnly is true.
return null;
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class UnresolvedBindingValidator method getRequiredSourcesTargeting.
/**
* Returns all of the source keys that have a required dependency on any key in the target set.
*/
private Collection<Key<?>> getRequiredSourcesTargeting(DependencyGraph graph, Iterable<Key<?>> targets) {
Collection<Key<?>> requiredSources = new LinkedHashSet<Key<?>>();
for (Key<?> target : targets) {
for (Dependency edge : graph.getDependenciesTargeting(target)) {
if (!edge.isOptional()) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Removing the key %s because of %s", edge.getSource(), edge);
requiredSources.add(edge.getSource());
}
}
}
return requiredSources;
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class ReachabilityAnalyzer method traceGinjectorMethods.
/**
* Traces out bindings that are reachable from a GInjector method.
*/
private void traceGinjectorMethods() {
TypeLiteral<?> ginjectorInterface = rootBindings.getGinjectorInterface();
for (MethodLiteral<?, Method> method : memberCollector.getMethods(ginjectorInterface)) {
if (!guiceUtil.isMemberInject(method)) {
// It's a constructor method, so just trace to the key that's
// constructed.
Key<?> key = guiceUtil.getKey(method);
PrettyPrinter.log(logger, TreeLogger.DEBUG, "ROOT -> %s:%s [%s]", rootBindings, key, method);
traceKey(key, rootBindings);
} else {
Key<?> sourceKey = guiceUtil.getKey(method);
getReachableMemberInjects(rootBindings).add(sourceKey.getTypeLiteral());
for (Dependency dependency : guiceUtil.getMemberInjectionDependencies(sourceKey, sourceKey.getTypeLiteral())) {
Key<?> targetKey = dependency.getTarget();
PrettyPrinter.log(logger, TreeLogger.DEBUG, "ROOT -> %s:%s [%s]", rootBindings, targetKey, method);
traceKey(targetKey, rootBindings);
}
}
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class GinjectorBindings method addUnresolvedEntriesForInjectorInterface.
void addUnresolvedEntriesForInjectorInterface() {
assertNotFinalized();
for (MethodLiteral<?, Method> method : completeCollector.getMethods(ginjectorInterface)) {
nameGenerator.markAsUsed(method.getName());
Key<?> key = guiceUtil.getKey(method);
logger.log(TreeLogger.TRACE, "Add unresolved key from injector interface: " + key);
// need to provide all dependencies.
if (guiceUtil.isMemberInject(method)) {
memberInjectRequests.add(key.getTypeLiteral());
addDependencies(guiceUtil.getMemberInjectionDependencies(Dependency.GINJECTOR, key.getTypeLiteral()));
} else {
addDependency(new Dependency(Dependency.GINJECTOR, key, method.toString()));
}
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class GinjectorBindings method addStaticInjectionRequest.
void addStaticInjectionRequest(Class<?> type, Object source) {
assertNotFinalized();
staticInjectionRequests.add(type);
// Calculate required bindings and add to dependencies
for (InjectionPoint injectionPoint : InjectionPoint.forStaticMethodsAndFields(type)) {
Member member = injectionPoint.getMember();
if (member instanceof Method) {
addDependencies(guiceUtil.getDependencies(Dependency.GINJECTOR, MethodLiteral.get((Method) member, TypeLiteral.get(member.getDeclaringClass()))));
} else if (member instanceof Field) {
FieldLiteral<?> field = FieldLiteral.get((Field) member, TypeLiteral.get(member.getDeclaringClass()));
Key<?> key = guiceUtil.getKey(field);
addDependency(new Dependency(Dependency.GINJECTOR, key, guiceUtil.isOptional(field), false, source.toString()));
}
}
}
Aggregations