本文整理汇总了Java中com.google.inject.spi.TypeConverter类的典型用法代码示例。如果您正苦于以下问题:Java TypeConverter类的具体用法?Java TypeConverter怎么用?Java TypeConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeConverter类属于com.google.inject.spi包,在下文中一共展示了TypeConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToClasses
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例2: convertToClasses
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例3: testStringIsConvertedOnlyOnce
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例4: convertToClasses
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例5: testStringIsConvertedOnlyOnce
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例6: testStringIsConvertedOnlyOnce
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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);
}
示例7: mockTypeConverter
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
TypeConverter mockTypeConverter(final Object result) {
return new TypeConverter() {
@Override
public Object convert(String value, TypeLiteral<?> toType) {
return result;
}
@Override
public String toString() {
return "CustomConverter";
}
};
}
示例8: failingTypeConverter
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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";
}
};
}
示例9: mockTypeConverter
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
TypeConverter mockTypeConverter(final Object result) {
return new TypeConverter() {
public Object convert(String value, TypeLiteral<?> toType) {
return result;
}
@Override public String toString() {
return "CustomConverter";
}
};
}
示例10: failingTypeConverter
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
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";
}
};
}
示例11: failingTypeConverter
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
private TypeConverter failingTypeConverter() {
return new TypeConverter() {
public Object convert(String value, TypeLiteral<?> toType) {
throw new UnsupportedOperationException("Cannot convert");
}
@Override public String toString() {
return "BrokenConverter";
}
};
}
示例12: convertToTypes
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
@Override
default void convertToTypes(final Matcher<? super TypeLiteral<?>> typeMatcher, final TypeConverter converter) {
this.binder().convertToTypes(typeMatcher, converter);
}
示例13: convertToTypes
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
/**
* @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);
}
示例14: convertToClass
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
private static <T> void convertToClass(
InjectorImpl injector, Class<T> type, TypeConverter converter) {
convertToClasses(injector, Matchers.identicalTo(type), converter);
}
示例15: internalConvertToTypes
import com.google.inject.spi.TypeConverter; //导入依赖的package包/类
private static void internalConvertToTypes(
InjectorImpl injector, Matcher<? super TypeLiteral<?>> typeMatcher, TypeConverter converter) {
injector.state.addConverter(
new TypeConverterBinding(SourceProvider.UNKNOWN_SOURCE, typeMatcher, converter));
}