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

项目:guice    文件:TypeConverterBindingProcessor.java   
private static void convertToClasses(
    InjectorImpl injector, final Matcher<? super Class<?>> typeMatcher, TypeConverter converter) {
  internalConvertToTypes(
      injector,
      new AbstractMatcher<TypeLiteral<?>>() {
        @Override
        public boolean matches(TypeLiteral<?> typeLiteral) {
          Type type = typeLiteral.getType();
          if (!(type instanceof Class)) {
            return false;
          }
          Class<?> clazz = (Class<?>) type;
          return typeMatcher.matches(clazz);
        }

        @Override
        public String toString() {
          return typeMatcher.toString();
        }
      },
      converter);
}
项目:guice-old    文件:TypeConverterBindingProcessor.java   
private static void convertToClasses(InjectorImpl injector,
    final Matcher<? super Class<?>> typeMatcher, TypeConverter converter) {
  internalConvertToTypes(injector, new AbstractMatcher<TypeLiteral<?>>() {
    public boolean matches(TypeLiteral<?> typeLiteral) {
      Type type = typeLiteral.getType();
      if (!(type instanceof Class)) {
        return false;
      }
      Class<?> clazz = (Class<?>) type;
      return typeMatcher.matches(clazz);
    }

    @Override public String toString() {
      return typeMatcher.toString();
    }
  }, converter);
}
项目:guice-old    文件:TypeConversionTest.java   
public void testStringIsConvertedOnlyOnce() {
  final TypeConverter converter = new TypeConverter() {
    boolean converted = false;
    public Object convert(String value, TypeLiteral<?> toType) {
      if (converted) {
        throw new AssertionFailedError("converted multiple times!");
      }
      converted = true;
      return new Date();
    }
  };

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

  Date first = injector.getInstance(Key.get(Date.class, NumericValue.class));
  Date second = injector.getInstance(Key.get(Date.class, NumericValue.class));
  assertSame(first, second);
}
项目:google-guice    文件:TypeConverterBindingProcessor.java   
private void convertToClasses(final Matcher<? super Class<?>> typeMatcher,
    TypeConverter converter) {
  internalConvertToTypes(new AbstractMatcher<TypeLiteral<?>>() {
    public boolean matches(TypeLiteral<?> typeLiteral) {
      Type type = typeLiteral.getType();
      if (!(type instanceof Class)) {
        return false;
      }
      Class<?> clazz = (Class<?>) type;
      return typeMatcher.matches(clazz);
    }

    @Override public String toString() {
      return typeMatcher.toString();
    }
  }, converter);
}
项目:google-guice    文件:TypeConversionTest.java   
public void testStringIsConvertedOnlyOnce() {
  final TypeConverter converter = new TypeConverter() {
    boolean converted = false;
    public Object convert(String value, TypeLiteral<?> toType) {
      if (converted) {
        throw new AssertionFailedError("converted multiple times!");
      }
      converted = true;
      return new Date();
    }
  };

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

  Date first = injector.getInstance(Key.get(Date.class, NumericValue.class));
  Date second = injector.getInstance(Key.get(Date.class, NumericValue.class));
  assertSame(first, second);
}
项目:guice    文件:TypeConversionTest.java   
public void testStringIsConvertedOnlyOnce() {
  final TypeConverter converter =
      new TypeConverter() {
        boolean converted = false;

        @Override
        public Object convert(String value, TypeLiteral<?> toType) {
          if (converted) {
            throw new AssertionFailedError("converted multiple times!");
          }
          converted = true;
          return new Date();
        }
      };

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

  Date first = injector.getInstance(Key.get(Date.class, NumericValue.class));
  Date second = injector.getInstance(Key.get(Date.class, NumericValue.class));
  assertSame(first, second);
}
项目:guice    文件:TypeConversionTest.java   
TypeConverter mockTypeConverter(final Object result) {
  return new TypeConverter() {
    @Override
    public Object convert(String value, TypeLiteral<?> toType) {
      return result;
    }

    @Override
    public String toString() {
      return "CustomConverter";
    }
  };
}
项目:guice    文件:TypeConversionTest.java   
private static TypeConverter failingTypeConverter() {
  return new TypeConverter() {
    @Override
    public Object convert(String value, TypeLiteral<?> toType) {
      throw new UnsupportedOperationException("Cannot convert");
    }

    @Override
    public String toString() {
      return "BrokenConverter";
    }
  };
}
项目:guice-old    文件:TypeConversionTest.java   
TypeConverter mockTypeConverter(final Object result) {
  return new TypeConverter() {
    public Object convert(String value, TypeLiteral<?> toType) {
      return result;
    }

    @Override public String toString() {
      return "CustomConverter";
    }
  };
}
项目:guice-old    文件:TypeConversionTest.java   
private static TypeConverter failingTypeConverter() {
  return new TypeConverter() {
    public Object convert(String value, TypeLiteral<?> toType) {
      throw new UnsupportedOperationException("Cannot convert");
    }
    @Override public String toString() {
      return "BrokenConverter";
    }
  };
}
项目:google-guice    文件:TypeConversionTest.java   
TypeConverter mockTypeConverter(final Object result) {
  return new TypeConverter() {
    public Object convert(String value, TypeLiteral<?> toType) {
      return result;
    }

    @Override public String toString() {
      return "CustomConverter";
    }
  };
}
项目:google-guice    文件:TypeConversionTest.java   
private TypeConverter failingTypeConverter() {
  return new TypeConverter() {
    public Object convert(String value, TypeLiteral<?> toType) {
      throw new UnsupportedOperationException("Cannot convert");
    }
    @Override public String toString() {
      return "BrokenConverter";
    }
  };
}
项目:violet    文件:ForwardingBinder.java   
@Override
default void convertToTypes(final Matcher<? super TypeLiteral<?>> typeMatcher, final TypeConverter converter) {
  this.binder().convertToTypes(typeMatcher, converter);
}
项目:guice    文件:PrivateModule.java   
/**
 * @see Binder#convertToTypes(com.google.inject.matcher.Matcher,
 *     com.google.inject.spi.TypeConverter)
 */
protected final void convertToTypes(
    Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:guice    文件:TypeConverterBindingProcessor.java   
private static <T> void convertToClass(
    InjectorImpl injector, Class<T> type, TypeConverter converter) {
  convertToClasses(injector, Matchers.identicalTo(type), converter);
}
项目: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    文件:AbstractModule.java   
/**
 * @see Binder#convertToTypes
 * @since 2.0
 */
protected void convertToTypes(
    Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:guice-old    文件:PrivateModule.java   
/**
 * @see Binder#convertToTypes(com.google.inject.matcher.Matcher, com.google.inject.spi.TypeConverter)
 */
protected final void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:guice-old    文件:TypeConverterBindingProcessor.java   
private static <T> void convertToClass(InjectorImpl injector, Class<T> type,
    TypeConverter converter) {
  convertToClasses(injector, Matchers.identicalTo(type), converter);
}
项目:guice-old    文件: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-old    文件:AbstractModule.java   
/**
 * @see Binder#convertToTypes
 * @since 2.0
 */
protected void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:google-guice    文件:PrivateModule.java   
/**
 * @see Binder#convertToTypes(com.google.inject.matcher.Matcher, com.google.inject.spi.TypeConverter)
 */
protected final void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:google-guice    文件:TypeConverterBindingProcessor.java   
private <T> void convertToClass(Class<T> type, TypeConverter converter) {
  convertToClasses(Matchers.identicalTo(type), converter);
}
项目:google-guice    文件:TypeConverterBindingProcessor.java   
private void internalConvertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter) {
  injector.state.addConverter(
      new TypeConverterBinding(SourceProvider.UNKNOWN_SOURCE, typeMatcher, converter));
}
项目:google-guice    文件:AbstractModule.java   
/**
 * @see Binder#convertToTypes
 * @since 2.0
 */
protected void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter) {
  binder().convertToTypes(typeMatcher, converter);
}
项目:guice    文件:Binder.java   
/**
 * Binds a type converter. The injector will use the given converter to convert string constants
 * to matching types as needed.
 *
 * @param typeMatcher matches types the converter can handle
 * @param converter converts values
 * @since 2.0
 */
void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter);
项目:guice-old    文件:Binder.java   
/**
 * Binds a type converter. The injector will use the given converter to
 * convert string constants to matching types as needed.
 *
 * @param typeMatcher matches types the converter can handle
 * @param converter converts values
 * @since 2.0
 */
void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter);
项目:google-guice    文件:Binder.java   
/**
 * Binds a type converter. The injector will use the given converter to
 * convert string constants to matching types as needed.
 *
 * @param typeMatcher matches types the converter can handle
 * @param converter converts values
 * @since 2.0
 */
void convertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
    TypeConverter converter);