com.google.inject.internal.InternalFactoryToProviderAdapter Maven / Gradle / Ivy
package com.google.inject.internal;
import com.google.inject.Provider;
import com.google.inject.spi.Dependency;
import static com.google.common.base.Preconditions.checkNotNull;
final class InternalFactoryToProviderAdapter implements InternalFactory {
private final Provider extends T> provider;
private final Object source;
InternalFactoryToProviderAdapter(Provider extends T> provider, Object source) {
this.provider = checkNotNull(provider, "provider");
this.source = checkNotNull(source, "source");
}
@Override
public T get(InternalContext context, Dependency> dependency, boolean linked)
throws InternalProvisionException {
try {
T t = provider.get();
if (t == null && !dependency.isNullable()) {
InternalProvisionException.onNullInjectedIntoNonNullableDependency(source, dependency);
}
return t;
} catch (RuntimeException userException) {
throw InternalProvisionException.errorInProvider(userException).addSource(source);
}
}
@Override
public String toString() {
return provider.toString();
}
}