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

com.google.inject.internal.DeferredLookups Maven / Gradle / Ivy

package com.google.inject.internal;

import com.google.common.collect.Lists;
import com.google.inject.Key;
import com.google.inject.MembersInjector;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.spi.Element;
import com.google.inject.spi.MembersInjectorLookup;
import com.google.inject.spi.ProviderLookup;

import java.util.List;

/**
 * Returns providers and members injectors that haven't yet been initialized. As a part of injector
 * creation it's necessary to {@link #initialize initialize} these lookups.
 */
final class DeferredLookups implements Lookups {
    private final InjectorImpl injector;
    private final List lookups = Lists.newArrayList();

    DeferredLookups(InjectorImpl injector) {
        this.injector = injector;
    }

    /**
     * Initialize the specified lookups, either immediately or when the injector is created.
     */
    void initialize(Errors errors) {
        injector.lookups = injector;
        new LookupProcessor(errors).process(injector, lookups);
    }

    public  Provider getProvider(Key key) {
        ProviderLookup lookup = new ProviderLookup<>(key, key);
        lookups.add(lookup);
        return lookup.getProvider();
    }

    public  MembersInjector getMembersInjector(TypeLiteral type) {
        MembersInjectorLookup lookup = new MembersInjectorLookup<>(type, type);
        lookups.add(lookup);
        return lookup.getMembersInjector();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy