Package com.google.inject.spi

Examples of com.google.inject.spi.HasDependencies


            .toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
      }
    });

    Binding<?> binding = injector.getBinding(ColoredCarFactory.class);
    HasDependencies hasDependencies = (HasDependencies) binding;
    assertEquals(ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(double.class))),
        hasDependencies.getDependencies());
  }
View Full Code Here


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

    Binding<Set<String>> binding = injector.getBinding(new Key<Set<String>>() {});
    HasDependencies withDependencies = (HasDependencies) binding;
    Set<String> elements = Sets.newHashSet();
    for (Dependency<?> dependency : withDependencies.getDependencies()) {
      elements.add((String) injector.getInstance(dependency.getKey()));
    }
    assertEquals(ImmutableSet.of("A", "B"), elements);
  }
View Full Code Here

            .toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
      }
    });

    Binding<?> binding = injector.getBinding(ColoredCarFactory.class);
    HasDependencies hasDependencies = (HasDependencies) binding;
    assertEquals(ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(double.class))),
        hasDependencies.getDependencies());
  }
View Full Code Here

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

            @Override
            public <T> Void visit(Binding<T> binding) {
               LOGGER.debug("visiting binding " + binding.toString());

               if (binding instanceof HasDependencies) {
                  HasDependencies deps = (HasDependencies) binding;
                  for (Dependency<?> d : deps.getDependencies()) {
                     collectDependencies(d.getKey(), dependencies);
                  }
               } else {
                  collectDependencies(binding.getKey(), dependencies);
                  dependencies.addAll(getDependencies(binding.getKey()));
View Full Code Here

            if (bindingInfo.boundKey != null) {
                keysNeeded.add(bindingInfo.boundKey);
            }
            if (bindingInfo.boundInstance != null &&
                    bindingInfo.boundInstance instanceof HasDependencies) {
                HasDependencies hasDependencies = (HasDependencies) bindingInfo.boundInstance;
                for (Dependency<?> dependency : hasDependencies.getDependencies()) {
                    keysNeeded.add(dependency.getKey());
                }
            }
        }
View Full Code Here

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

    Binding<Set<String>> binding = injector.getBinding(new Key<Set<String>>() {});
    HasDependencies withDependencies = (HasDependencies) binding;
    Set<String> elements = Sets.newHashSet();
    for (Dependency<?> dependency : withDependencies.getDependencies()) {
      elements.add((String) injector.getInstance(dependency.getKey()));
    }
    assertEquals(ImmutableSet.of("A", "B"), elements);
  }
View Full Code Here

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

    Binding<Set<String>> binding = injector.getBinding(new Key<Set<String>>() {});
    HasDependencies withDependencies = (HasDependencies) binding;
    InstanceBinding<?> instanceBinding = null;
    LinkedKeyBinding<?> linkedBinding = null;
    // The non-tool stage test can test this by calling injector.getInstance to ensure
    // the right values are returned -- in tool stage we can't do that.  It's also a
    // little difficult to validate the dependencies & bindings, because they're
    // bindings created internally within Multibinder.
    // To workaround this, we just validate that the dependencies lookup to a single
    // InstanceBinding whose value is "A" and another LinkedBinding whose target is
    // the Key of @Named("b") String=B
    for (Dependency<?> dependency : withDependencies.getDependencies()) {
      Binding<?> b = injector.getBinding(dependency.getKey());
      if(b instanceof InstanceBinding) {
        if(instanceBinding != null) {
          fail("Already have an instance binding of: " + instanceBinding + ", and now want to add: " + b);
        } else {
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

 
          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());
  }
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.