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

项目:guice    文件:InheritingState.java   
@Override
public TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
  TypeConverterBinding matchingConverter = null;
  for (State s = this; s != State.NONE; s = s.parent()) {
    for (TypeConverterBinding converter : s.getConvertersThisLevel()) {
      if (converter.getTypeMatcher().matches(type)) {
        if (matchingConverter != null) {
          errors.ambiguousTypeConversion(stringValue, source, type, matchingConverter, converter);
        }
        matchingConverter = converter;
      }
    }
  }
  return matchingConverter;
}
项目:guice    文件:InjectorImpl.java   
ConvertedConstantBindingImpl(
    InjectorImpl injector,
    Key<T> key,
    T value,
    Binding<String> originalBinding,
    TypeConverterBinding typeConverterBinding) {
  super(
      injector,
      key,
      originalBinding.getSource(),
      new ConstantFactory<T>(Initializables.of(value)),
      Scoping.UNSCOPED);
  this.value = value;
  provider = Providers.of(value);
  this.originalBinding = originalBinding;
  this.typeConverterBinding = typeConverterBinding;
}
项目: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    文件:TypeConverterBindingProcessor.java   
@Override
public Boolean visit(TypeConverterBinding command) {
  injector.state.addConverter(
      new TypeConverterBinding(
          command.getSource(), command.getTypeMatcher(), command.getTypeConverter()));
  return true;
}
项目:guice    文件:Errors.java   
public Errors converterReturnedNull(
    String stringValue,
    Object source,
    TypeLiteral<?> type,
    TypeConverterBinding typeConverterBinding) {
  return addMessage(
      "Received null converting '%s' (bound at %s) to %s%n using %s.",
      stringValue, convert(source), type, typeConverterBinding);
}
项目:guice    文件:Errors.java   
public Errors conversionTypeError(
    String stringValue,
    Object source,
    TypeLiteral<?> type,
    TypeConverterBinding typeConverterBinding,
    Object converted) {
  return addMessage(
      "Type mismatch converting '%s' (bound at %s) to %s%n"
          + " using %s.%n"
          + " Converter returned %s.",
      stringValue, convert(source), type, typeConverterBinding, converted);
}
项目:guice    文件:Errors.java   
public Errors conversionError(
    String stringValue,
    Object source,
    TypeLiteral<?> type,
    TypeConverterBinding typeConverterBinding,
    RuntimeException cause) {
  return errorInUserCode(
      cause,
      "Error converting '%s' (bound at %s) to %s%n using %s.%n Reason: %s",
      stringValue,
      convert(source),
      type,
      typeConverterBinding,
      cause);
}
项目:guice    文件:Errors.java   
public Errors ambiguousTypeConversion(
    String stringValue,
    Object source,
    TypeLiteral<?> type,
    TypeConverterBinding a,
    TypeConverterBinding b) {
  return addMessage(
      "Multiple converters can convert '%s' (bound at %s) to %s:%n"
          + " %s and%n"
          + " %s.%n"
          + " Please adjust your type converter configuration to avoid overlapping matches.",
      stringValue, convert(source), type, a, b);
}
项目:guice-old    文件:InheritingState.java   
public TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
  TypeConverterBinding matchingConverter = null;
  for (State s = this; s != State.NONE; s = s.parent()) {
    for (TypeConverterBinding converter : s.getConvertersThisLevel()) {
      if (converter.getTypeMatcher().matches(type)) {
        if (matchingConverter != null) {
          errors.ambiguousTypeConversion(stringValue, source, type, matchingConverter, converter);
        }
        matchingConverter = converter;
      }
    }
  }
  return matchingConverter;
}
项目:guice-old    文件:InjectorImpl.java   
ConvertedConstantBindingImpl(
    InjectorImpl injector, Key<T> key, T value, Binding<String> originalBinding,
    TypeConverterBinding typeConverterBinding) {
  super(injector, key, originalBinding.getSource(),
      new ConstantFactory<T>(Initializables.of(value)), Scoping.UNSCOPED);
  this.value = value;
  provider = Providers.of(value);
  this.originalBinding = originalBinding;
  this.typeConverterBinding = typeConverterBinding;
}
项目:guice-old    文件:Errors.java   
public Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type,
    TypeConverterBinding typeConverterBinding, Object converted) {
  return addMessage("Type mismatch converting '%s' (bound at %s) to %s%n"
      + " using %s.%n"
      + " Converter returned %s.",
      stringValue, convert(source), type, typeConverterBinding, converted);
}
项目:guice-old    文件:Errors.java   
public Errors conversionError(String stringValue, Object source,
    TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause) {
  return errorInUserCode(cause, "Error converting '%s' (bound at %s) to %s%n"
      + " using %s.%n"
      + " Reason: %s",
      stringValue, convert(source), type, typeConverterBinding, cause);
}
项目:guice-old    文件:Errors.java   
public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type,
    TypeConverterBinding a, TypeConverterBinding b) {
  return addMessage("Multiple converters can convert '%s' (bound at %s) to %s:%n"
      + " %s and%n"
      + " %s.%n"
      + " Please adjust your type converter configuration to avoid overlapping matches.",
      stringValue, convert(source), type, a, b);
}
项目:google-guice    文件:InheritingState.java   
public TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
  TypeConverterBinding matchingConverter = null;
  for (State s = this; s != State.NONE; s = s.parent()) {
    for (TypeConverterBinding converter : s.getConvertersThisLevel()) {
      if (converter.getTypeMatcher().matches(type)) {
        if (matchingConverter != null) {
          errors.ambiguousTypeConversion(stringValue, source, type, matchingConverter, converter);
        }
        matchingConverter = converter;
      }
    }
  }
  return matchingConverter;
}
项目:google-guice    文件:InjectorImpl.java   
ConvertedConstantBindingImpl(
    InjectorImpl injector, Key<T> key, T value, Binding<String> originalBinding,
    TypeConverterBinding typeConverterBinding) {
  super(injector, key, originalBinding.getSource(),
      new ConstantFactory<T>(Initializables.of(value)), Scoping.UNSCOPED);
  this.value = value;
  provider = Providers.of(value);
  this.originalBinding = originalBinding;
  this.typeConverterBinding = typeConverterBinding;
}
项目:google-guice    文件:Errors.java   
public Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type,
    TypeConverterBinding typeConverterBinding, Object converted) {
  return addMessage("Type mismatch converting '%s' (bound at %s) to %s%n"
      + " using %s.%n"
      + " Converter returned %s.",
      stringValue, convert(source), type, typeConverterBinding, converted);
}
项目:google-guice    文件:Errors.java   
public Errors conversionError(String stringValue, Object source,
    TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause) {
  return errorInUserCode(cause, "Error converting '%s' (bound at %s) to %s%n"
      + " using %s.%n"
      + " Reason: %s",
      stringValue, convert(source), type, typeConverterBinding, cause);
}
项目:google-guice    文件:Errors.java   
public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type,
    TypeConverterBinding a, TypeConverterBinding b) {
  return addMessage("Multiple converters can convert '%s' (bound at %s) to %s:%n"
      + " %s and%n"
      + " %s.%n"
      + " Please adjust your type converter configuration to avoid overlapping matches.",
      stringValue, convert(source), type, a, b);
}
项目:beadledom    文件:DelegatingInjector.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings() {
  return injector.getTypeConverterBindings();
}
项目:ProjectAres    文件:ElementInspector.java   
@Override
public V visit(TypeConverterBinding binding) {
    return message(binding,
                   "Binding type converter " + binding.getTypeConverter() +
                   " to classes matching " + binding.getTypeMatcher());
}
项目:play-java-spring-data-jpa    文件:SpringInjector.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings() {
    return null;
}
项目:langforia    文件:InjectorProxy.java   
public final Set<TypeConverterBinding> getTypeConverterBindings() {
    return _injector.getTypeConverterBindings();
}
项目:guice-bootstrap    文件:InjectorProxy.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings()
{
    return injector().getTypeConverterBindings();
}
项目:fabricator    文件:SettableInjector.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings() {
    return injector.getTypeConverterBindings();
}
项目:guice    文件:InternalInjectorCreator.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings() {
  return delegateInjector.getTypeConverterBindings();
}
项目:guice    文件:TypeConverterBindingProcessor.java   
private static void internalConvertToTypes(
    InjectorImpl injector, Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) {
  injector.state.addConverter(
      new TypeConverterBinding(SourceProvider.UNKNOWN_SOURCE, typeMatcher, converter));
}
项目:guice    文件:InheritingState.java   
@Override
public Iterable<TypeConverterBinding> getConvertersThisLevel() {
  return converters;
}
项目:guice    文件:InheritingState.java   
@Override
public void addConverter(TypeConverterBinding typeConverterBinding) {
  converters.add(typeConverterBinding);
}
项目:guice    文件:State.java   
@Override
public void addConverter(TypeConverterBinding typeConverterBinding) {
  throw new UnsupportedOperationException();
}
项目:guice    文件:State.java   
@Override
public TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
  throw new UnsupportedOperationException();
}
项目:guice    文件:State.java   
@Override
public Iterable<TypeConverterBinding> getConvertersThisLevel() {
  return ImmutableSet.of();
}
项目:guice    文件:State.java   
/** Returns the matching converter for {@code type}, or null if none match. */
TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source);
项目:guice    文件:State.java   
/** Returns all converters at this level only. */
Iterable<TypeConverterBinding> getConvertersThisLevel();
项目:guice    文件:InjectorImpl.java   
@Override
public TypeConverterBinding getTypeConverterBinding() {
  return typeConverterBinding;
}
项目:guice    文件:InjectorImpl.java   
@Override
public Set<TypeConverterBinding> getTypeConverterBindings() {
  return ImmutableSet.copyOf(state.getConvertersThisLevel());
}
项目:guice    文件:WeakKeySetTest.java   
@Override
public void addConverter(TypeConverterBinding typeConverterBinding) {
  throw new UnsupportedOperationException();
}
项目:guice    文件:WeakKeySetTest.java   
@Override
public TypeConverterBinding getConverter(
    String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
  throw new UnsupportedOperationException();
}
项目:guice    文件:WeakKeySetTest.java   
@Override
public Iterable<TypeConverterBinding> getConvertersThisLevel() {
  return ImmutableSet.of();
}