Package com.google.gwt.inject.rebind

Examples of com.google.gwt.inject.rebind.GinjectorBindings


       
    replayAndResolve(root, required(Dependency.GINJECTOR, foo()));
  }
 
  public void testManyChildren() throws Exception {
    GinjectorBindings root = createInjectorNode("root");
    GinjectorBindings child1 = createInjectorNode("child1");
    GinjectorBindings child2 = createInjectorNode("child2");
    GinjectorBindings child3 = createInjectorNode("child3");
    setChildren(root, child1, child2, child3);
   
    bind(bar(), child1);
    bindChild(bar(), root, child1);
    bind(baz(), child2);
View Full Code Here


    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());
  }
View Full Code Here

   * specified by the {@link BindingPositioner}. Also ensures that the dependencies of the implicit
   * binding are available at the chosen position.
   */
  private void installBinding(DependencyGraph graph, Key<?> key, Binding binding) {
    // Figure out where we're putting the implicit entry
    GinjectorBindings implicitEntryPosition = positions.getInstallPosition(key);
   
    // Ensure that the dependencies are available to the ginjector
    inheritBindingsForDeps(implicitEntryPosition, graph.getDependenciesOf(key));
   
    // Now add the implicit binding to the ginjector
    implicitEntryPosition.addBinding(key, binding);
  }
View Full Code Here

   * removed from the dependency graph earlier.
   */
  public GinjectorBindings getInstallPosition(Key<?> key) {
    Preconditions.checkNotNull(positions,
        "Must call position before calling getInstallPosition(Key<?>)");
    GinjectorBindings position = installOverrides.get(key);
    if (position == null) {
      position = positions.get(key);
    }
    return position;
  }
View Full Code Here

   * possible in the injector tree without causing double binding.
   */
  private void computeInitialPositions() {
    positions.putAll(output.getPreExistingLocations());
    for (Key<?> key : output.getImplicitlyBoundKeys()) {
      GinjectorBindings initialPosition = computeInitialPosition(key);

      PrettyPrinter.log(logger, TreeLogger.DEBUG, PrettyPrinter.format(
          "Initial highest visible position of %s is %s", key, initialPosition));

      positions.put(key, initialPosition);
View Full Code Here

  /**
   * Returns the highest injector that we could possibly position the key at without causing a
   * double binding.
   */
  private GinjectorBindings computeInitialPosition(Key<?> key) {
    GinjectorBindings initialPosition = output.getGraph().getOrigin();
    boolean pinned = initialPosition.isPinned(key);

    // If the key is pinned (explicitly bound) at the origin, we may be in a situation where we need
    // to install a binding at the origin, even though we should *use* the binding form a higher
    // location.
    // If key is already bound in parent, there is a reason that {@link DependencyExplorer}
    // chose not to use that binding.  Specifically, it implies that the key is exposed to the
    // parent from the origin.  While we are fine using the higher binding, it is still necessary
    // to install the binding in the origin.
    if (pinned) {
      PrettyPrinter.log(logger, TreeLogger.DEBUG,
          PrettyPrinter.format("Forcing %s to be installed in %s due to a pin.", key,
              initialPosition));
      installOverrides.put(key, initialPosition);
    }

    while (canExposeKeyFrom(key, initialPosition, pinned)) {
      PrettyPrinter.log(logger, TreeLogger.SPAM,
          "Moving the highest visible position of %s from %s to %s.", key, initialPosition,
          initialPosition.getParent());
      initialPosition = initialPosition.getParent();
    }
    return initialPosition;
  }
View Full Code Here

   *
   * <p>Note that "pinned" states whether the key was pinned in the injector it
   * started in; it might not be pinned in child.
   */
  private boolean canExposeKeyFrom(Key<?> key, GinjectorBindings child, boolean pinned) {
    GinjectorBindings parent = child.getParent();

    if (parent == null) {
      // Can't move above the root.
      return false;
    } else if (parent.isBoundLocallyInChild(key)) {
      // If a sibling module already materialized a binding for this key, we
      // can't float over it.
      return false;
    } else if (pinned) {
      // If a key is pinned, it's visible in the parent iff it has an
      // ExposedChildBinding pointing at the child.
      Binding binding = parent.getBinding(key);
      if (binding == null) {
        return false;
      } else if (!(binding instanceof ExposedChildBinding)) {
        // This should never happen (it would have been caught as a
        // double-binding earlier).
View Full Code Here

      Key<?> key = workqueue.iterator().next();
      workqueue.remove(key);
     
      Set<GinjectorBindings> injectors = getSourceGinjectors(key);
      injectors.add(positions.get(key));
      GinjectorBindings newPosition = lowest(injectors);
     
      GinjectorBindings oldPosition = positions.put(key, newPosition);
      if (oldPosition != newPosition) {
        PrettyPrinter.log(logger, TreeLogger.DEBUG,
            "Moved the highest visible position of %s from %s to %s, the lowest injector of %s.",
            key, oldPosition, newPosition, injectors);
View Full Code Here

 
  /**
   * Returns the member of {@code sources} closest to the origin.
   */
  private GinjectorBindings lowest(Set<GinjectorBindings> sources) {
    GinjectorBindings lowest = output.getGraph().getOrigin();
    while (!sources.contains(lowest)) {
      lowest = lowest.getParent();
    }
    return Preconditions.checkNotNull(lowest, "Should never make it to null");
  }
View Full Code Here

      Set<Module> modules = new HashSet<Module>();
      for (Class<? extends GinModule> literal : classLiterals) {
         LOGGER.debug("wrapping GinModule literal " + literal);
         MemberCollector memberCollector = new MemberCollector(GwtTreeLogger.get());
         GuiceUtil guiceUtil = new GuiceUtil(memberCollector);
         modules.add(new GinModuleAdapter(literal.newInstance(), new GinjectorBindings(null,
                  GwtTreeLogger.get(), guiceUtil, ginectorClass, null, memberCollector, null, null)));
      }

      return modules;
View Full Code Here

TOP

Related Classes of com.google.gwt.inject.rebind.GinjectorBindings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.