All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 provider;
    private final Object source;

    InternalFactoryToProviderAdapter(Provider 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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy