Java 类com.google.inject.spi.ConvertedConstantBinding 实例源码

项目:guice    文件:TypeConversionTest.java   
public void testCustomTypeConversion() throws CreationException {
  final Date result = new Date();

  Injector injector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              convertToTypes(
                  Matchers.only(TypeLiteral.get(Date.class)), mockTypeConverter(result));
              bindConstant().annotatedWith(NumericValue.class).to("Today");
              bind(DateHolder.class);
            }
          });

  assertSame(result, injector.getInstance(DateHolder.class).date);

  Binding<Date> binding = injector.getBinding(Key.get(Date.class, NumericValue.class));
  assertTrue(binding instanceof ConvertedConstantBinding<?>);

  TypeConverterBinding converterBinding =
      ((ConvertedConstantBinding<?>) binding).getTypeConverterBinding();
  assertEquals("CustomConverter", converterBinding.getTypeConverter().toString());

  assertTrue(injector.getTypeConverterBindings().contains(converterBinding));
}
项目:guice-old    文件:TypeConversionTest.java   
public void testCustomTypeConversion() throws CreationException {
  final Date result = new Date();

  Injector injector = Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      convertToTypes(Matchers.only(TypeLiteral.get(Date.class)) , mockTypeConverter(result));
      bindConstant().annotatedWith(NumericValue.class).to("Today");
      bind(DateHolder.class);
    }
  });

  assertSame(result, injector.getInstance(DateHolder.class).date);

  Binding<Date> binding = injector.getBinding(Key.get(Date.class, NumericValue.class));
  assertTrue(binding instanceof ConvertedConstantBinding<?>);

  TypeConverterBinding converterBinding = ((ConvertedConstantBinding<?>)binding).getTypeConverterBinding();
  assertEquals("CustomConverter", converterBinding.getTypeConverter().toString());

  assertTrue(injector.getTypeConverterBindings().contains(converterBinding));
}
项目:google-guice    文件:TypeConversionTest.java   
public void testCustomTypeConversion() throws CreationException {
  final Date result = new Date();

  Injector injector = Guice.createInjector(new AbstractModule() {
    protected void configure() {
      convertToTypes(Matchers.only(TypeLiteral.get(Date.class)) , mockTypeConverter(result));
      bindConstant().annotatedWith(NumericValue.class).to("Today");
      bind(DateHolder.class);
    }
  });

  assertSame(result, injector.getInstance(DateHolder.class).date);

  Binding<Date> binding = injector.getBinding(Key.get(Date.class, NumericValue.class));
  assertTrue(binding instanceof ConvertedConstantBinding<?>);

  TypeConverterBinding converterBinding = ((ConvertedConstantBinding<?>)binding).getTypeConverterBinding();
  assertEquals("CustomConverter", converterBinding.getTypeConverter().toString());

  assertTrue(injector.getTypeConverterBindings().contains(converterBinding));
}
项目:guice    文件:DefaultEdgeCreator.java   
/**
 * Visitor for {@link ConvertedConstantBinding}. The {@link Binding}'s {@link Key} will be of an
 * annotated primitive type, and the value of {@link ConvertedConstantBinding#getSourceKey()}
 * will be of a {@link String} with the same annotation.
 */
@Override
public Collection<Edge> visit(ConvertedConstantBinding<?> binding) {
  return ImmutableList.<Edge>of(
      new BindingEdge(
          NodeId.newTypeId(binding.getKey()),
          NodeId.newTypeId(binding.getSourceKey()),
          BindingEdge.Type.CONVERTED_CONSTANT));
}
项目:guice    文件:TransitiveDependencyVisitorTest.java   
public void testVisitConvertedConstant() {
  Binding<?> binding =
      getBinding(Key.get(Integer.class, Names.named("number")), new ConvertedConstantModule());
  Collection<Key<?>> dependencies = visitor.visit((ConvertedConstantBinding<?>) binding);

  assertDependencies(dependencies, Key.get(String.class, Names.named("number")));
}
项目:guice    文件:InjectorImpl.java   
@Override
public String toString() {
  return MoreObjects.toStringHelper(ConvertedConstantBinding.class)
      .add("key", getKey())
      .add("sourceKey", getSourceKey())
      .add("value", value)
      .toString();
}
项目:guice-old    文件:TransitiveDependencyVisitorTest.java   
public void testVisitConvertedConstant() {
  Binding<?> binding = getBinding(Key.get(Integer.class, Names.named("number")),
      new ConvertedConstantModule());
  Collection<Key<?>> dependencies = visitor.visit(
      (ConvertedConstantBinding<?>) binding);

  assertDependencies(dependencies, Key.get(String.class, Names.named("number")));
}
项目:guice-old    文件:InjectorImpl.java   
@Override public String toString() {
  return Objects.toStringHelper(ConvertedConstantBinding.class)
      .add("key", getKey())
      .add("sourceKey", getSourceKey())
      .add("value", value)
      .toString();
}
项目:google-guice    文件:TransitiveDependencyVisitorTest.java   
public void testVisitConvertedConstant() {
  Binding<?> binding = getBinding(Key.get(Integer.class, Names.named("number")),
      new ConvertedConstantModule());
  Collection<Key<?>> dependencies = visitor.visit(
      (ConvertedConstantBinding<?>) binding);

  assertDependencies(dependencies, Key.get(String.class, Names.named("number")));
}
项目:google-guice    文件:InjectorImpl.java   
@Override public String toString() {
  return Objects.toStringHelper(ConvertedConstantBinding.class)
      .add("key", getKey())
      .add("sourceKey", getSourceKey())
      .add("value", value)
      .toString();
}
项目:ProjectAres    文件:BindingTargetTypeResolver.java   
@Override
public Optional<TypeLiteral<?>> visit(ConvertedConstantBinding<?> binding) {
    // Return the provisioned object's type
    return of(TypeLiteral.get(binding.getValue().getClass()));
}
项目:ProjectAres    文件:DependencyCollector.java   
@Override
public Object visit(ConvertedConstantBinding<? extends T> convertedConstantBinding) {
    // TODO: What do I do here??
    return super.visit(convertedConstantBinding);
}
项目:ProjectAres    文件:Scoper.java   
@Override
public Void visit(ConvertedConstantBinding<? extends T> binding) {
    // Cannot be scoped
    binding.applyTo(binder);
    return null;
}
项目:guice    文件:TransitiveDependencyVisitor.java   
@Override
public Collection<Key<?>> visit(ConvertedConstantBinding<?> binding) {
  return visitHasDependencies(binding);
}
项目:guice    文件:Indexer.java   
@Override
public Indexer.IndexedBinding visit(ConvertedConstantBinding<? extends Object> binding) {
  return new Indexer.IndexedBinding(
      binding, BindingType.CONSTANT, scope(binding), binding.getValue());
}
项目:guice-old    文件:TransitiveDependencyVisitor.java   
@Override public Collection<Key<?>> visit(ConvertedConstantBinding<?> binding) {
  return visitHasDependencies(binding);
}
项目:guice-old    文件:DefaultEdgeCreator.java   
/**
 * Visitor for {@link ConvertedConstantBinding}. The {@link Binding}'s {@link Key} will be of an
 * annotated primitive type, and the value of {@link ConvertedConstantBinding#getSourceKey()}
 * will be of a {@link String} with the same annotation.
 */
@Override public Collection<Edge> visit(ConvertedConstantBinding<?> binding) {
  return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
      NodeId.newTypeId(binding.getSourceKey()),
      BindingEdge.Type.CONVERTED_CONSTANT));
}
项目:google-guice    文件:TransitiveDependencyVisitor.java   
@Override public Collection<Key<?>> visit(ConvertedConstantBinding<?> binding) {
  return visitHasDependencies(binding);
}
项目:google-guice    文件:DefaultEdgeCreator.java   
/**
 * Visitor for {@link ConvertedConstantBinding}. The {@link Binding}'s {@link Key} will be of an
 * annotated primitive type, and the value of {@link ConvertedConstantBinding#getSourceKey()}
 * will be of a {@link String} with the same annotation.
 */
@Override public Collection<Edge> visit(ConvertedConstantBinding<?> binding) {
  return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
      NodeId.newTypeId(binding.getSourceKey()),
      BindingEdge.Type.CONVERTED_CONSTANT));
}