• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.writing;
18 
19 import androidx.room.compiler.processing.XProcessingEnv;
20 import dagger.assisted.Assisted;
21 import dagger.assisted.AssistedFactory;
22 import dagger.assisted.AssistedInject;
23 import dagger.internal.codegen.binding.FrameworkType;
24 import dagger.internal.codegen.binding.ProvisionBinding;
25 
26 /** Binding expression for provider instances. */
27 final class ProviderInstanceRequestRepresentation extends FrameworkInstanceRequestRepresentation {
28 
29   @AssistedInject
ProviderInstanceRequestRepresentation( @ssisted ProvisionBinding binding, SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory, StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory, ProviderInstanceSupplier.Factory providerInstanceSupplierFactory, ComponentImplementation componentImplementation, XProcessingEnv processingEnv)30   ProviderInstanceRequestRepresentation(
31       @Assisted ProvisionBinding binding,
32       SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory,
33       StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory,
34       ProviderInstanceSupplier.Factory providerInstanceSupplierFactory,
35       ComponentImplementation componentImplementation,
36       XProcessingEnv processingEnv) {
37     super(
38         binding,
39         frameworkInstanceSupplier(
40             binding,
41             switchingProviderInstanceSupplierFactory,
42             staticFactoryInstanceSupplierFactory,
43             providerInstanceSupplierFactory,
44             componentImplementation),
45         processingEnv);
46   }
47 
48   @Override
frameworkType()49   protected FrameworkType frameworkType() {
50     return FrameworkType.PROVIDER;
51   }
52 
frameworkInstanceSupplier( ProvisionBinding binding, SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory, StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory, ProviderInstanceSupplier.Factory providerInstanceSupplierFactory, ComponentImplementation componentImplementation)53   private static FrameworkInstanceSupplier frameworkInstanceSupplier(
54       ProvisionBinding binding,
55       SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory,
56       StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory,
57       ProviderInstanceSupplier.Factory providerInstanceSupplierFactory,
58       ComponentImplementation componentImplementation) {
59     FrameworkInstanceKind frameworkInstanceKind =
60         FrameworkInstanceKind.from(binding, componentImplementation.compilerMode());
61     switch (frameworkInstanceKind) {
62       case SWITCHING_PROVIDER:
63         return switchingProviderInstanceSupplierFactory.create(binding);
64       case STATIC_FACTORY:
65         return staticFactoryInstanceSupplierFactory.create(binding);
66       case PROVIDER_FIELD:
67         return providerInstanceSupplierFactory.create(binding);
68     }
69     throw new AssertionError("Unexpected FrameworkInstanceKind: " + frameworkInstanceKind);
70   }
71 
72   @AssistedFactory
73   static interface Factory {
create(ProvisionBinding binding)74     ProviderInstanceRequestRepresentation create(ProvisionBinding binding);
75   }
76 }
77