use of com.google.gwt.inject.rebind.binding.Context in project google-gin by gwtplus.
the class BindingInstaller method ensureAccessible.
/**
* Ensure that the binding for key which exists in the parent Ginjector is also available to the
* child Ginjector.
*/
private void ensureAccessible(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
// Parent will be null if it is was an optional dependency and it couldn't be created.
if (parent != null && !child.equals(parent) && !child.isBound(key)) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "In %s: inheriting binding for %s from the parent %s", child, key, parent);
Context context = Context.format("Inheriting %s from parent", key);
// We don't strictly need all the extra checks in addBinding, but it can't hurt. We know, for
// example, that there will not be any unresolved bindings for this key.
child.addBinding(key, bindingFactory.getParentBinding(key, parent, context));
}
}
use of com.google.gwt.inject.rebind.binding.Context in project google-gin by gwtplus.
the class GuiceBindingVisitor method visit.
public Void visit(InstanceBinding<? extends T> instanceBinding) {
T instance = instanceBinding.getInstance();
if (BindConstantBinding.isConstantKey(targetKey)) {
Context context = Context.forElement(instanceBinding);
bindingsCollection.addBinding(targetKey, bindingFactory.getBindConstantBinding(targetKey, instance, context));
} else {
messages.add(new Message(instanceBinding.getSource(), PrettyPrinter.format("Instance binding not supported; key=%s, inst=%s", targetKey, instance)));
}
return null;
}
use of com.google.gwt.inject.rebind.binding.Context in project google-gin by gwtplus.
the class GinjectorFragmentOutputter method writeBindingGetter.
/**
* Writes a method describing the getter for the given key, along with any
* other code necessary to support it. Produces a list of helper methods that
* still need to be written.
*/
void writeBindingGetter(Key<?> key, Binding binding, GinScope scope, List<InjectorMethod> helperMethodsOutput) {
Context bindingContext = binding.getContext();
SourceSnippetBuilder getterBuilder = new SourceSnippetBuilder();
SourceSnippet creationStatements;
String getter = nameGenerator.getGetterMethodName(key);
String typeName;
try {
typeName = ReflectUtil.getSourceName(key.getTypeLiteral());
creationStatements = binding.getCreationStatements(nameGenerator, helperMethodsOutput);
} catch (NoSourceNameException e) {
errorManager.logError("Error trying to write getter for [%s] -> [%s];" + " binding declaration: %s", e, key, binding, bindingContext);
return;
}
// Name of the field that we might need.
String field = nameGenerator.getSingletonFieldName(key);
switch(scope) {
case EAGER_SINGLETON:
initializeEagerSingletonsBody.append("// Eager singleton bound at:\n");
appendBindingContextCommentToMethod(bindingContext, initializeEagerSingletonsBody);
initializeEagerSingletonsBody.append(getter).append("();\n");
// $FALL-THROUGH$
case SINGLETON:
writer.println("private " + typeName + " " + field + " = null;");
writer.println();
getterBuilder.append(String.format("\nif (%s == null) {\n", field)).append(creationStatements).append("\n").append(String.format(" %s = result;\n", field)).append("}\n").append(String.format("return %s;\n", field));
break;
case NO_SCOPE:
sourceWriteUtil.writeBindingContextJavadoc(writer, bindingContext, key);
getterBuilder.append(creationStatements).append("\n").append("return result;\n");
break;
default:
throw new IllegalStateException();
}
outputMethod(SourceSnippets.asMethod(false, String.format("public %s %s()", typeName, getter), fragmentPackageName.toString(), getterBuilder.build()));
}
use of com.google.gwt.inject.rebind.binding.Context in project google-gin by gwtplus.
the class GuiceBindingVisitor method visit.
public Void visit(LinkedKeyBinding<? extends T> linkedKeyBinding) {
Context context = Context.forElement(linkedKeyBinding);
bindingsCollection.addBinding(targetKey, bindingFactory.getBindClassBinding(linkedKeyBinding.getLinkedKey(), targetKey, context));
return null;
}
use of com.google.gwt.inject.rebind.binding.Context in project google-gin by gwtplus.
the class GuiceBindingVisitor method visit.
public Void visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) {
// Detect provider methods and handle them
// TODO(bstoler): Update this when the SPI explicitly has a case for
// provider methods
Provider<? extends T> provider = providerInstanceBinding.getProviderInstance();
if (provider instanceof ProviderMethod) {
Context context = Context.forElement(providerInstanceBinding);
bindingsCollection.addBinding(targetKey, bindingFactory.getProviderMethodBinding((ProviderMethod<?>) provider, context));
return null;
}
if (provider instanceof GwtDotCreateProvider) {
addImplicitBinding(providerInstanceBinding);
return null;
}
// OTt, use the normal default handler (and error)
return super.visit(providerInstanceBinding);
}
Aggregations