use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class GinjectorFragmentContext method callParentGetter.
public String callParentGetter(Key<?> key, GinjectorBindings parentBindings) {
Binding parentKeyBinding = parentBindings.getBinding(key);
if (parentKeyBinding == null) {
errorManager.logError("No binding found for %s in %s", key, parentBindings);
return "null /* No binding found */";
}
FragmentPackageName parentKeyPackageName = fragmentPackageNameFactory.create(parentKeyBinding.getGetterMethodPackage());
StringBuilder result = new StringBuilder().append("injector");
// Walk up the injector hierarchy until we hit the requested parent.
GinjectorBindings current = bindings;
while (current != null && current != parentBindings) {
result.append(".getParent()");
current = current.getParent();
}
if (current == null) {
// This should never happen; it indicates that the given parent injector
// isn't actually a parent of the current bindings object.
errorManager.logError("Internal Gin error: %s is not a parent of %s.", parentBindings, bindings);
return "null /* Internal error: unreachable parent bindings */";
}
NameGenerator parentNameGenerator = parentBindings.getNameGenerator();
String fragmentGetter = parentNameGenerator.getFragmentGetterMethodName(parentKeyPackageName);
String getter = parentNameGenerator.getGetterMethodName(key);
return result.append(String.format(".%s().%s()", fragmentGetter, getter)).toString();
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class ReachabilityAnalyzer method doTraceEagerSingletons.
private void doTraceEagerSingletons(GinjectorBindings bindings) {
for (Map.Entry<Key<?>, Binding> entry : bindings.getBindings()) {
Key<?> key = entry.getKey();
Binding binding = entry.getValue();
GinScope scope = bindings.determineScope(key);
if (scope == GinScope.EAGER_SINGLETON) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "ROOT -> %s:%s [eager singleton: %s]", bindings, key, binding);
traceKey(key, bindings);
}
}
for (GinjectorBindings child : bindings.getChildren()) {
doTraceEagerSingletons(child);
}
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class BindingInstaller method installBindings.
/**
* Installs all of the implicit bindings as described {@link BindingInstaller above}.
*
* @param output {@link DependencyExplorerOutput} with information about the unresolved bindings
* for the current ginjector.
*/
public void installBindings(DependencyExplorerOutput output) {
positions.position(output);
// Install each implicit binding in the correct position
for (Map.Entry<Key<?>, Binding> entry : output.getImplicitBindings()) {
installBinding(output.getGraph(), entry.getKey(), entry.getValue());
}
// Make sure that each of the dependencies needed directly from the origin are available
GinjectorBindings origin = output.getGraph().getOrigin();
inheritBindingsForDeps(origin, origin.getDependencies());
}
use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.
the class GinjectorBindings method determineScope.
public GinScope determineScope(Key<?> key) {
assertFinalized();
GinScope scope = scopes.get(key);
if (scope == null) {
Class<?> raw = key.getTypeLiteral().getRawType();
Binding binding = bindings.get(key);
if (binding != null && (binding instanceof ExposedChildBinding || binding instanceof ParentBinding)) {
// If this is just a "copy" of a binding higher/lower in the injector
// tree, we prefer to treat the binding like it's unscoped, and refer to
// the "real" binding every time we need the value.
scope = GinScope.NO_SCOPE;
} else if (raw.getAnnotation(Singleton.class) != null || raw.getAnnotation(javax.inject.Singleton.class) != null) {
// Look for scope annotation as a fallback
scope = GinScope.SINGLETON;
} else if (RemoteServiceProxyBinding.isRemoteServiceProxy(key.getTypeLiteral())) {
// Special case for remote services
scope = GinScope.SINGLETON;
} else {
scope = GinScope.NO_SCOPE;
}
}
logger.log(TreeLogger.TRACE, "scope for " + key + ": " + scope);
return scope;
}
Aggregations