private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
@SuppressWarnings("unchecked") public static <T> TypeLiteral<T> getProvidedType( TypeLiteral<? extends Provider<? extends T>> initialProviderTypeLiteral, Errors errors) throws ErrorsException { TypeLiteral<? extends Provider<? extends T>> providerTypeLiteral = initialProviderTypeLiteral; while (providerTypeLiteral.getRawType() != Provider.class) { providerTypeLiteral = (TypeLiteral<? extends Provider<? extends T>>) providerTypeLiteral.getSupertype(Provider.class); } Type providerType = providerTypeLiteral.getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; return (TypeLiteral<T>) TypeLiteral.get(entryType); }
@SuppressWarnings("unchecked") public static <T> TypeLiteral<T> getProvidedType( TypeLiteral<? extends Provider<? extends T>> initialProviderTypeLiteral, Errors errors) throws ErrorsException { TypeLiteral<? extends Provider<? extends T>> providerTypeLiteral = initialProviderTypeLiteral; while (providerTypeLiteral.getRawType() != Provider.class) { providerTypeLiteral = (TypeLiteral<? extends Provider<? extends T>>) providerTypeLiteral.getSupertype(Provider.class); } Type providerType = providerTypeLiteral.getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; return (TypeLiteral<T>) TypeLiteral.get(entryType); }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException { Type providerType = key.getTypeLiteral().getType(); // If the Provider has no type parameter (raw Provider)... if (!(providerType instanceof ParameterizedType)) { throw errors.cannotInjectRawProvider().toException(); } Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; @SuppressWarnings("unchecked") // safe because T came from Key<Provider<T>> Key<T> providedKey = (Key<T>) key.ofType(entryType); return providedKey; }