Package com.google.inject.spi

Examples of com.google.inject.spi.HasDependencies


        bindConstant().annotatedWith(Names.named("b")).to("B");
      }
    });

    Binding<Map<Integer, String>> binding = injector.getBinding(new Key<Map<Integer, String>>() {});
    HasDependencies withDependencies = (HasDependencies) binding;
    Key<?> setKey = new Key<Set<Map.Entry<Integer, Provider<String>>>>() {};
    assertEquals(ImmutableSet.<Dependency<?>>of(Dependency.get(setKey)),
        withDependencies.getDependencies());
    Set<String> elements = Sets.newHashSet();
    elements.addAll(recurseForDependencies(injector, withDependencies));
    assertEquals(ImmutableSet.of("A", "B"), elements);
  }
View Full Code Here


        bindConstant().annotatedWith(Names.named("b")).to("B");
      }
    });

    Binding<String> binding = injector.getBinding(Key.get(String.class));
    HasDependencies withDependencies = (HasDependencies) binding;
    Set<String> elements = Sets.newHashSet();
    elements.addAll(recurseForDependencies(injector, withDependencies));
    assertEquals(ImmutableSet.of("A", "B"), elements);
  }
View Full Code Here

 
  private Set<String> recurseForDependencies(Injector injector, HasDependencies hasDependencies) {
    Set<String> elements = Sets.newHashSet();
    for (Dependency<?> dependency : hasDependencies.getDependencies()) {
      Binding<?> binding = injector.getBinding(dependency.getKey());
      HasDependencies deps = (HasDependencies) binding;
      if (binding instanceof InstanceBinding) {
        elements.add((String) ((InstanceBinding) binding).getInstance());
      } else {
        elements.addAll(recurseForDependencies(injector, deps));
      }
View Full Code Here

   
    /**
     * Traverses through the dependencies of the providers in order to get to the user's binding.
     */
    private Binding<?> getBindingFromMapProvider(Injector injector, Provider<T> mapProvider) {
      HasDependencies deps = (HasDependencies) mapProvider;
      Key<?> depKey = Iterables.getOnlyElement(deps.getDependencies()).getKey();
      // The dep flow is (and will stay this way, until we change the internals) --
      //    Key[type=Provider<java.lang.String>, annotation=@Element(type=MAPBINDER)]
      // -> Key[type=String, annotation=@Element(type=MAPBINDER)]
      // -> Key[type=Provider<String>, annotation=@Element(type=OPTIONALBINDER)]
      // -> Key[type=String, annotation=@Element(type=OPTIONALBINDER)]
      // The last one points to the user's binding.
      for (int i = 0; i < 3; i++) {
        deps = (HasDependencies) injector.getBinding(depKey);
        depKey = Iterables.getOnlyElement(deps.getDependencies()).getKey();
      }
      return injector.getBinding(depKey);
    }
View Full Code Here

TOP

Related Classes of com.google.inject.spi.HasDependencies

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.