com.google.inject.internal.InternalFactoryToInitializableAdapter Maven / Gradle / Ivy
package com.google.inject.internal;
import com.google.inject.spi.Dependency;
import com.google.inject.spi.ProviderInstanceBinding;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Adapts {@link ProviderInstanceBinding} providers, ensuring circular proxies
* fail (or proxy) properly.
*/
final class InternalFactoryToInitializableAdapter extends ProviderInternalFactory {
private final ProvisionListenerStackCallback provisionCallback;
private final Initializable extends javax.inject.Provider extends T>> initializable;
InternalFactoryToInitializableAdapter(
Initializable extends javax.inject.Provider extends T>> initializable,
Object source, ProvisionListenerStackCallback provisionCallback) {
super(source);
this.provisionCallback = checkNotNull(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 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();
}
}