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

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

package com.google.inject.internal;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Binding;
import com.google.inject.Key;
import com.google.inject.Scope;
import com.google.inject.TypeLiteral;
import com.google.inject.spi.InjectionRequest;
import com.google.inject.spi.MembersInjectorLookup;
import com.google.inject.spi.ModuleAnnotatedMethodScannerBinding;
import com.google.inject.spi.ProviderLookup;
import com.google.inject.spi.ProvisionListenerBinding;
import com.google.inject.spi.ScopeBinding;
import com.google.inject.spi.StaticInjectionRequest;
import com.google.inject.spi.TypeConverterBinding;
import com.google.inject.spi.TypeListenerBinding;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * The inheritable data within an injector. This class is intended to allow parent and local
 * injector data to be accessed as a unit.
 *
 */
interface State {

    State NONE = new State() {

        @Override
        public State parent() {
            throw new UnsupportedOperationException();
        }

        @Override
        public  BindingImpl getExplicitBinding(Key key) {
            return null;
        }

        @Override
        public Map, Binding> getExplicitBindingsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void putBinding(Key key, BindingImpl binding) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void putProviderLookup(ProviderLookup lookup) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set> getProviderLookupsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void putStaticInjectionRequest(StaticInjectionRequest staticInjectionRequest) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set getStaticInjectionRequestsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set> getInjectionRequestsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set> getMembersInjectorLookupsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void putInjectionRequest(InjectionRequest injectionRequest) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void putMembersInjectorLookup(MembersInjectorLookup membersInjectorLookup) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ScopeBinding getScopeBinding(Class scopingAnnotation) {
            return null;
        }

        @Override
        public void putScopeBinding(Class annotationType, ScopeBinding scope) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void addConverter(TypeConverterBinding typeConverterBinding) {
            throw new UnsupportedOperationException();
        }

        @Override
        public TypeConverterBinding getConverter(String stringValue, TypeLiteral type, Errors errors,
                                                 Object source) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterable getConvertersThisLevel() {
            return ImmutableSet.of();
        }

        @Override
        public void addTypeListener(TypeListenerBinding typeListenerBinding) {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getTypeListenerBindings() {
            return ImmutableList.of();
        }

        @Override
        public void addProvisionListener(ProvisionListenerBinding provisionListenerBinding) {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getProvisionListenerBindings() {
            return ImmutableList.of();
        }

        @Override
        public void addScanner(ModuleAnnotatedMethodScannerBinding scanner) {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getScannerBindings() {
            return ImmutableList.of();
        }

        @Override
        public void blacklist(Key key, State state, Object source) {
        }

        @Override
        public boolean isBlacklisted(Key key) {
            return true;
        }

        @Override
        public Set getSourcesForBlacklistedKey(Key key) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Object lock() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Map, Scope> getScopes() {
            return ImmutableMap.of();
        }

        @Override
        public List getScopeBindingsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getTypeListenerBindingsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getProvisionListenerBindingsThisLevel() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List getScannerBindingsThisLevel() {
            throw new UnsupportedOperationException();
        }
    };

    State parent();

    /**
     * Gets a binding which was specified explicitly in a module, or null.
     */
     BindingImpl getExplicitBinding(Key key);

    /**
     * Returns the explicit bindings at this level only.
     */
    Map, Binding> getExplicitBindingsThisLevel();

    void putBinding(Key key, BindingImpl binding);

    void putProviderLookup(ProviderLookup lookup);

    Set> getProviderLookupsThisLevel();

    void putStaticInjectionRequest(StaticInjectionRequest staticInjectionRequest);

    Set getStaticInjectionRequestsThisLevel();

    ScopeBinding getScopeBinding(Class scopingAnnotation);

    void putInjectionRequest(InjectionRequest injectionRequest);

    Set> getInjectionRequestsThisLevel();

    void putMembersInjectorLookup(MembersInjectorLookup membersInjectorLookup);

    Set> getMembersInjectorLookupsThisLevel();

    void putScopeBinding(Class annotationType, ScopeBinding scope);

    Collection getScopeBindingsThisLevel();

    void addConverter(TypeConverterBinding typeConverterBinding);

    /**
     * Returns the matching converter for {@code type}, or null if none match.
     */
    TypeConverterBinding getConverter(
            String stringValue, TypeLiteral type, Errors errors, Object source);

    /**
     * Returns all converters at this level only.
     */
    Iterable getConvertersThisLevel();

    void addTypeListener(TypeListenerBinding typeListenerBinding);

    List getTypeListenerBindings();

    List getTypeListenerBindingsThisLevel();

    void addProvisionListener(ProvisionListenerBinding provisionListenerBinding);

    List getProvisionListenerBindings();

    List getProvisionListenerBindingsThisLevel();

    void addScanner(ModuleAnnotatedMethodScannerBinding scanner);

    List getScannerBindings();

    List getScannerBindingsThisLevel();

    /**
     * Forbids the corresponding injector from creating a binding to {@code key}. Child injectors
     * blacklist their bound keys on their parent injectors to prevent just-in-time bindings on the
     * parent injector that would conflict and pass along their state to control the lifetimes.
     */
    void blacklist(Key key, State state, Object source);

    /**
     * Returns true if {@code key} is forbidden from being bound in this injector. This indicates that
     * one of this injector's descendent's has bound the key.
     */
    boolean isBlacklisted(Key key);

    /**
     * Returns the source of a blacklisted key.
     */
    Set getSourcesForBlacklistedKey(Key key);

    /**
     * Returns the shared lock for all injector data. This is a low-granularity, high-contention lock
     * to be used when reading mutable data (ie. just-in-time bindings, and binding blacklists).
     */
    Object lock();

    /**
     * Returns all the scope bindings at this level and parent levels.
     */
    Map, Scope> getScopes();
}