本文整理了Java中com.google.inject.TypeLiteral.getType()
方法的一些代码示例,展示了TypeLiteral.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeLiteral.getType()
方法的具体详情如下:
包路径:com.google.inject.TypeLiteral
类名称:TypeLiteral
方法名:getType
[英]Gets underlying Type instance.
[中]获取基础类型实例。
代码示例来源:origin: prestodb/presto
public void bindJsonCodec(TypeLiteral<?> type)
{
requireNonNull(type, "type is null");
binder.bind(getJsonCodecKey(type.getType())).toProvider(new JsonCodecProvider(type.getType())).in(Scopes.SINGLETON);
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a map of <K, V> is safely a Map<K, V>
static <K, V> TypeLiteral<Map<K, V>> mapOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, V>>)
TypeLiteral.get(Types.mapOf(keyType.getType(), valueType.getType()));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // wrapping a T in a Set safely returns a Set<T>
static <T> TypeLiteral<Set<T>> setOf(TypeLiteral<T> elementType) {
Type type = Types.setOf(elementType.getType());
return (TypeLiteral<Set<T>>) TypeLiteral.get(type);
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<T>> optionalOf(TypeLiteral<T> type) {
return (TypeLiteral<Optional<T>>)
TypeLiteral.get(Types.newParameterizedType(Optional.class, type.getType()));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider map <K, V> is safely a Map<K, Provider<V>>
static <K, V> TypeLiteral<Map<K, Provider<V>>> mapOfProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Provider<V>>>)
TypeLiteral.get(Types.mapOf(keyType.getType(), Types.providerOf(valueType.getType())));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider entry <K, V> is safely a Map.Entry<K, Provider<V>>
static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfJavaxProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map.Entry<K, Provider<V>>>)
TypeLiteral.get(
newParameterizedTypeWithOwner(
Map.class,
Map.Entry.class,
keyType.getType(),
Types.javaxProviderOf(valueType.getType())));
}
代码示例来源:origin: com.google.inject/guice
/** Gets the type of this type's provider. */
@SuppressWarnings("unchecked")
final TypeLiteral<Provider<T>> providerType() {
// This cast is safe and wouldn't generate a warning if Type had a type
// parameter.
return (TypeLiteral<Provider<T>>) get(Types.providerOf(getType()));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked")
static <K, V> TypeLiteral<Map<K, javax.inject.Provider<V>>> mapOfJavaxProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, javax.inject.Provider<V>>>)
TypeLiteral.get(
Types.mapOf(
keyType.getType(),
newParameterizedType(javax.inject.Provider.class, valueType.getType())));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider entry <K, V> is safely a Map.Entry<K, Provider<V>>
static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map.Entry<K, Provider<V>>>)
TypeLiteral.get(
newParameterizedTypeWithOwner(
Map.class,
Map.Entry.class,
keyType.getType(),
Types.providerOf(valueType.getType())));
}
代码示例来源:origin: com.google.inject/guice
@Override
public boolean matches(TypeLiteral<?> typeLiteral) {
Type type = typeLiteral.getType();
if (!(type instanceof Class)) {
return false;
}
Class<?> clazz = (Class<?>) type;
return typeMatcher.matches(clazz);
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
static <K, V> TypeLiteral<Map<K, Collection<Provider<V>>>> mapOfCollectionOfProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Collection<Provider<V>>>>)
TypeLiteral.get(
Types.mapOf(
keyType.getType(), Types.collectionOf(Types.providerOf(valueType.getType()))));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
static <K, V>
TypeLiteral<Map<K, Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Collection<javax.inject.Provider<V>>>>)
TypeLiteral.get(
Types.mapOf(
keyType.getType(), Types.collectionOf(Types.javaxProviderOf(valueType.getType()))));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>> mapOfSetOfProviderOf(
TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Set<Provider<V>>>>)
TypeLiteral.get(
Types.mapOf(keyType.getType(), Types.setOf(Types.providerOf(valueType.getType()))));
}
代码示例来源:origin: com.google.inject/guice
static <T> TypeLiteral<?> javaOptionalOfProvider(TypeLiteral<T> type) {
checkState(JAVA_OPTIONAL_CLASS != null, "java.util.Optional not found");
return TypeLiteral.get(
Types.newParameterizedType(
JAVA_OPTIONAL_CLASS, newParameterizedType(Provider.class, type.getType())));
}
代码示例来源:origin: com.google.inject/guice
static <T> TypeLiteral<?> javaOptionalOfJavaxProvider(TypeLiteral<T> type) {
checkState(JAVA_OPTIONAL_CLASS != null, "java.util.Optional not found");
return TypeLiteral.get(
Types.newParameterizedType(
JAVA_OPTIONAL_CLASS,
newParameterizedType(javax.inject.Provider.class, type.getType())));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<javax.inject.Provider<T>>> optionalOfJavaxProvider(
TypeLiteral<T> type) {
return (TypeLiteral<Optional<javax.inject.Provider<T>>>)
TypeLiteral.get(
Types.newParameterizedType(
Optional.class, newParameterizedType(javax.inject.Provider.class, type.getType())));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<Provider<T>>> optionalOfProvider(TypeLiteral<T> type) {
return (TypeLiteral<Optional<Provider<T>>>)
TypeLiteral.get(
Types.newParameterizedType(
Optional.class, newParameterizedType(Provider.class, type.getType())));
}
代码示例来源:origin: com.google.inject/guice
@SuppressWarnings("unchecked")
static <T> Key<Provider<T>> providerOf(Key<T> key) {
Type providerT = Types.providerOf(key.getTypeLiteral().getType());
return (Key<Provider<T>>) key.ofType(providerT);
}
代码示例来源:origin: com.google.inject/guice
/** Given a Key<T> will return a Key<Provider<T>> */
@SuppressWarnings("unchecked")
private static <T> Key<Provider<T>> getKeyOfProvider(Key<T> valueKey) {
return (Key<Provider<T>>)
valueKey.ofType(Types.providerOf(valueKey.getTypeLiteral().getType()));
}
代码示例来源:origin: com.google.inject/guice
@Override
public Set<Dependency<?>> getDependencies() {
// We depend on Provider<T>, not T directly. This is an important distinction
// for dependency analysis tools that short-circuit on providers.
Key<?> providerKey = getKey().ofType(Types.providerOf(getKey().getTypeLiteral().getType()));
return ImmutableSet.<Dependency<?>>of(Dependency.get(providerKey));
}
内容来源于网络,如有侵权,请联系作者删除!