1 /* 2 * Copyright (C) 2017 The Dagger Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dagger.internal.codegen.binding; 18 19 import com.google.errorprone.annotations.CanIgnoreReturnValue; 20 import dagger.Component; 21 import dagger.Provides; 22 import dagger.internal.codegen.base.SourceFileGenerationException; 23 import dagger.internal.codegen.base.SourceFileGenerator; 24 import dagger.model.Key; 25 import java.util.Optional; 26 import javax.inject.Inject; 27 import javax.lang.model.element.ExecutableElement; 28 import javax.lang.model.element.TypeElement; 29 30 /** 31 * Maintains the collection of provision bindings from {@link Inject} constructors and members 32 * injection bindings from {@link Inject} fields and methods known to the annotation processor. Note 33 * that this registry <b>does not</b> handle any explicit bindings (those from {@link Provides} 34 * methods, {@link Component} dependencies, etc.). 35 */ 36 public interface InjectBindingRegistry { 37 /** 38 * Returns a {@link ProvisionBinding} for {@code key}. If none has been registered yet, registers 39 * one. 40 */ getOrFindProvisionBinding(Key key)41 Optional<ProvisionBinding> getOrFindProvisionBinding(Key key); 42 43 /** 44 * Returns a {@link MembersInjectionBinding} for {@code key}. If none has been registered yet, 45 * registers one, along with all necessary members injection bindings for superclasses. 46 */ getOrFindMembersInjectionBinding(Key key)47 Optional<MembersInjectionBinding> getOrFindMembersInjectionBinding(Key key); 48 49 /** 50 * Returns a {@link ProvisionBinding} for a {@link dagger.MembersInjector} of {@code key}. If none 51 * has been registered yet, registers one. 52 */ getOrFindMembersInjectorProvisionBinding(Key key)53 Optional<ProvisionBinding> getOrFindMembersInjectorProvisionBinding(Key key); 54 55 @CanIgnoreReturnValue tryRegisterConstructor(ExecutableElement constructorElement)56 Optional<ProvisionBinding> tryRegisterConstructor(ExecutableElement constructorElement); 57 58 @CanIgnoreReturnValue tryRegisterMembersInjectedType(TypeElement typeElement)59 Optional<MembersInjectionBinding> tryRegisterMembersInjectedType(TypeElement typeElement); 60 61 /** 62 * This method ensures that sources for all registered {@link Binding bindings} (either explicitly 63 * or implicitly via {@link #getOrFindMembersInjectionBinding} or {@link 64 * #getOrFindProvisionBinding}) are generated. 65 */ generateSourcesForRequiredBindings( SourceFileGenerator<ProvisionBinding> factoryGenerator, SourceFileGenerator<MembersInjectionBinding> membersInjectorGenerator)66 void generateSourcesForRequiredBindings( 67 SourceFileGenerator<ProvisionBinding> factoryGenerator, 68 SourceFileGenerator<MembersInjectionBinding> membersInjectorGenerator) 69 throws SourceFileGenerationException; 70 } 71