package com.google.inject.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.inject.spi.Dependency;
import com.google.inject.spi.ProviderInstanceBinding;
final class InternalFactoryToInitializableAdapter<T> extends ProviderInternalFactory<T> {
private final ProvisionListenerStackCallback<T> provisionCallback;
private final Initializable<? extends javax.inject.Provider<? extends T>> initializable;
public InternalFactoryToInitializableAdapter(
Initializable<? extends javax.inject.Provider<? extends T>> initializable,
Object source,
ProvisionListenerStackCallback<T> provisionCallback) {
super(source);
this.provisionCallback = provisionCallback;
this.initializable = checkNotNull(initializable, "provider");
}
@Override
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
return circularGet(initializable.get(), context, dependency, provisionCallback);
}
@Override
protected T provision(
javax.inject.Provider<? extends T> provider,
Dependency<?> dependency,
ConstructionContext<T> constructionContext)
throws InternalProvisionException {
try {
return super.provision(provider, dependency, constructionContext);
} catch (RuntimeException userException) {
throw InternalProvisionException.errorInProvider(userException).addSource(source);
}
}
@Override
public String toString() {
return initializable.toString();
}
}