1*f585d8a3SJacky Wang /* 2*f585d8a3SJacky Wang * Copyright (C) 2021 The Dagger Authors. 3*f585d8a3SJacky Wang * 4*f585d8a3SJacky Wang * Licensed under the Apache License, Version 2.0 (the "License"); 5*f585d8a3SJacky Wang * you may not use this file except in compliance with the License. 6*f585d8a3SJacky Wang * You may obtain a copy of the License at 7*f585d8a3SJacky Wang * 8*f585d8a3SJacky Wang * http://www.apache.org/licenses/LICENSE-2.0 9*f585d8a3SJacky Wang * 10*f585d8a3SJacky Wang * Unless required by applicable law or agreed to in writing, software 11*f585d8a3SJacky Wang * distributed under the License is distributed on an "AS IS" BASIS, 12*f585d8a3SJacky Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*f585d8a3SJacky Wang * See the License for the specific language governing permissions and 14*f585d8a3SJacky Wang * limitations under the License. 15*f585d8a3SJacky Wang */ 16*f585d8a3SJacky Wang 17*f585d8a3SJacky Wang package dagger.spi.model; 18*f585d8a3SJacky Wang 19*f585d8a3SJacky Wang import com.google.common.collect.ImmutableSet; 20*f585d8a3SJacky Wang import dagger.spi.model.BindingGraph.MaybeBinding; 21*f585d8a3SJacky Wang import java.util.Optional; 22*f585d8a3SJacky Wang 23*f585d8a3SJacky Wang /** 24*f585d8a3SJacky Wang * The association between a {@link Key} and the way in which instances of the key are provided. 25*f585d8a3SJacky Wang * Includes any {@linkplain DependencyRequest dependencies} that are needed in order to provide the 26*f585d8a3SJacky Wang * instances. 27*f585d8a3SJacky Wang * 28*f585d8a3SJacky Wang * <p>If a binding is owned by more than one component, there is one {@code Binding} for every 29*f585d8a3SJacky Wang * owning component. 30*f585d8a3SJacky Wang */ 31*f585d8a3SJacky Wang public interface Binding extends MaybeBinding { 32*f585d8a3SJacky Wang @Override componentPath()33*f585d8a3SJacky Wang ComponentPath componentPath(); 34*f585d8a3SJacky Wang 35*f585d8a3SJacky Wang /** @deprecated This always returns {@code Optional.of(this)}. */ 36*f585d8a3SJacky Wang @Override 37*f585d8a3SJacky Wang @Deprecated binding()38*f585d8a3SJacky Wang default Optional<Binding> binding() { 39*f585d8a3SJacky Wang return Optional.of(this); 40*f585d8a3SJacky Wang } 41*f585d8a3SJacky Wang /** 42*f585d8a3SJacky Wang * The dependencies of this binding. The order of the dependencies corresponds to the order in 43*f585d8a3SJacky Wang * which they will be injected when the binding is requested. 44*f585d8a3SJacky Wang */ dependencies()45*f585d8a3SJacky Wang ImmutableSet<DependencyRequest> dependencies(); 46*f585d8a3SJacky Wang 47*f585d8a3SJacky Wang /** 48*f585d8a3SJacky Wang * The {@link DaggerElement} that declares this binding. Absent for 49*f585d8a3SJacky Wang * {@linkplain BindingKind binding kinds} that are not always declared by exactly one element. 50*f585d8a3SJacky Wang * 51*f585d8a3SJacky Wang * <p>For example, consider {@link BindingKind#MULTIBOUND_SET}. A component with many 52*f585d8a3SJacky Wang * {@code @IntoSet} bindings for the same key will have a synthetic binding that depends on all 53*f585d8a3SJacky Wang * contributions, but with no identifiying binding element. A {@code @Multibinds} method will also 54*f585d8a3SJacky Wang * contribute a synthetic binding, but since multiple {@code @Multibinds} methods can coexist in 55*f585d8a3SJacky Wang * the same component (and contribute to one single binding), it has no binding element. 56*f585d8a3SJacky Wang */ bindingElement()57*f585d8a3SJacky Wang Optional<DaggerElement> bindingElement(); 58*f585d8a3SJacky Wang 59*f585d8a3SJacky Wang /** 60*f585d8a3SJacky Wang * The {@link DaggerTypeElement} of the module which contributes this binding. Absent for bindings 61*f585d8a3SJacky Wang * that have no {@link #bindingElement() binding element}. 62*f585d8a3SJacky Wang */ contributingModule()63*f585d8a3SJacky Wang Optional<DaggerTypeElement> contributingModule(); 64*f585d8a3SJacky Wang 65*f585d8a3SJacky Wang /** 66*f585d8a3SJacky Wang * Returns {@code true} if using this binding requires an instance of the {@link 67*f585d8a3SJacky Wang * #contributingModule()}. 68*f585d8a3SJacky Wang */ requiresModuleInstance()69*f585d8a3SJacky Wang boolean requiresModuleInstance(); 70*f585d8a3SJacky Wang 71*f585d8a3SJacky Wang /** The scope of this binding if it has one. */ scope()72*f585d8a3SJacky Wang Optional<Scope> scope(); 73*f585d8a3SJacky Wang 74*f585d8a3SJacky Wang /** 75*f585d8a3SJacky Wang * Returns {@code true} if this binding may provide {@code null} instead of an instance of {@link 76*f585d8a3SJacky Wang * #key()}. Nullable bindings cannot be requested from {@linkplain DependencyRequest#isNullable() 77*f585d8a3SJacky Wang * non-nullable dependency requests}. 78*f585d8a3SJacky Wang */ isNullable()79*f585d8a3SJacky Wang boolean isNullable(); 80*f585d8a3SJacky Wang 81*f585d8a3SJacky Wang /** Returns {@code true} if this is a production binding, e.g. an {@code @Produces} method. */ isProduction()82*f585d8a3SJacky Wang boolean isProduction(); 83*f585d8a3SJacky Wang 84*f585d8a3SJacky Wang /** The kind of binding this instance represents. */ kind()85*f585d8a3SJacky Wang BindingKind kind(); 86*f585d8a3SJacky Wang 87*f585d8a3SJacky Wang } 88