use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class EagerCycleFinder method reportCycle.
private void reportCycle(Dependency cycleEdge) {
cycleDetected = true;
// Get the edges in the cycle
List<Dependency> cycle = describeCycle(cycleEdge);
// Using the edges, determine the keys in the cycle
PathFinder pathFinder = new PathFinder().onGraph(graph).addRoots(Dependency.GINJECTOR);
for (Dependency edge : cycle) {
pathFinder.addDestinations(edge.getTarget());
}
List<Dependency> path = pathFinder.findShortestPath();
if (path != null && !path.isEmpty()) {
cycle = rootCycleAt(cycle, path.get(path.size() - 1).getTarget());
}
reportError(path, cycle);
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class GuiceUtil method getMemberInjectionDependencies.
/**
* Collects and returns all keys required to member-inject the given class.
*
* @param typeKey key causing member injection
* @param type class for which required keys are calculated
* @return keys required to inject given class
*/
public Collection<Dependency> getMemberInjectionDependencies(Key<?> typeKey, TypeLiteral<?> type) {
Set<Dependency> required = new LinkedHashSet<Dependency>();
for (MethodLiteral<?, Method> method : memberCollector.getMethods(type)) {
required.addAll(getDependencies(typeKey, method));
}
for (FieldLiteral<?> field : memberCollector.getFields(type)) {
Key<?> key = getKey(field);
required.add(new Dependency(typeKey, key, isOptional(field), false, "member injection of " + field));
}
return required;
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class PrettyPrinter method formatArgTo.
/**
* Formats a list of dependencies as a dependency path; see the class
* comments.
*/
private static void formatArgTo(List<Dependency> path, StringBuilder builder) {
if (path.isEmpty()) {
return;
}
builder.append("\n");
boolean first = true;
// For sanity-checking.
Key<?> previousTarget = null;
for (Dependency dependency : path) {
Key<?> source = dependency.getSource();
Key<?> target = dependency.getTarget();
// Sanity-check.
if (previousTarget != null && !previousTarget.equals(source)) {
throw new IllegalArgumentException("Dependency list is not a path.");
}
// ...
if (first) {
if (source == Dependency.GINJECTOR) {
formatArgTo(target, builder);
builder.append(String.format(" [%s]%n", dependency.getContext()));
} else {
formatArgTo(source, builder);
builder.append("\n -> ");
formatArgTo(target, builder);
builder.append(String.format(" [%s]%n", dependency.getContext()));
}
first = false;
} else {
builder.append(" -> ");
formatArgTo(target, builder);
builder.append(String.format(" [%s]%n", dependency.getContext()));
}
previousTarget = target;
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class ReachabilityAnalyzer method traceKey.
/**
* Marks the binding of the given key in the given {@link GinjectorBindings}
* as reachable, and traces out its dependencies.
*/
private void traceKey(Key<?> key, GinjectorBindings bindings) {
Binding binding = bindings.getBinding(key);
// Make sure the binding is present: optional bindings might be missing.
if (binding != null) {
if (!reachable.add(binding)) {
// The binding was already marked as reachable.
return;
}
getReachableMemberInjects(bindings).addAll(binding.getMemberInjectRequests());
for (Dependency dependency : binding.getDependencies()) {
if (dependency.getSource().equals(key)) {
Key<?> target = dependency.getTarget();
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [%s]", bindings, key, bindings, dependency.getTarget(), binding);
traceKey(target, bindings);
}
}
// dependency graph.
if (binding instanceof ParentBinding) {
ParentBinding parentBinding = (ParentBinding) binding;
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [inherited]", bindings, key, parentBinding.getParentBindings(), key);
traceKey(key, parentBinding.getParentBindings());
} else if (binding instanceof ExposedChildBinding) {
ExposedChildBinding exposedChildBinding = (ExposedChildBinding) binding;
PrettyPrinter.log(logger, TreeLogger.DEBUG, "%s:%s -> %s:%s [exposed]", bindings, key, exposedChildBinding.getChildBindings(), key);
traceKey(key, exposedChildBinding.getChildBindings());
}
}
}
use of com.google.gwt.inject.rebind.binding.Dependency in project google-gin by gwtplus.
the class GuiceUtil method getDependencies.
/**
* Collects and returns all keys required to inject the given method.
*
* @param typeKey the key that depends on injecting the arguments of method
* @param method method for which required keys are calculated
* @return required keys
*/
public Collection<Dependency> getDependencies(Key<?> typeKey, MethodLiteral<?, ?> method) {
String context;
if (method.isConstructor()) {
context = "@Inject constructor of " + method.getDeclaringType();
} else if (typeKey == Dependency.GINJECTOR) {
context = "Member injector " + method;
} else {
context = "Member injection via " + method;
}
Set<Dependency> required = new LinkedHashSet<Dependency>();
for (Key<?> key : method.getParameterKeys()) {
required.add(new Dependency(typeKey, key, isOptional(method), false, context));
}
return required;
}
Aggregations