1*f585d8a3SJacky Wang /* 2*f585d8a3SJacky Wang * Copyright (C) 2017 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.model; 18*f585d8a3SJacky Wang 19*f585d8a3SJacky Wang import com.google.common.collect.ImmutableSet; 20*f585d8a3SJacky Wang import dagger.model.BindingGraph.MaybeBinding; 21*f585d8a3SJacky Wang import java.util.Optional; 22*f585d8a3SJacky Wang import javax.lang.model.element.Element; 23*f585d8a3SJacky Wang import javax.lang.model.element.TypeElement; 24*f585d8a3SJacky Wang 25*f585d8a3SJacky Wang /** 26*f585d8a3SJacky Wang * The association between a {@link Key} and the way in which instances of the key are provided. 27*f585d8a3SJacky Wang * Includes any {@linkplain DependencyRequest dependencies} that are needed in order to provide the 28*f585d8a3SJacky Wang * instances. 29*f585d8a3SJacky Wang * 30*f585d8a3SJacky Wang * <p>If a binding is owned by more than one component, there is one {@code Binding} for every 31*f585d8a3SJacky Wang * owning component. 32*f585d8a3SJacky Wang */ 33*f585d8a3SJacky Wang public interface Binding extends MaybeBinding { 34*f585d8a3SJacky Wang @Override componentPath()35*f585d8a3SJacky Wang ComponentPath componentPath(); 36*f585d8a3SJacky Wang 37*f585d8a3SJacky Wang /** @deprecated This always returns {@code Optional.of(this)}. */ 38*f585d8a3SJacky Wang @Override 39*f585d8a3SJacky Wang @Deprecated binding()40*f585d8a3SJacky Wang default Optional<Binding> binding() { 41*f585d8a3SJacky Wang return Optional.of(this); 42*f585d8a3SJacky Wang } 43*f585d8a3SJacky Wang /** 44*f585d8a3SJacky Wang * The dependencies of this binding. The order of the dependencies corresponds to the order in 45*f585d8a3SJacky Wang * which they will be injected when the binding is requested. 46*f585d8a3SJacky Wang */ dependencies()47*f585d8a3SJacky Wang ImmutableSet<DependencyRequest> dependencies(); 48*f585d8a3SJacky Wang 49*f585d8a3SJacky Wang /** 50*f585d8a3SJacky Wang * The {@link Element} that declares this binding. Absent for {@linkplain BindingKind binding 51*f585d8a3SJacky Wang * kinds} that are not always declared by exactly one element. 52*f585d8a3SJacky Wang * 53*f585d8a3SJacky Wang * <p>For example, consider {@link BindingKind#MULTIBOUND_SET}. A component with many 54*f585d8a3SJacky Wang * {@code @IntoSet} bindings for the same key will have a synthetic binding that depends on all 55*f585d8a3SJacky Wang * contributions, but with no identifiying binding element. A {@code @Multibinds} method will also 56*f585d8a3SJacky Wang * contribute a synthetic binding, but since multiple {@code @Multibinds} methods can coexist in 57*f585d8a3SJacky Wang * the same component (and contribute to one single binding), it has no binding element. 58*f585d8a3SJacky Wang */ bindingElement()59*f585d8a3SJacky Wang Optional<Element> bindingElement(); 60*f585d8a3SJacky Wang 61*f585d8a3SJacky Wang /** 62*f585d8a3SJacky Wang * The {@link TypeElement} of the module which contributes this binding. Absent for bindings that 63*f585d8a3SJacky Wang * have no {@link #bindingElement() binding element}. 64*f585d8a3SJacky Wang */ contributingModule()65*f585d8a3SJacky Wang Optional<TypeElement> contributingModule(); 66*f585d8a3SJacky Wang 67*f585d8a3SJacky Wang /** 68*f585d8a3SJacky Wang * Returns {@code true} if using this binding requires an instance of the {@link 69*f585d8a3SJacky Wang * #contributingModule()}. 70*f585d8a3SJacky Wang */ requiresModuleInstance()71*f585d8a3SJacky Wang boolean requiresModuleInstance(); 72*f585d8a3SJacky Wang 73*f585d8a3SJacky Wang /** The scope of this binding if it has one. */ scope()74*f585d8a3SJacky Wang Optional<Scope> scope(); 75*f585d8a3SJacky Wang 76*f585d8a3SJacky Wang /** 77*f585d8a3SJacky Wang * Returns {@code true} if this binding may provide {@code null} instead of an instance of {@link 78*f585d8a3SJacky Wang * #key()}. Nullable bindings cannot be requested from {@linkplain DependencyRequest#isNullable() 79*f585d8a3SJacky Wang * non-nullable dependency requests}. 80*f585d8a3SJacky Wang */ isNullable()81*f585d8a3SJacky Wang boolean isNullable(); 82*f585d8a3SJacky Wang 83*f585d8a3SJacky Wang /** Returns {@code true} if this is a production binding, e.g. an {@code @Produces} method. */ isProduction()84*f585d8a3SJacky Wang boolean isProduction(); 85*f585d8a3SJacky Wang 86*f585d8a3SJacky Wang /** The kind of binding this instance represents. */ kind()87*f585d8a3SJacky Wang BindingKind kind(); 88*f585d8a3SJacky Wang 89*f585d8a3SJacky Wang } 90