Package com.google.gwt.inject.rebind.binding

Examples of com.google.gwt.inject.rebind.binding.Binding


    // interface.
    for (MethodLiteral<?, Method> method :
        constructorInjectCollector.getMethods(ginjectorInterface)) {

      Key<?> methodKey = guiceUtil.getKey(method);
      Binding binding = bindings.getBinding(methodKey);
      if (binding == null) {
        // This should not happen, but fail with a meaningful message if it
        // does.
        logger.log(TreeLogger.Type.ERROR, "Unable to find a binding for the required key "
            + methodKey);
        throw new UnableToCompleteException();
      }

      if (!reachabilityAnalyzer.isReachable(binding)) {
        // Sanity-check reachability: every binding in the Ginjector ought to be
        // reachable.
        PrettyPrinter.log(logger, TreeLogger.Type.ERROR,
            "The key %s is required by the Ginjector, but is not reachable.", methodKey);
        throw new UnableToCompleteException();
      }

      FragmentPackageName fragmentPackageName = fragmentPackageNameFactory.create(
          binding.getGetterMethodPackage());

      String body = String.format("return %s.%s().%s();",
          ginjectorNameGenerator.getFieldName(bindings),
          nameGenerator.getFragmentGetterMethodName(fragmentPackageName),
          nameGenerator.getGetterMethodName(guiceUtil.getKey(method)));
View Full Code Here


  }

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

  /**
   * 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);
View Full Code Here

    outputMemberInjections(bindings, fragments, sourceWriteUtil);
    outputStaticInjections(bindings, fragments, sourceWriteUtil);

    // Output the bindings in the fragments.
    for (Map.Entry<Key<?>, Binding> entry : bindings.getBindings()) {
      Binding binding = entry.getValue();
      if (!reachabilityAnalyzer.isReachable(binding)) {
        continue;
      }

      FragmentPackageName fragmentPackageName =
          fragmentPackageNameFactory.create(binding.getGetterMethodPackage());
      Key<?> key = entry.getKey();

      List<InjectorMethod> helperMethods = new ArrayList();
      fragments.get(fragmentPackageName)
          .writeBindingGetter(key, binding, bindings.determineScope(key), helperMethods);
View Full Code Here

    this.sourceWriteUtil = sourceWriteUtilFactory.create(bindings);
    this.sourceWriter = sourceWriter;
  }

  public String callGetter(Key<?> key) {
    Binding keyBinding = bindings.getBinding(key);
    if (keyBinding == null) {
      errorManager.logError("No binding found for %s in %s", key, bindings);
      return "null /* No binding found */";
    }
    FragmentPackageName keyPackageName =
        fragmentPackageNameFactory.create(keyBinding.getGetterMethodPackage());

    String getterCall = bindings.getNameGenerator().getGetterMethodName(key) + "()";

    if (keyPackageName.equals(fragmentPackageName)) {
      return getterCall;
View Full Code Here

      return String.format("injector.%s().%s", fragmentGetterName, getterCall);
    }
  }

  public String callChildGetter(GinjectorBindings childBindings, Key<?> key) {
    Binding childKeyBinding = childBindings.getBinding(key);
    if (childKeyBinding == null) {
      errorManager.logError("No binding found for %s", key);
      return "null /* No binding found */";
    }
    FragmentPackageName childKeyPackageName =
        fragmentPackageNameFactory.create(childKeyBinding.getGetterMethodPackage());

    NameGenerator nameGenerator = bindings.getNameGenerator();
    NameGenerator childNameGenerator = childBindings.getNameGenerator();

    String childInjectorClassName = ginjectorNameGenerator.getClassName(childBindings);
View Full Code Here

    return String.format("%s(%s);", memberInjectMethodName, input);
  }

  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) {
View Full Code Here

  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
View Full Code Here

    expect(child.isBound(bar())).andReturn(false);
    expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class)))
        .andReturn(barBinding);
   
    // Implicit binding for Foo
    Binding fooBinding = control.createMock("fooBinding", Binding.class);
    expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList());
    implicitBindingMap.put(foo(), fooBinding);
   
    expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
    expect(child.getDependencies()).andReturn(TestUtils.dependencyList(
View Full Code Here

    expect(child.isBound(bar())).andReturn(false);
    expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class)))
        .andReturn(barBinding);

    // Implicit binding for Bar
    Binding bazBinding = control.createMock("bazBinding", Binding.class);
    expect(graph.getDependenciesOf(baz())).andReturn(TestUtils.dependencyList());
    implicitBindingMap.put(baz(), bazBinding);
   
    // Implicit binding for Foo
    Binding fooBinding = control.createMock("fooBinding", Binding.class);
    expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList(
        new Dependency(foo(), bar(), SOURCE),
        new Dependency(foo(), baz(), SOURCE)));
    implicitBindingMap.put(foo(), fooBinding);
   
View Full Code Here

TOP

Related Classes of com.google.gwt.inject.rebind.binding.Binding

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.