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; 18 19 import static com.google.common.base.Preconditions.checkNotNull; 20 21 import dagger.internal.codegen.ComponentDescriptor.ComponentMethodDescriptor; 22 import dagger.internal.codegen.ModifiableBindingMethods.ModifiableBindingMethod; 23 import dagger.internal.codegen.langmodel.DaggerTypes; 24 import java.util.Optional; 25 import javax.lang.model.type.TypeMirror; 26 27 /** 28 * A {@link ModifiableAbstractMethodBindingExpression} for a binding that exists but is not ready to 29 * be expressed in this compilation unit and should be deferred until a future compilation. 30 * Generates a method that will be implemented in the future compilation. 31 * 32 * <p>A deferred modifiable binding expression is used when: 33 * 34 * <ul> 35 * <li>The generated code for a binding requires an instance of a type that is generated in the 36 * root component compilation unit. 37 * <li>A {@linkplain ModifiableBindingType#BINDS_METHOD_WITH_MISSING_DEPENDENCY {@code @Binds} 38 * method's dependency is missing} in a subcomponent. 39 * </ul> 40 */ 41 final class DeferredModifiableBindingExpression extends ModifiableAbstractMethodBindingExpression { 42 private final ComponentImplementation componentImplementation; 43 private final ContributionBinding binding; 44 private final BindingRequest request; 45 DeferredModifiableBindingExpression( ComponentImplementation componentImplementation, ModifiableBindingType modifiableBindingType, ContributionBinding binding, BindingRequest request, Optional<ModifiableBindingMethod> matchingModifiableBindingMethod, Optional<ComponentMethodDescriptor> matchingComponentMethod, DaggerTypes types)46 DeferredModifiableBindingExpression( 47 ComponentImplementation componentImplementation, 48 ModifiableBindingType modifiableBindingType, 49 ContributionBinding binding, 50 BindingRequest request, 51 Optional<ModifiableBindingMethod> matchingModifiableBindingMethod, 52 Optional<ComponentMethodDescriptor> matchingComponentMethod, 53 DaggerTypes types) { 54 super( 55 componentImplementation, 56 modifiableBindingType, 57 request, 58 matchingModifiableBindingMethod, 59 matchingComponentMethod, 60 types); 61 this.componentImplementation = checkNotNull(componentImplementation); 62 this.binding = checkNotNull(binding); 63 this.request = checkNotNull(request); 64 } 65 66 @Override chooseMethodName()67 String chooseMethodName() { 68 return componentImplementation.getUniqueMethodName(request); 69 } 70 71 @Override contributedType()72 protected TypeMirror contributedType() { 73 return binding.contributedType(); 74 } 75 } 76