• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.auto.value.AutoValue;
20 import com.google.auto.value.extension.memoized.Memoized;
21 import com.google.common.collect.ImmutableSet;
22 import com.google.errorprone.annotations.CheckReturnValue;
23 import dagger.internal.codegen.base.ContributionType;
24 import dagger.internal.codegen.model.BindingKind;
25 import dagger.internal.codegen.model.DependencyRequest;
26 import dagger.internal.codegen.xprocessing.Nullability;
27 import java.util.Optional;
28 
29 /** A binding for a {@link BindingKind#PRODUCTION}. */
30 @CheckReturnValue
31 @AutoValue
32 public abstract class ProductionBinding extends ContributionBinding {
33   @Override
kind()34   public BindingKind kind() {
35     return BindingKind.PRODUCTION;
36   }
37 
38   @Override
optionalBindingType()39   public Optional<BindingType> optionalBindingType() {
40     return Optional.of(BindingType.PRODUCTION);
41   }
42   @Override
43   @Memoized
contributionType()44   public ContributionType contributionType() {
45     return ContributionType.fromBindingElement(bindingElement().get());
46   }
47 
48   @Override
nullability()49   public Nullability nullability() {
50     return Nullability.NOT_NULLABLE;
51   }
52 
53   /** Dependencies necessary to invoke the {@code @Produces} method. */
explicitDependencies()54   public abstract ImmutableSet<DependencyRequest> explicitDependencies();
55 
56   @Override
57   @Memoized
dependencies()58   public ImmutableSet<DependencyRequest> dependencies() {
59     return ImmutableSet.<DependencyRequest>builder()
60         .add(executorRequest())
61         .add(monitorRequest())
62         .addAll(explicitDependencies())
63         .build();
64   }
65 
executorRequest()66   public abstract DependencyRequest executorRequest();
67 
monitorRequest()68   public abstract DependencyRequest monitorRequest();
69 
70   // Profiling determined that this method is called enough times that memoizing it had a measurable
71   // performance improvement for large components.
72   @Memoized
73   @Override
requiresModuleInstance()74   public boolean requiresModuleInstance() {
75     return super.requiresModuleInstance();
76   }
77 
78   @Override
toBuilder()79   public abstract Builder toBuilder();
80 
81   @Memoized
82   @Override
hashCode()83   public abstract int hashCode();
84 
85   // TODO(ronshapiro,dpb): simplify the equality semantics
86   @Override
equals(Object obj)87   public abstract boolean equals(Object obj);
88 
builder()89   static Builder builder() {
90     return new AutoValue_ProductionBinding.Builder();
91   }
92 
93   /** A {@link ProductionBinding} builder. */
94   @AutoValue.Builder
95   abstract static class Builder extends ContributionBinding.Builder<ProductionBinding, Builder> {
executorRequest(DependencyRequest executorRequest)96     abstract Builder executorRequest(DependencyRequest executorRequest);
97 
monitorRequest(DependencyRequest monitorRequest)98     abstract Builder monitorRequest(DependencyRequest monitorRequest);
99 
explicitDependencies(Iterable<DependencyRequest> explicitDependencies)100     abstract Builder explicitDependencies(Iterable<DependencyRequest> explicitDependencies);
101   }
102 }
103