Search in sources :

Example 1 with ExposedChildBinding

use of com.google.gwt.inject.rebind.binding.ExposedChildBinding 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());
        }
    }
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 2 with ExposedChildBinding

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

the class GuiceElementVisitor method visit.

public Void visit(PrivateElements privateElements) {
    GinjectorBindings childCollection = children.next();
    // Add information about the elements in the child ginjector to the child bindings
    // TODO(bchambers): Use the tree loggers more intelligently -- when visiting
    // a child bindings collection, we should create a new branch.  This is slightly
    // complicated because we process  in two stages -- once here where we
    // add explicit bindings (and record implicit dependencies), and again later
    // to resolve the implicit dependencies.
    GuiceElementVisitor childVisitor = guiceElementVisitorFactory.create(childCollection);
    childVisitor.visitElements(privateElements.getElements());
    messages.addAll(childVisitor.getMessages());
    // Add information about the exposed elements in child to the current binding collection
    for (Key<?> key : privateElements.getExposedKeys()) {
        ExposedChildBinding childBinding = bindingFactory.getExposedChildBinding(key, childCollection, Context.forElement(privateElements));
        // described.
        if (!(childCollection.isBound(key) || childCollection.isPinned(key))) {
            errorManager.logError("Key %s was exposed from but not bound in %s.  Did you forget to call bind()?", key, childCollection);
        }
        PrettyPrinter.log(logger, TreeLogger.TRACE, "Child binding for %s in %s: %s", key, bindings, childBinding);
        bindings.addBinding(key, childBinding);
    }
    return null;
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding)

Example 3 with ExposedChildBinding

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

the class BindingResolverTest method bindChild.

private void bindChild(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
    ExposedChildBinding binding = control.createMock(ExposedChildBinding.class);
    expect(binding.getContext()).andReturn(Context.forText("")).anyTimes();
    expect(parent.isBound(key)).andReturn(true).anyTimes();
    expect(parent.getBinding(key)).andReturn(binding).anyTimes();
    expect(child.isPinned(key)).andReturn(true).anyTimes();
    expect(binding.getChildBindings()).andReturn(child).anyTimes();
    bindings.add(binding);
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding)

Example 4 with ExposedChildBinding

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

the class DoubleBindingChecker method linkedGinjector.

private GinjectorBindings linkedGinjector(Binding binding) {
    GinjectorBindings nextGinjector = null;
    if (binding instanceof ExposedChildBinding) {
        ExposedChildBinding childBinding = (ExposedChildBinding) binding;
        nextGinjector = childBinding.getChildBindings();
    } else if (binding instanceof ParentBinding) {
        ParentBinding parentBinding = (ParentBinding) binding;
        nextGinjector = parentBinding.getParentBindings();
    }
    return nextGinjector;
}
Also used : ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding)

Example 5 with ExposedChildBinding

use of com.google.gwt.inject.rebind.binding.ExposedChildBinding 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;
}
Also used : RemoteServiceProxyBinding(com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) Singleton(com.google.inject.Singleton) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding)

Aggregations

ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)5 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)3 Binding (com.google.gwt.inject.rebind.binding.Binding)2 Dependency (com.google.gwt.inject.rebind.binding.Dependency)1 RemoteServiceProxyBinding (com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding)1 Singleton (com.google.inject.Singleton)1