• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.room.compiler.processing.XConstructorElement;
20 import androidx.room.compiler.processing.XFieldElement;
21 import androidx.room.compiler.processing.XMethodElement;
22 import com.google.errorprone.annotations.CanIgnoreReturnValue;
23 import dagger.Component;
24 import dagger.Provides;
25 import dagger.internal.codegen.base.SourceFileGenerationException;
26 import dagger.internal.codegen.base.SourceFileGenerator;
27 import dagger.internal.codegen.model.Key;
28 import java.util.Optional;
29 import javax.inject.Inject;
30 
31 /**
32  * Maintains the collection of provision bindings from {@link Inject} constructors and members
33  * injection bindings from {@link Inject} fields and methods known to the annotation processor. Note
34  * that this registry <b>does not</b> handle any explicit bindings (those from {@link Provides}
35  * methods, {@link Component} dependencies, etc.).
36  */
37 public interface InjectBindingRegistry {
38   /**
39    * Returns an injection binding for {@code key}. If none has been registered yet, registers one.
40    */
getOrFindInjectionBinding(Key key)41   Optional<ContributionBinding> getOrFindInjectionBinding(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 MembersInjectorBinding} for {@code key}. If none has been registered yet,
51    * registers one.
52    */
getOrFindMembersInjectorBinding(Key key)53   Optional<MembersInjectorBinding> getOrFindMembersInjectorBinding(Key key);
54 
55   @CanIgnoreReturnValue
tryRegisterInjectConstructor( XConstructorElement constructorElement)56   Optional<ContributionBinding> tryRegisterInjectConstructor(
57       XConstructorElement constructorElement);
58 
59   @CanIgnoreReturnValue
tryRegisterInjectField(XFieldElement fieldElement)60   Optional<MembersInjectionBinding> tryRegisterInjectField(XFieldElement fieldElement);
61 
62   @CanIgnoreReturnValue
tryRegisterInjectMethod(XMethodElement methodElement)63   Optional<MembersInjectionBinding> tryRegisterInjectMethod(XMethodElement methodElement);
64 
65   /**
66    * This method ensures that sources for all registered {@link Binding bindings} (either explicitly
67    * or implicitly via {@link #getOrFindMembersInjectionBinding} or
68    * {@link #getOrFindInjectionBinding}) are generated.
69    */
generateSourcesForRequiredBindings( SourceFileGenerator<ContributionBinding> factoryGenerator, SourceFileGenerator<MembersInjectionBinding> membersInjectorGenerator)70   void generateSourcesForRequiredBindings(
71       SourceFileGenerator<ContributionBinding> factoryGenerator,
72       SourceFileGenerator<MembersInjectionBinding> membersInjectorGenerator)
73       throws SourceFileGenerationException;
74 }
75