@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())); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotation}. */ public static <K, V> MapBinder<K, V> newMapBinder( Binder binder, Class<K> keyType, Class<V> valueType, Annotation annotation) { return newMapBinder(binder, TypeLiteral.get(keyType), TypeLiteral.get(valueType), annotation); }
private ProviderMethodsModule( Object delegate, boolean skipFastClassGeneration, ModuleAnnotatedMethodScanner scanner) { this.delegate = checkNotNull(delegate, "delegate"); this.typeLiteral = TypeLiteral.get(this.delegate.getClass()); this.skipFastClassGeneration = skipFastClassGeneration; this.scanner = scanner; }
@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()))); }
/** * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a {@link * Map} that is itself bound with {@code annotationType}. */ public static <K, V> MapBinder<K, V> newMapBinder( Binder binder, Class<K> keyType, Class<V> valueType, Class<? extends Annotation> annotationType) { return newMapBinder( binder, TypeLiteral.get(keyType), TypeLiteral.get(valueType), annotationType); }
@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())))); }
public static MapBinder<Class<? extends Query>, QueryRunnerFactory> queryRunnerFactoryBinder(Binder binder) { return MapBinder.newMapBinder( binder, new TypeLiteral<Class<? extends Query>>(){}, TypeLiteral.get(QueryRunnerFactory.class) ); }
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()))); }
public static MapBinder<String, Function<?>> processorFunctionBinder(Binder binder) { return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), new TypeLiteral<Function<?>>() {}); }
@SuppressWarnings("unchecked") // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>> static <K, V> TypeLiteral<Map<K, Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf( TypeLiteral<K> keyType, TypeLiteral<V> valueType) { return (TypeLiteral<Map<K, Set<javax.inject.Provider<V>>>>) TypeLiteral.get( Types.mapOf( keyType.getType(), Types.setOf(Types.javaxProviderOf(valueType.getType())))); }
private MapBinder<String, Function<?>> processorFunctionBinder(Binder binder) { return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class), new TypeLiteral<Function<?>>() {}); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
@Override @SuppressWarnings("unchecked") // it is safe to use the type literal for the raw type public void requestInjection(Object instance) { requestInjection((TypeLiteral<Object>) TypeLiteral.get(instance.getClass()), instance); }
public void validate(Errors errors) throws ErrorsException { @SuppressWarnings("unchecked") // the type of 'T' is a TypeLiteral<T> TypeLiteral<T> type = TypeLiteral.get((Class<T>) instance.getClass()); membersInjector = injector.membersInjectorStore.get(type, errors.withSource(source)); Preconditions.checkNotNull( membersInjector, "No membersInjector available for instance: %s, from key: %s", instance, key); state = InjectableReferenceState.VALIDATED; }
protected MapBinder<String, Codec.Factory<? extends Codec>> codecMapBinder() { return MapBinder.newMapBinder(binder(), TypeLiteral.get(String.class), new TypeLiteral<Codec.Factory<? extends Codec>>() { }); }
protected MapBinder<String, Transport.Factory<? extends Transport>> transportMapBinder() { return MapBinder.newMapBinder(binder(), TypeLiteral.get(String.class), new TypeLiteral<Transport.Factory<? extends Transport>>() { }); }
protected MapBinder<String, MessageOutput.Factory<? extends MessageOutput>> outputsMapBinder() { return MapBinder.newMapBinder(binder(), TypeLiteral.get(String.class), new TypeLiteral<MessageOutput.Factory<? extends MessageOutput>>() { }); }
protected MapBinder<String, MessageInput.Factory<? extends MessageInput>> inputsMapBinder() { return MapBinder.newMapBinder(binder(), TypeLiteral.get(String.class), new TypeLiteral<MessageInput.Factory<? extends MessageInput>>() { }); }
protected MapBinder<String, WidgetStrategy.Factory<? extends WidgetStrategy>> widgetStrategyBinder() { return MapBinder.newMapBinder(binder(), TypeLiteral.get(String.class), new TypeLiteral<WidgetStrategy.Factory<? extends WidgetStrategy>>() { }); }
/** Unsafe. Constructs a key from a manually specified type. */ @SuppressWarnings("unchecked") private Key(Type type, AnnotationStrategy annotationStrategy) { this.annotationStrategy = annotationStrategy; this.typeLiteral = MoreTypes.canonicalizeForKey((TypeLiteral<T>) TypeLiteral.get(type)); this.hashCode = computeHashCode(); }